diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java index 826b03afbe..17ff6788b3 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java @@ -5344,6 +5344,29 @@ public void testCompileStatic9799() { runConformTest(sources, "works"); } + @Test + public void testCompileStatic9855() { + //@formatter:off + String[] sources = { + "Main.groovy", + "@groovy.transform.CompileStatic\n" + + "@SuppressWarnings(C.PREFIX + 'checked')\n" + // not 'un'.plus('checked') + "class C {\n" + + " public static final String PREFIX = 'un'\n" + + "}\n" + + "new C()\n", + }; + //@formatter:on + + runNegativeTest(sources, + "----------\n" + + "1. WARNING in Main.groovy (at line 2)\n" + + "\t@SuppressWarnings(C.PREFIX + 'checked')\n" + + "\t ^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unchecked\")\n" + + "----------\n"); + } + @Test public void testCompileStatic9860() { //@formatter:off diff --git a/base/org.codehaus.groovy25/src/org/apache/groovy/ast/tools/ExpressionUtils.java b/base/org.codehaus.groovy25/src/org/apache/groovy/ast/tools/ExpressionUtils.java index f630fe092a..ca1b928a01 100644 --- a/base/org.codehaus.groovy25/src/org/apache/groovy/ast/tools/ExpressionUtils.java +++ b/base/org.codehaus.groovy25/src/org/apache/groovy/ast/tools/ExpressionUtils.java @@ -350,9 +350,21 @@ public static Expression transformInlineConstants(final Expression exp) { } } else if (exp instanceof BinaryExpression) { BinaryExpression be = (BinaryExpression) exp; + /* GRECLIPSE edit -- GROOVY-9855: inline string concat sooner be.setLeftExpression(transformInlineConstants(be.getLeftExpression())); be.setRightExpression(transformInlineConstants(be.getRightExpression())); return be; + */ + Expression lhs = transformInlineConstants(be.getLeftExpression()); + Expression rhs = transformInlineConstants(be.getRightExpression()); + if (be.getOperation().getType() == PLUS && lhs instanceof ConstantExpression && rhs instanceof ConstantExpression && + lhs.getType().equals(ClassHelper.STRING_TYPE) && rhs.getType().equals(ClassHelper.STRING_TYPE)) { + return configure(be, new ConstantExpression(lhs.getText() + rhs.getText())); + } + be.setLeftExpression(lhs); + be.setRightExpression(rhs); + return be; + // GRECLIPSE end } else if (exp instanceof ListExpression) { ListExpression origList = (ListExpression) exp; ListExpression newList = new ListExpression(); diff --git a/base/org.codehaus.groovy30/src/org/apache/groovy/ast/tools/ExpressionUtils.java b/base/org.codehaus.groovy30/src/org/apache/groovy/ast/tools/ExpressionUtils.java index 855bf4e0ed..94909d62f7 100644 --- a/base/org.codehaus.groovy30/src/org/apache/groovy/ast/tools/ExpressionUtils.java +++ b/base/org.codehaus.groovy30/src/org/apache/groovy/ast/tools/ExpressionUtils.java @@ -337,9 +337,21 @@ public static Expression transformInlineConstants(final Expression exp) { } } else if (exp instanceof BinaryExpression) { BinaryExpression be = (BinaryExpression) exp; + /* GRECLIPSE edit -- GROOVY-9855: inline string concat sooner be.setLeftExpression(transformInlineConstants(be.getLeftExpression())); be.setRightExpression(transformInlineConstants(be.getRightExpression())); return be; + */ + Expression lhs = transformInlineConstants(be.getLeftExpression()); + Expression rhs = transformInlineConstants(be.getRightExpression()); + if (be.getOperation().getType() == PLUS && lhs instanceof ConstantExpression && rhs instanceof ConstantExpression && + lhs.getType().equals(ClassHelper.STRING_TYPE) && rhs.getType().equals(ClassHelper.STRING_TYPE)) { + return configure(be, new ConstantExpression(lhs.getText() + rhs.getText())); + } + be.setLeftExpression(lhs); + be.setRightExpression(rhs); + return be; + // GRECLIPSE end } else if (exp instanceof ListExpression) { ListExpression origList = (ListExpression) exp; ListExpression newList = new ListExpression(); diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java index f1e385ece0..6acad11581 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java @@ -89,6 +89,7 @@ import org.codehaus.groovy.syntax.PreciseSyntaxException; import org.codehaus.groovy.syntax.SyntaxException; import org.codehaus.groovy.syntax.Token; +import org.codehaus.groovy.syntax.Types; import org.codehaus.groovy.tools.GroovyClass; import org.codehaus.jdt.groovy.control.EclipseSourceUnit; import org.codehaus.jdt.groovy.core.dom.GroovyCompilationUnit; @@ -1655,8 +1656,18 @@ private org.eclipse.jdt.internal.compiler.ast.Expression createAnnotationMemberE return new ClassLiteralAccess(expr.getStart() - 1, new Wildcard(Wildcard.UNBOUND)); } else if (expr instanceof BinaryExpression) { - // annotation may be something like "@Tag(value = List