You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by jd...@apache.org on 2026/07/26 20:33:50 UTC
(grails-intellij-plugin) 30/35: Convert the five Kotlin test classes to Java
This is an automated email from the ASF dual-hosted git repository.
jdaugherty pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/grails-intellij-plugin.git
commit 8af0a4805872f46f58c6e3e31a12401692c77080
Author: James Daugherty <jd...@jdresources.net>
AuthorDate: Sun Jul 26 15:22:49 2026 -0400
Convert the five Kotlin test classes to Java
These lean on Kotlin raw strings for the Groovy and GSP fixtures, where the
exact bytes matter: the fixtures embed <caret>, <selection> and inline
<error descr="..."> markers that the test framework parses by offset.
A Kotlin raw string keeps the newline immediately after the opening quotes,
while a Java text block strips it, so every block gains a leading blank line to
compensate, and content plus closing delimiter sit flush-left so incidental-
indentation stripping is a no-op. DomainFieldIntentionsTest holds 38 of these,
so it was transformed by script and then checked by extracting every literal
from both files and comparing: all 38 are byte-identical. The shorter GSP
fixtures use explicit escapes instead of text blocks, being single-line.
Two platform test-framework methods are Kotlin with default arguments, which
Java cannot omit. Their values come from the $default bridges:
createStdProjectFolders takes "" and importProject takes false. WebRoot is in
com.intellij.javaee.web, not the .facet subpackage Kotlin's import implied.
Kotlin default parameters in the two i18n intention tests become overloads.
Verified: 186 classes / 987 tests / 0 failures / 0 errors, unchanged; each
converted class ran its full count (23, 2, 8, 14, 14); rat clean.
---
...mporterTest.kt => GrailsMavenImporterTest.java} | 69 +++---
...tionsTest.kt => DomainFieldIntentionsTest.java} | 275 ++++++++++++---------
.../grails/i18n/GrailsGroovyI18nIntentionTest.java | 115 +++++++++
.../grails/i18n/GrailsGroovyI18nIntentionTest.kt | 105 --------
...ectionTest.kt => GrailsI18nInspectionTest.java} | 131 +++++-----
.../groovy/grails/i18n/GspI18nIntentionTest.java | 116 +++++++++
.../groovy/grails/i18n/GspI18nIntentionTest.kt | 118 ---------
7 files changed, 497 insertions(+), 432 deletions(-)
diff --git a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/GrailsMavenImporterTest.kt b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/GrailsMavenImporterTest.java
similarity index 68%
rename from plugin/src/test/java/org/jetbrains/plugins/groovy/grails/GrailsMavenImporterTest.kt
rename to plugin/src/test/java/org/jetbrains/plugins/groovy/grails/GrailsMavenImporterTest.java
index aa60e20..f6f606c 100644
--- a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/GrailsMavenImporterTest.kt
+++ b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/GrailsMavenImporterTest.java
@@ -13,20 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.jetbrains.plugins.groovy.grails;
-package org.jetbrains.plugins.groovy.grails
+import com.intellij.facet.FacetManager;
+import com.intellij.javaee.web.facet.WebFacet;
+import com.intellij.javaee.web.WebRoot;
+import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCase;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.vfs.VfsUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.plugins.grails.config.GrailsFramework;
+import org.junit.Test;
-import com.intellij.facet.FacetManager
-import com.intellij.javaee.web.facet.WebFacet
-import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCase
-import com.intellij.openapi.vfs.VfsUtil
-import com.intellij.openapi.vfs.VirtualFile
-import org.jetbrains.plugins.grails.config.GrailsFramework
-import org.junit.Test
-import java.util.Arrays
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
-class GrailsMavenImporterTest : MavenMultiVersionImportingTestCase() {
- private fun createGrailsStdFolders() {
+public class GrailsMavenImporterTest extends MavenMultiVersionImportingTestCase {
+
+ private void createGrailsStdFolders() {
createProjectSubDirs("grails-app/conf/hibernate",
"grails-app/controllers",
"grails-app/domain",
@@ -40,13 +45,13 @@ class GrailsMavenImporterTest : MavenMultiVersionImportingTestCase() {
"src/java",
"test/unit",
"test/integration",
- "web-app/WEB-INF")
+ "web-app/WEB-INF");
}
@Test
- fun testImportGrailsProject() {
- createStdProjectFolders()
- createGrailsStdFolders()
+ public void testImportGrailsProject() {
+ createStdProjectFolders("");
+ createGrailsStdFolders();
importProject(" <groupId>test</groupId>" +
" <artifactId>project</artifactId>" +
@@ -73,9 +78,9 @@ class GrailsMavenImporterTest : MavenMultiVersionImportingTestCase() {
" <version>1.0</version>" +
" </plugin>" +
" </plugins>" +
- " </build>")
+ " </build>", false);
- assertModules("project")
+ assertModules("project");
assertSources("project",
"grails-app/controllers",
@@ -90,34 +95,34 @@ class GrailsMavenImporterTest : MavenMultiVersionImportingTestCase() {
"src/java",
"src/main/java",
"src/gwt",
- "src/scala")
- assertDefaultResources("project", "grails-app/resources")
+ "src/scala");
+ assertDefaultResources("project", "grails-app/resources");
assertTestSources("project",
"src/test/java",
"test/integration",
"test/functional",
- "test/unit")
- assertDefaultTestResources("project")
+ "test/unit");
+ assertDefaultTestResources("project");
- val module = getModule("project")
+ Module module = getModule("project");
- val webFacet = FacetManager.getInstance(module).findFacet(WebFacet.ID, "GrailsWeb")
- assertNotNull(webFacet)
+ WebFacet webFacet = FacetManager.getInstance(module).findFacet(WebFacet.ID, "GrailsWeb");
+ assertNotNull(webFacet);
- val appRoot = GrailsFramework.getInstance().findAppRoot(module)
- assertNotNull(appRoot)
+ VirtualFile appRoot = GrailsFramework.getInstance().findAppRoot(module);
+ assertNotNull(appRoot);
- val shouldBeRoot: MutableList<VirtualFile?> = ArrayList(Arrays.asList(
+ List<VirtualFile> shouldBeRoot = new ArrayList<>(Arrays.asList(
VfsUtil.findRelativeFile(appRoot, "web-app"),
VfsUtil.findRelativeFile(appRoot, "grails-app", "views")
- ))
+ ));
- for (webRoot in webFacet!!.getWebRoots()) {
- shouldBeRoot.remove(webRoot.file)
+ for (WebRoot webRoot : webFacet.getWebRoots()) {
+ shouldBeRoot.remove(webRoot.getFile());
}
- assertTrue("Following web folder was not added to web roots: " + shouldBeRoot.toString() + "; " + webFacet.getWebRoots(),
- shouldBeRoot.isEmpty())
+ assertTrue("Following web folder was not added to web roots: " + shouldBeRoot + "; " + webFacet.getWebRoots(),
+ shouldBeRoot.isEmpty());
}
}
diff --git a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/action/DomainFieldIntentionsTest.kt b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/action/DomainFieldIntentionsTest.java
similarity index 54%
rename from plugin/src/test/java/org/jetbrains/plugins/groovy/grails/action/DomainFieldIntentionsTest.kt
rename to plugin/src/test/java/org/jetbrains/plugins/groovy/grails/action/DomainFieldIntentionsTest.java
index 2aa76ed..c559a21 100644
--- a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/action/DomainFieldIntentionsTest.kt
+++ b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/action/DomainFieldIntentionsTest.java
@@ -13,17 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.jetbrains.plugins.groovy.grails.action;
-package org.jetbrains.plugins.groovy.grails.action
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.impl.source.PostprocessReformattingAspect;
+import org.jetbrains.plugins.groovy.grails.GrailsTestCase;
-import com.intellij.openapi.application.ApplicationManager
-import com.intellij.psi.impl.source.PostprocessReformattingAspect
-import org.jetbrains.plugins.groovy.grails.GrailsTestCase
+public class DomainFieldIntentionsTest extends GrailsTestCase {
-class DomainFieldIntentionsTest : GrailsTestCase() {
- fun testInnerClass() {
- val file = addDomain("""
+ public void testInnerClass() {
+ PsiFile file = addDomain("""
+
class City {
String name;
@@ -32,35 +34,38 @@ class City {
String nam<caret>e;
}
}
-""")
+""");
- runIntention(file, "Make property nullable", false)
+ runIntention(file, "Make property nullable", false);
}
- fun testTransientsField() {
- val file = addDomain("""
+ public void testTransientsField() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
static transients = ["name"]
}
-""")
+""");
- runIntention(file, "Make property nullable", false)
+ runIntention(file, "Make property nullable", false);
}
- fun testConstraintsNotExists1() {
- val file = addDomain("""
+ public void testConstraintsNotExists1() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -69,21 +74,23 @@ class City {
name(nullable: true)
}
}
-""")
+""");
}
- fun testConstraintsNotExists2() {
- val file = addDomain("""
+ public void testConstraintsNotExists2() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -92,22 +99,24 @@ class City {
name(nullable: true)
}
}
-""")
+""");
}
- fun testConstraintsWithoutInitializer() {
- val file = addDomain("""
+ public void testConstraintsWithoutInitializer() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
static constraints
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -116,22 +125,24 @@ class City {
name(nullable: true)
}
}
-""")
+""");
}
- fun testConstraintsNull() {
- val file = addDomain("""
+ public void testConstraintsNull() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
static constraints = null
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -140,35 +151,38 @@ class City {
name(nullable: true)
}
}
-""")
+""");
}
- fun testConstraintsWithInvalidInitializer() {
- val file = addDomain("""
+ public void testConstraintsWithInvalidInitializer() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
static constraints = "!!!!!!"
}
-""")
+""");
- runIntention(file, "Make property nullable", false)
+ runIntention(file, "Make property nullable", false);
}
- fun testConstraintsEmpty() {
- val file = addDomain("""
+ public void testConstraintsEmpty() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
static constraints = { }
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -177,19 +191,20 @@ class City {
name(nullable: true)
}
}
-""")
+""");
}
- private fun checkResult(text: String) {
- ApplicationManager.getApplication().runWriteAction {
- PostprocessReformattingAspect.getInstance(project).doPostponedFormatting()
- }
+ private void checkResult(String text) {
+ ApplicationManager.getApplication().runWriteAction(() -> {
+ PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
+ });
- myFixture.checkResult(text)
+ myFixture.checkResult(text);
}
- fun testConstraintsHasFieldDescription() {
- val file = addDomain("""
+ public void testConstraintsHasFieldDescription() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -198,11 +213,12 @@ class City {
name()
}
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -211,11 +227,12 @@ class City {
name(nullable: true)
}
}
-""")
+""");
}
- fun testNullableAlreadyExists() {
- val file = addDomain("""
+ public void testNullableAlreadyExists() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -224,13 +241,14 @@ class City {
name(nullable: true)
}
}
-""")
+""");
- runIntention(file, "Make property nullable", false)
+ runIntention(file, "Make property nullable", false);
}
- fun testNonNullable() {
- val file = addDomain("""
+ public void testNonNullable() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -239,11 +257,12 @@ class City {
name(nullable: false)
}
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -252,11 +271,12 @@ class City {
name(nullable: true)
}
}
-""")
+""");
}
- fun testInvalidValue() {
- val file = addDomain("""
+ public void testInvalidValue() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -265,25 +285,27 @@ class City {
name(nullable: 1 + 2)
}
}
-""")
+""");
- runIntention(file, "Make property nullable", false)
+ runIntention(file, "Make property nullable", false);
}
- fun testMakeNullableOnPrimitiveField() {
- val file = addDomain("""
+ public void testMakeNullableOnPrimitiveField() {
+ PsiFile file = addDomain("""
+
class City {
int siz<caret>e;
}
-""")
+""");
- runIntention(file, "Make property nullable", false)
+ runIntention(file, "Make property nullable", false);
}
- fun testAppStatement1() {
- val file = addDomain("""
+ public void testAppStatement1() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -292,11 +314,12 @@ class City {
name nullable: false
}
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -305,11 +328,12 @@ class City {
name nullable: true
}
}
-""")
+""");
}
- fun testAppStatement2() {
- val file = addDomain("""
+ public void testAppStatement2() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -318,11 +342,12 @@ class City {
name asdasdasd: 4
}
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -331,11 +356,12 @@ class City {
name nullable: true, asdasdasd: 4
}
}
-""")
+""");
}
- fun testCreation1() {
- val file = addDomain("""
+ public void testCreation1() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -344,11 +370,12 @@ class City {
name(nullable:, size: 4)
}
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -357,11 +384,12 @@ class City {
name(nullable: true, size: 4)
}
}
-""")
+""");
}
- fun testCreation2() {
- val file = addDomain("""
+ public void testCreation2() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -370,11 +398,12 @@ class City {
name(nullable: false, size: 4)
}
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -383,11 +412,12 @@ class City {
name(nullable: true, size: 4)
}
}
-""")
+""");
}
- fun testCreation3() {
- val file = addDomain("""
+ public void testCreation3() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -396,11 +426,12 @@ class City {
name(size: 4, nullable: )
}
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -409,11 +440,12 @@ class City {
name(size: 4, nullable: true)
}
}
-""")
+""");
}
- fun testCreation4() {
- val file = addDomain("""
+ public void testCreation4() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -423,11 +455,12 @@ class City {
description(nullable: false)
}
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class City {
String name;
@@ -438,11 +471,12 @@ class City {
name(nullable: true)
}
}
-""")
+""");
}
- fun testMakeUnique() {
- val file = addDomain("""
+ public void testMakeUnique() {
+ PsiFile file = addDomain("""
+
class City {
String nam<caret>e;
@@ -451,11 +485,12 @@ class City {
name()
}
}
-""")
+""");
- runIntention(file, "Make property unique", true)
+ runIntention(file, "Make property unique", true);
checkResult("""
+
class City {
String name;
@@ -464,11 +499,12 @@ class City {
name(unique: true)
}
}
-""")
+""");
}
- fun testMakeUniqueInCommand() {
- val file = addController("""
+ public void testMakeUniqueInCommand() {
+ PsiFile file = addController("""
+
class CccController {
def index = { ZzzCommand com ->
}
@@ -482,13 +518,14 @@ class ZzzCommand {
name()
}
}
-""")
+""");
- runIntention(file, "Make property unique", false)
+ runIntention(file, "Make property unique", false);
}
- fun testMakeNullableInCommand() {
- val file = addController("""
+ public void testMakeNullableInCommand() {
+ PsiFile file = addController("""
+
class CccController {
def index = { ZzzCommand com ->
}
@@ -502,11 +539,12 @@ class ZzzCommand {
name()
}
}
-""")
+""");
- runIntention(file, "Make property nullable", true)
+ runIntention(file, "Make property nullable", true);
checkResult("""
+
class CccController {
def index = { ZzzCommand com ->
}
@@ -520,19 +558,20 @@ class ZzzCommand {
name(nullable: true)
}
}
-""")
+""");
}
- fun testUniqueIsNotApplicable() {
- val file = addDomain("""
+ public void testUniqueIsNotApplicable() {
+ PsiFile file = addDomain("""
+
class City {
Set stree<caret>t;
}
-""")
+""");
- runIntention(file, "Make property unique", false)
+ runIntention(file, "Make property unique", false);
}
-}
\ No newline at end of file
+}
diff --git a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsGroovyI18nIntentionTest.java b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsGroovyI18nIntentionTest.java
new file mode 100644
index 0000000..0de03b5
--- /dev/null
+++ b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsGroovyI18nIntentionTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2000-2026 JetBrains s.r.o. and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.grails.i18n;
+
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.groovy.grails.i18n.GrailsI18nGroovyQuickFixHandler;
+import com.intellij.openapi.util.Trinity;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.plugins.grails.fileType.GspFileType;
+
+import java.util.List;
+
+public class GrailsGroovyI18nIntentionTest extends LightJavaCodeInsightFixtureTestCase {
+
+ private void doTest(String text, String defaultPropertyValue) {
+ doTest(text, defaultPropertyValue, "");
+ }
+
+ private void doTest(String text, String defaultPropertyValue, String args) {
+ PsiFile file = myFixture.configureByText(GspFileType.GSP_FILE_TYPE, text);
+
+ List<IntentionAction> intentions = myFixture.filterAvailableIntentions("Extract");
+ if (intentions.isEmpty()) {
+ assertNull(defaultPropertyValue);
+ return;
+ }
+
+ try {
+ GrailsI18nGroovyQuickFixHandler.INSTANCE.checkApplicability(file, myFixture.getEditor());
+ }
+ catch (IncorrectOperationException e) {
+ assertNull(defaultPropertyValue);
+ return;
+ }
+
+ Trinity<String, String, PsiElement> pair =
+ GrailsI18nGroovyQuickFixHandler.calculatePropertyValue(myFixture.getEditor(), file);
+ assertNotNull(pair);
+
+ assertEquals(defaultPropertyValue, pair.first);
+ assertEquals(args, pair.second);
+ }
+
+ public void testIntention1() {
+ doTest("${\"<caret>aaa\"}", "aaa");
+ }
+
+ public void testIntention2() {
+ doTest("${\"<selection>aaa 12</selection>\"}", "aaa 12");
+ }
+
+ public void testIntention3() {
+ doTest("${<selection>\"aaa\"</selection>}", "aaa");
+ }
+
+ public void testIntention4() {
+ doTest("${\"\"\"<selection>aaa</selection>\"\"\"}", "aaa");
+ }
+
+ public void testIntention5() {
+ doTest("${<selection>\"\"\"aaa\"\"\"</selection>}", "aaa");
+ }
+
+ public void testIntention6() {
+ doTest("${'<selection>aaa</selection>'}", "aaa");
+ }
+
+ public void testIntention7() {
+ doTest("${<selection>'aaa'</selection>}", "aaa");
+ }
+
+ public void testIntentionFalse() {
+ doTest("${'a<selection>a</selection>a'}", null);
+ }
+
+ public void testIntentionGString1() {
+ doTest("${<selection>'a${777}aa'</selection>}", "a${777}aa");
+ }
+
+ public void testIntentionGString2() {
+ doTest("${<selection>\"\"\"a${777}a${888}a\"\"\"</selection>}", "a{0}a{1}a", "777, 888");
+ }
+
+ public void testIntentionGString3() {
+ doTest("${<selection>\"\"\"a${777}a${888}a\"\"\"</selection>}", "a{0}a{1}a", "777, 888");
+ }
+
+ public void testIntentionGString4() {
+ doTest("${\"<caret>a${777}a${888}a\"}", "a{0}a{1}a", "777, 888");
+ }
+
+ public void testIntentionGStringExpression() {
+ doTest("${\"<caret>a$a a\"}", "a{0} a", "a");
+ }
+
+ public void testIntentionGStringSum() {
+ doTest("${\"<caret>a${a + 1} a\"}", "a{0} a", "a + 1");
+ }
+}
diff --git a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsGroovyI18nIntentionTest.kt b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsGroovyI18nIntentionTest.kt
deleted file mode 100644
index 16cb6b5..0000000
--- a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsGroovyI18nIntentionTest.kt
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2000-2026 JetBrains s.r.o. and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jetbrains.plugins.groovy.grails.i18n
-
-import com.intellij.groovy.grails.i18n.GrailsI18nGroovyQuickFixHandler
-import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
-import com.intellij.util.IncorrectOperationException
-import org.jetbrains.plugins.grails.fileType.GspFileType
-
-class GrailsGroovyI18nIntentionTest : LightJavaCodeInsightFixtureTestCase() {
-
- private fun doTest(text: String, defaultPropertyValue: String? = null, args: String = "") {
- val file = myFixture.configureByText(GspFileType.GSP_FILE_TYPE, text)
-
- val intentions = myFixture.filterAvailableIntentions("Extract")
- if (intentions.isEmpty()) {
- assertNull(defaultPropertyValue)
- return
- }
-
- try {
- GrailsI18nGroovyQuickFixHandler.INSTANCE.checkApplicability(file, myFixture.editor)
- }
- catch (e: IncorrectOperationException) {
- assertNull(defaultPropertyValue)
- return
- }
-
- val pair = GrailsI18nGroovyQuickFixHandler.calculatePropertyValue(myFixture.editor, file)
- assertNotNull(pair)
-
- assertEquals(defaultPropertyValue, pair!!.first)
- assertEquals(args, pair.second)
- }
-
- fun testIntention1() {
- doTest("""${'$'}{"<caret>aaa"}""", "aaa")
- }
-
- fun testIntention2() {
- doTest("""${'$'}{"<selection>aaa 12</selection>"}""", "aaa 12")
- }
-
- fun testIntention3() {
- doTest("""${'$'}{<selection>"aaa"</selection>}""", "aaa")
- }
-
- fun testIntention4() {
- doTest("\${\"\"\"<selection>aaa</selection>\"\"\"}", "aaa")
- }
-
- fun testIntention5() {
- doTest("\${<selection>\"\"\"aaa\"\"\"</selection>}", "aaa")
- }
-
- fun testIntention6() {
- doTest("""${'$'}{'<selection>aaa</selection>'}""", "aaa")
- }
-
- fun testIntention7() {
- doTest("""${'$'}{<selection>'aaa'</selection>}""", "aaa")
- }
-
- fun testIntentionFalse() {
- doTest("""${'$'}{'a<selection>a</selection>a'}""", null)
- }
-
- fun testIntentionGString1() {
- doTest("""${'$'}{<selection>'a${'$'}{777}aa'</selection>}""", "a${'$'}{777}aa")
- }
-
- fun testIntentionGString2() {
- doTest("\${<selection>\"\"\"a${'$'}{777}a\${888}a\"\"\"</selection>}", "a{0}a{1}a", "777, 888")
- }
-
- fun testIntentionGString3() {
- doTest("\${<selection>\"\"\"a\${777}a\${888}a\"\"\"</selection>}", "a{0}a{1}a", "777, 888")
- }
-
- fun testIntentionGString4() {
- doTest("""${'$'}{"<caret>a${'$'}{777}a${'$'}{888}a"}""", "a{0}a{1}a", "777, 888")
- }
-
- fun testIntentionGStringExpression() {
- doTest("""${'$'}{"<caret>a${'$'}a a"}""", "a{0} a", "a")
- }
-
- fun testIntentionGStringSum() {
- doTest("""${'$'}{"<caret>a${'$'}{a + 1} a"}""", "a{0} a", "a + 1")
- }
-}
\ No newline at end of file
diff --git a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsI18nInspectionTest.kt b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsI18nInspectionTest.java
similarity index 55%
rename from plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsI18nInspectionTest.kt
rename to plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsI18nInspectionTest.java
index 020124c..aca731c 100644
--- a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsI18nInspectionTest.kt
+++ b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GrailsI18nInspectionTest.java
@@ -13,52 +13,58 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.jetbrains.plugins.groovy.grails.i18n;
-package org.jetbrains.plugins.groovy.grails.i18n
+import com.intellij.codeInspection.InspectionProfileEntry;
+import com.intellij.codeInspection.ex.InspectionToolWrapper;
+import com.intellij.groovy.grails.i18n.GrailsI18nInspection;
+import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
+import com.intellij.psi.PsiFile;
+import org.jetbrains.plugins.groovy.grails.GrailsTestCase;
-import com.intellij.codeInspection.ex.InspectionToolWrapper
-import com.intellij.groovy.grails.i18n.GrailsI18nInspection
-import com.intellij.profile.codeInspection.InspectionProjectProfileManager
-import org.jetbrains.plugins.groovy.grails.GrailsTestCase
+import java.util.List;
-class GrailsI18nInspectionTest : GrailsTestCase() {
+public class GrailsI18nInspectionTest extends GrailsTestCase {
- override fun setUp() {
- super.setUp()
- myFixture.enableInspections(GrailsI18nInspection::class.java)
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ myFixture.enableInspections(GrailsI18nInspection.class);
}
- private fun setIgnoreIfDefault(value: Boolean) {
- val tool = InspectionProjectProfileManager.getInstance(project).currentProfile.getInspectionTool(
- GrailsI18nInspection().shortName, project)
- val inspection = (tool as InspectionToolWrapper).tool as GrailsI18nInspection
-
- inspection.ignoreTagsWithDefault = value
+ private void setIgnoreIfDefault(boolean value) {
+ InspectionToolWrapper<?, ?> tool = InspectionProjectProfileManager.getInstance(getProject()).getCurrentProfile()
+ .getInspectionTool(new GrailsI18nInspection().getShortName(), getProject());
+ InspectionProfileEntry inspection = tool.getTool();
+ ((GrailsI18nInspection)inspection).ignoreTagsWithDefault = value;
}
- fun testCodeReference() {
+ public void testCodeReference() {
myFixture.addFileToProject("grails-app/i18n/messages.properties", """
+
aaa1=Aaaa1
aaa2=Aaaa2
bbb=Bbbb
-""")
+""");
- myFixture.addFileToProject("grails-app/views/a.gsp", "<g:message code='aa<caret>' />")
+ myFixture.addFileToProject("grails-app/views/a.gsp", "<g:message code='aa<caret>' />");
- assertEquals(listOf("aaa1", "aaa2"), myFixture.getCompletionVariants("grails-app/views/a.gsp"))
+ assertEquals(List.of("aaa1", "aaa2"), myFixture.getCompletionVariants("grails-app/views/a.gsp"));
}
- fun testHighlightingGsp() {
- setIgnoreIfDefault(true)
+ public void testHighlightingGsp() {
+ setIgnoreIfDefault(true);
myFixture.addFileToProject("grails-app/i18n/messages.properties", """
+
aaa.bbb=Aaa bbb
-""")
+""");
+
+ PsiFile gsp = addView("aaa.gsp", """
- val gsp = addView("aaa.gsp", """
<g:message code="aaa.bbb" />
<g:message code="<error descr="Cannot resolve property key">aaa.bbb.sss</error>" />
-<g:message code="aaa.${"$"}{xxx}" />
+<g:message code="aaa.${xxx}" />
<g:message code="asdaskdjaskdaj" default="Default Text" />
<<error descr="Element tooltip:tip is not allowed here">tooltip:tip</error> code="sdfsdfsdf" />
@@ -68,46 +74,50 @@ aaa.bbb=Aaa bbb
<%--suppress InvalidI18nProperty --%>
<g:sortableColumn titleKey="sdfsdfsdf" />
-""")
+""");
- myFixture.testHighlighting(true, false, true, gsp.virtualFile)
+ myFixture.testHighlighting(true, false, true, gsp.getVirtualFile());
}
- fun testSuppressionWarningForFile() {
- val gsp = addView("aaa.gsp", """
+ public void testSuppressionWarningForFile() {
+ PsiFile gsp = addView("aaa.gsp", """
+
<%--suppress InvalidI18nProperty --%>
<div />
<g:sortableColumn titleKey="sdfsdfsdf" />
-""")
+""");
- myFixture.testHighlighting(true, false, true, gsp.virtualFile)
+ myFixture.testHighlighting(true, false, true, gsp.getVirtualFile());
}
- fun testSuppressionAllWarningInFile() {
- val gsp = addView("aaa.gsp", """
+ public void testSuppressionAllWarningInFile() {
+ PsiFile gsp = addView("aaa.gsp", """
+
<%--suppress ALL --%>
<div />
<g:sortableColumn titleKey="sdfsdfsdf" />
-""")
+""");
- myFixture.testHighlighting(true, false, true, gsp.virtualFile)
+ myFixture.testHighlighting(true, false, true, gsp.getVirtualFile());
}
- fun testHighlightingGroovy() {
- setIgnoreIfDefault(true)
+ public void testHighlightingGroovy() {
+ setIgnoreIfDefault(true);
myFixture.addFileToProject("grails-app/i18n/messages.properties", """
+
aaa.bbb=Aaa bbb
-""")
+""");
+
+ PsiFile file = addController("""
- val file = addController("""
class CccController {
def index = {
g.message(code:"aaa.bbb")
g.message(code:"<error descr="Cannot resolve property key">aaa.bbb.sss</error>")
- g.message(code:"aaa.${'$'}{xxx}")
+ g.message(code:"aaa.${xxx}")
g.message(code:"asdaskdjaskdaj", default:"Default Text")
g.sortableColumn(titleKey:"<error descr="Cannot resolve property key">sdfsdfsdf</error>")
@@ -122,50 +132,53 @@ class CccController {
g.sortableColumn(titleKey:"sdfsdfsdf")
}
}
-""")
+""");
- myFixture.testHighlighting(true, false, true, file.virtualFile)
+ myFixture.testHighlighting(true, false, true, file.getVirtualFile());
}
- fun testHighlighting2() {
- setIgnoreIfDefault(false)
+ public void testHighlighting2() {
+ setIgnoreIfDefault(false);
+
+ PsiFile file = addController("""
- val file = addController("""
class CccController {
def index = {
g.sortableColumn(titleKey:"<error>sdfsdfsdf</error>", title:"Default Text")
}
}
-""")
+""");
- myFixture.testHighlighting(true, false, true, file.virtualFile)
+ myFixture.testHighlighting(true, false, true, file.getVirtualFile());
}
- fun testCreatePropertyGsp() {
- setIgnoreIfDefault(false)
+ public void testCreatePropertyGsp() {
+ setIgnoreIfDefault(false);
myFixture.addFileToProject("grails-app/i18n/messages.properties", """
+
aaa.bbb=Aaa bbb
-""")
+""");
- configureByView("aaa.gsp", "<g:message code='aaa.bbb.ccc<caret>' />")
+ configureByView("aaa.gsp", "<g:message code='aaa.bbb.ccc<caret>' />");
- val intentions = myFixture.filterAvailableIntentions("Create property")
- assertSize(1, intentions)
+ var intentions = myFixture.filterAvailableIntentions("Create property");
+ assertSize(1, intentions);
- assertEmpty(myFixture.filterAvailableIntentions("Don't check"))
+ assertEmpty(myFixture.filterAvailableIntentions("Don't check"));
}
- fun testCreatePropertyGsp2() {
- setIgnoreIfDefault(false)
+ public void testCreatePropertyGsp2() {
+ setIgnoreIfDefault(false);
myFixture.addFileToProject("grails-app/i18n/messages.properties", """
+
aaa.bbb=Aaa bbb
-""")
+""");
- configureByView("aaa.gsp", "<g:message code='aaa.bbb.ccc<caret>' default='aaa'/>")
+ configureByView("aaa.gsp", "<g:message code='aaa.bbb.ccc<caret>' default='aaa'/>");
- assertSize(1, myFixture.filterAvailableIntentions("Create property"))
- assertSize(1, myFixture.filterAvailableIntentions("Don't check"))
+ assertSize(1, myFixture.filterAvailableIntentions("Create property"));
+ assertSize(1, myFixture.filterAvailableIntentions("Don't check"));
}
}
diff --git a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GspI18nIntentionTest.java b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GspI18nIntentionTest.java
new file mode 100644
index 0000000..9e3a814
--- /dev/null
+++ b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GspI18nIntentionTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2000-2026 JetBrains s.r.o. and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.grails.i18n;
+
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.groovy.grails.i18n.GrailsI18nQuickFixHandler;
+import com.intellij.openapi.util.Couple;
+import com.intellij.psi.PsiFile;
+import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.plugins.grails.fileType.GspFileType;
+
+import java.util.List;
+
+public class GspI18nIntentionTest extends LightJavaCodeInsightFixtureTestCase {
+
+ private void doTest(String text) {
+ doTest(text, null, null);
+ }
+
+ private void doTest(String text, String defaultPropertyValue, String args) {
+ PsiFile file = myFixture.configureByText(GspFileType.GSP_FILE_TYPE, text);
+
+ List<IntentionAction> intentions = myFixture.filterAvailableIntentions("Extract");
+ if (intentions.isEmpty()) {
+ assertNull(defaultPropertyValue);
+ return;
+ }
+
+ try {
+ GrailsI18nQuickFixHandler.INSTANCE.checkApplicability(file, myFixture.getEditor());
+ }
+ catch (IncorrectOperationException e) {
+ assertNull(defaultPropertyValue);
+ return;
+ }
+
+ Couple<String> pair = GrailsI18nQuickFixHandler.calculatePropertyValue(myFixture.getEditor(), file);
+ assertNotNull(pair);
+
+ assertEquals(defaultPropertyValue, pair.first);
+ assertEquals(args, pair.second);
+ }
+
+ public void testIntention1() {
+ doTest("\na<selection>aa\nsda</selection>\n", "aa\nsda", "");
+ }
+
+ public void testIntention2() {
+ doTest("\na<selection>aa<% out << 1 %>sda</selection>\n");
+ }
+
+ public void testIntention21() {
+ doTest("\na<selection>aasda${</selection>2}\n");
+ }
+
+ public void testIntention22() {
+ doTest("\na${1<selection>}aasda</selection>\n");
+ }
+
+ public void testIntention3() {
+ doTest("a<selection><div>aasda</div></selection>", "<div>aasda</div>", "");
+ }
+
+ public void testIntention4() {
+ doTest("a<selection><g:link/></selection>");
+ }
+
+ public void testIntention5() {
+ doTest("a<caret>aa");
+ }
+
+ public void testIntention6() {
+ doTest("a<% 1 %><selection>${aaa}</selection><% out << \"aaa\" %>", "{0}", "aaa");
+ }
+
+ public void testIntention7() {
+ doTest("a<selection>a ${aaa} s <%= 777 * 5 %> </selection> sdsa", "a {0} s {1} ", "aaa, 777 * 5");
+ }
+
+ public void testIntention8() {
+ doTest("<selection>aaa${777}bbb${'!' + actionName + 'aaa'}</selection>", "aaa{0}bbb{1}",
+ "777, '!' + actionName + 'aaa'");
+ }
+
+ public void testIntention9() {
+ doTest("<selection>aaa${777}${777}</selection>", "aaa{0}{1}", "777, 777");
+ }
+
+ public void testIntention10() {
+ doTest("<input class=\"button green medium\" type=\"button\" value=\"<selection>Subscribe</selection>\"/>",
+ "Subscribe", "");
+ }
+
+ public void testIntention11() {
+ doTest("<input class=\"button green medium\" type=\"button\" value=\"<selection>Subscribe ${aaa}</selection>\"/>",
+ "Subscribe {0}", "aaa");
+ }
+
+ public void testIntention12() {
+ doTest("<input class=\"button green medium\" type=\"button\" <selection>value=\"Subscribe</selection>\"/>");
+ }
+}
diff --git a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GspI18nIntentionTest.kt b/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GspI18nIntentionTest.kt
deleted file mode 100644
index 7750cdd..0000000
--- a/plugin/src/test/java/org/jetbrains/plugins/groovy/grails/i18n/GspI18nIntentionTest.kt
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2000-2026 JetBrains s.r.o. and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jetbrains.plugins.groovy.grails.i18n
-
-import com.intellij.groovy.grails.i18n.GrailsI18nQuickFixHandler
-import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
-import com.intellij.util.IncorrectOperationException
-import org.jetbrains.plugins.grails.fileType.GspFileType
-
-class GspI18nIntentionTest : LightJavaCodeInsightFixtureTestCase() {
-
- private fun doTest(text: String, defaultPropertyValue: String? = null, args: String? = null) {
- val file = myFixture.configureByText(GspFileType.GSP_FILE_TYPE, text)
-
- val intentions = myFixture.filterAvailableIntentions("Extract")
- if (intentions.isEmpty()) {
- assertNull(defaultPropertyValue)
- return
- }
-
- try {
- GrailsI18nQuickFixHandler.INSTANCE.checkApplicability(file, myFixture.editor)
- }
- catch (e: IncorrectOperationException) {
- assertNull(defaultPropertyValue)
- return
- }
-
- val pair = GrailsI18nQuickFixHandler.calculatePropertyValue(myFixture.editor, file)
- assertNotNull(pair)
-
- assertEquals(defaultPropertyValue, pair!!.first)
- assertEquals(args, pair.second)
- }
-
- fun testIntention1() {
- doTest(
- """
-a<selection>aa
-sda</selection>
-""", "aa\nsda", ""
- )
- }
-
- fun testIntention2() {
- doTest(
- """
-a<selection>aa<% out << 1 %>sda</selection>
-"""
- )
- }
-
- fun testIntention21() {
- doTest("""
-a<selection>aasda${'$'}{</selection>2}
-""")
- }
-
- fun testIntention22() {
- doTest("""
-a${'$'}{1<selection>}aasda</selection>
-""")
- }
-
- fun testIntention3() {
- doTest("a<selection><div>aasda</div></selection>", "<div>aasda</div>", "")
- }
-
- fun testIntention4() {
- doTest("a<selection><g:link/></selection>")
- }
-
- fun testIntention5() {
- doTest("a<caret>aa")
- }
-
- fun testIntention6() {
- doTest("a<% 1 %><selection>${'$'}{aaa}</selection><% out << \"aaa\" %>", "{0}", "aaa")
- }
-
- fun testIntention7() {
- doTest("a<selection>a ${'$'}{aaa} s <%= 777 * 5 %> </selection> sdsa", "a {0} s {1} ", "aaa, 777 * 5")
- }
-
- fun testIntention8() {
- doTest("<selection>aaa${'$'}{777}bbb${'$'}{'!' + actionName + 'aaa'}</selection>", "aaa{0}bbb{1}", "777, '!' + actionName + 'aaa'")
- }
-
- fun testIntention9() {
- doTest("<selection>aaa${'$'}{777}${'$'}{777}</selection>", "aaa{0}{1}", "777, 777")
- }
-
- fun testIntention10() {
- doTest("<input class=\"button green medium\" type=\"button\" value=\"<selection>Subscribe</selection>\"/>", "Subscribe", "")
- }
-
- fun testIntention11() {
- doTest("<input class=\"button green medium\" type=\"button\" value=\"<selection>Subscribe ${'$'}{aaa}</selection>\"/>", "Subscribe {0}", "aaa")
- }
-
- fun testIntention12() {
- doTest("<input class=\"button green medium\" type=\"button\" <selection>value=\"Subscribe</selection>\"/>")
- }
-}