From ad5c02e81d40ba2b6dc57574dcaec590767afaae Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Sat, 26 Jun 2021 10:19:14 -0500 Subject: [PATCH] Fix for #1231: skip problem annotations from JDT bindings for Groovy AST --- .../model/GroovyCompilationUnitTests.java | 571 ++++++++---------- .../tests/model/GroovyPartialModelTests.java | 23 +- .../tests/model/GroovyTypeRootTestSuite.java | 23 +- .../tests/model/MoveRenameCopyTests.java | 8 +- .../ast/GroovyCompilationUnitDeclaration.java | 4 +- .../compiler/ast/JDTAnnotationNode.java | 4 +- .../internal/compiler/ast/JDTClassNode.java | 6 +- .../internal/compiler/ast/JDTFieldNode.java | 6 +- .../internal/compiler/ast/JDTMethodNode.java | 4 +- .../internal/compiler/ast/JDTResolver.java | 16 +- .../build.properties | 4 +- 11 files changed, 294 insertions(+), 375 deletions(-) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyCompilationUnitTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyCompilationUnitTests.java index 0aa8728f01..954689baef 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyCompilationUnitTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyCompilationUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 the original author or authors. + * Copyright 2009-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Set; import org.codehaus.groovy.ast.ClassNode; @@ -32,8 +31,8 @@ import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; import org.codehaus.jdt.groovy.model.ModuleNodeMapper; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jdt.core.IAnnotatable; import org.eclipse.jdt.core.IAnnotation; import org.eclipse.jdt.core.ICompilationUnit; @@ -42,7 +41,6 @@ import org.eclipse.jdt.core.IMemberValuePair; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.groovy.core.util.JavaConstants; @@ -51,104 +49,104 @@ public final class GroovyCompilationUnitTests extends GroovyTypeRootTestSuite { @Test - public void testCreateJavaCompilationUnit() throws Exception { - IPath projectPath = env.addProject("Project"); - fullBuild(projectPath); - - IPath root = env.getPackageFragmentRootPath(projectPath, "src"); - - IPath path = env.addClass(root, "p1", "Hello", - "package p1;\n" + + public void testJavaCompilationUnit() throws Exception { + IPath project = env.addProject("Project"); + IPath src = env.getPackageFragmentRootPath(project, "src"); + ICompilationUnit unit = env.getUnit(env.addClass(src, "p", "Hello", + "package p;\n" + "public class Hello {\n" + " public static void main(String[] args) {\n" + " System.out.println(\"Hello world\");\n" + " }\n" + "}" - ); - - ICompilationUnit unit = env.getUnit(path); + )); assertTrue(unit.exists()); assertFalse(unit instanceof GroovyCompilationUnit); } @Test - public void testCreateGroovyCompilationUnit() throws Exception { + public void testGroovyCompilationUnit() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - ICompilationUnit unit = JavaCore.createCompilationUnitFrom(groovyFile); - assertTrue("CompilationUnit " + groovyFile + " should exist.", unit.exists()); - assertTrue("CompilationUnit " + groovyFile + " should be a Groovy compilation unit.", unit instanceof GroovyCompilationUnit); + ICompilationUnit unit = env.getUnit(groovyFile.getFullPath()); + + assertTrue(unit.exists()); + assertTrue(unit instanceof GroovyCompilationUnit); } @Test public void testGetModuleNode1() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); - unit1.becomeWorkingCopy(null); - ModuleNode node1 = unit1.getModuleNode(); - ModuleNode node2 = unit1.getModuleNode(); + GroovyCompilationUnit unit = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); + unit.becomeWorkingCopy(null); + ModuleNode node1 = unit.getModuleNode(); + ModuleNode node2 = unit.getModuleNode(); + unit.discardWorkingCopy(); + assertSame("getModuleNode() should return the same object if nothing has changed underneath", node1, node2); - unit1.discardWorkingCopy(); } @Test public void testGetModuleNode2() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); + GroovyCompilationUnit unit1 = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); unit1.becomeWorkingCopy(null); ModuleNode node1 = unit1.getModuleNode(); - GroovyCompilationUnit unit2 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); + GroovyCompilationUnit unit2 = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); unit2.becomeWorkingCopy(null); ModuleNode node2 = unit2.getModuleNode(); - assertSame("getModuleNode() should return the same object if nothing has changed underneath", node1, node2); unit1.discardWorkingCopy(); unit2.discardWorkingCopy(); + + assertSame("getModuleNode() should return the same object if nothing has changed underneath", node1, node2); } @Test public void testGetModuleNode3() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); - unit1.becomeWorkingCopy(null); - ModuleNode node1 = unit1.getModuleNode(); - unit1.reconcile(JavaConstants.AST_LEVEL, true, unit1.owner, null); - ModuleNode node2 = unit1.getModuleNode(); + GroovyCompilationUnit unit = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); + unit.becomeWorkingCopy(null); + ModuleNode node1 = unit.getModuleNode(); + unit.reconcile(JavaConstants.AST_LEVEL, true, unit.owner, null); + ModuleNode node2 = unit.getModuleNode(); + unit.discardWorkingCopy(); + assertNotSame("getModuleNode() should not return the same object after a call to reconcile with problem detection enabled", node1, node2); - unit1.discardWorkingCopy(); } @Test - @SuppressWarnings("rawtypes") public void testGetModuleNode4() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); - unit1.becomeWorkingCopy(null); - ModuleNode node1 = unit1.getModuleNode(); - unit1.makeConsistent(JavaConstants.AST_LEVEL, true, ICompilationUnit.FORCE_PROBLEM_DETECTION, new HashMap(), null); - ModuleNode node2 = unit1.getModuleNode(); + GroovyCompilationUnit unit = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); + unit.becomeWorkingCopy(null); + ModuleNode node1 = unit.getModuleNode(); + unit.makeConsistent(JavaConstants.AST_LEVEL, true, ICompilationUnit.FORCE_PROBLEM_DETECTION, new HashMap<>(), null); + ModuleNode node2 = unit.getModuleNode(); + unit.discardWorkingCopy(); + assertSame("getModuleNode() should return the same object if nothing has changed underneath", node1, node2); - unit1.discardWorkingCopy(); } @Test public void testGetModuleNode5() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); - unit1.becomeWorkingCopy(null); - ModuleNode node1 = unit1.getModuleNode(); - unit1.getBuffer().append(" "); - ModuleNode node2 = unit1.getModuleNode(); + GroovyCompilationUnit unit = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); + unit.becomeWorkingCopy(null); + ModuleNode node1 = unit.getModuleNode(); + unit.getBuffer().append(" "); + ModuleNode node2 = unit.getModuleNode(); + unit.discardWorkingCopy(); + assertNotSame("getModuleNode() should return different objects if something has changed underneath", node1, node2); - unit1.discardWorkingCopy(); } @Test public void testGetModuleNode6() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); + GroovyCompilationUnit unit1 = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); unit1.becomeWorkingCopy(null); ModuleNode node1 = unit1.getModuleNode(); - GroovyCompilationUnit unit2 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); + GroovyCompilationUnit unit2 = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); unit2.becomeWorkingCopy(null); ModuleNode node2 = unit2.getModuleNode(); unit1.getBuffer().append(" "); @@ -165,10 +163,10 @@ public void testGetModuleNode6() throws Exception { @Test public void testGetModuleNode7() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); + GroovyCompilationUnit unit1 = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); unit1.becomeWorkingCopy(null); unit1.getModuleNode(); - GroovyCompilationUnit unit2 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); + GroovyCompilationUnit unit2 = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); unit2.becomeWorkingCopy(null); unit2.getModuleNode(); unit1.getBuffer().append(" "); @@ -183,10 +181,9 @@ public void testGetModuleNode7() throws Exception { @Test public void testGetModuleNode8() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); - ModuleNode node1 = unit1.getModuleNode(); - ModuleNode node2 = unit1.getModuleNode(); - unit1.discardWorkingCopy(); + GroovyCompilationUnit unit = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); + ModuleNode node1 = unit.getModuleNode(); + ModuleNode node2 = unit.getModuleNode(); assertNotSame("getModuleNode() should return the different objects if unit is not a working copy", node1, node2); } @@ -194,12 +191,12 @@ public void testGetModuleNode8() throws Exception { @Test public void testGetModuleNode9() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); - unit1.becomeWorkingCopy(null); - ModuleNode node1 = unit1.getModuleNode(); - unit1.reconcile(true, null); - ModuleNode node2 = unit1.getModuleNode(); - unit1.discardWorkingCopy(); + GroovyCompilationUnit unit = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); + unit.becomeWorkingCopy(null); + ModuleNode node1 = unit.getModuleNode(); + unit.reconcile(true, null); + ModuleNode node2 = unit.getModuleNode(); + unit.discardWorkingCopy(); assertNotSame("getModuleNode() should return the different objects after a call to reconcile with force problem detection", node1, node2); } @@ -207,371 +204,295 @@ public void testGetModuleNode9() throws Exception { @Test public void testGetModuleNode10() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); - unit1.becomeWorkingCopy(null); - ModuleNode node1 = unit1.getModuleNode(); - unit1.reconcile(false, null); - ModuleNode node2 = unit1.getModuleNode(); - unit1.discardWorkingCopy(); + GroovyCompilationUnit unit = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); + unit.becomeWorkingCopy(null); + ModuleNode node1 = unit.getModuleNode(); + unit.reconcile(false, null); + ModuleNode node2 = unit.getModuleNode(); + unit.discardWorkingCopy(); assertSame("getModuleNode() should return the same object after a call to reconcile with no force problem detection", node1, node2); } @Test - public void testGetNewModuleNode() throws Exception { + public void testGetModuleNode11() throws Exception { IFile groovyFile = createSimpleGroovyProject(); - GroovyCompilationUnit unit1 = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(groovyFile); - ModuleNode module1 = unit1.getModuleNode(); - ModuleNode module2 = unit1.getNewModuleInfo().module; - unit1.discardWorkingCopy(); + GroovyCompilationUnit unit = Adapters.adapt(groovyFile, GroovyCompilationUnit.class); + ModuleNode module1 = unit.getModuleNode(); + ModuleNode module2 = unit.getNewModuleInfo().module; assertNotSame("getNewModuleNode() should have forced creation of a new module node", module1, module2); } @Test public void testMarkerAnnotation1() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + "@Anno2\n" + - "public class X {\n" + - " public int foo = 5\n" + - " public static void main(String[]argv) {\n" + - " print \"success\"\n" + - " }\n" + + "class C {\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); - assertEquals("Should have one annotation on type X", 1, type.getAnnotations().length); - IAnnotation annotation = type.getAnnotations()[0]; - assertMarkerAnnotation(annotation, "Anno2"); + IType type = unit.getType("C"); + IAnnotation[] annotations = type.getAnnotations(); + + assertEquals(1, annotations.length); + assertMarkerAnnotation(annotations[0], "Anno2"); } @Test public void testMarkerAnnotation2() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + - "public class X {\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + " @Anno2\n" + - " public int foo = 5\n" + - " public static void m() {\n" + - " print \"success\"\n" + - " }\n" + + " public int f\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); - IField field = type.getField("foo"); - assertEquals("Should have one annotation on field foo", 1, field.getAnnotations().length); - IAnnotation annotation = field.getAnnotations()[0]; - assertMarkerAnnotation(annotation, "Anno2"); + IType type = unit.getType("C"); + IField field = type.getField("f"); + IAnnotation[] annotations = field.getAnnotations(); + + assertEquals(1, annotations.length); + assertMarkerAnnotation(annotations[0], "Anno2"); } @Test public void testMarkerAnnotation3() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + - "public class X {\n" + - " public int foo = 5\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + " @Anno2\n" + - " public static void m() {\n" + - " print \"success\"\n" + + " void m() {\n" + " }\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); + IType type = unit.getType("C"); IMethod method = type.getMethod("m", new String[0]); - assertEquals("Should have one annotation on method main()", 1, method.getAnnotations().length); - IAnnotation annotation = method.getAnnotations()[0]; - assertMarkerAnnotation(annotation, "Anno2"); + IAnnotation[] annotations = method.getAnnotations(); + + assertEquals(1, annotations.length); + assertMarkerAnnotation(annotations[0], "Anno2"); } @Test public void testMarkerAnnotation4() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + "@p.Anno2\n" + - "public class X {\n" + - " public int foo = 5\n" + - " public static void main(String[]argv) {\n" + - " print \"success\"\n" + - " }\n" + + "class C {\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); - assertEquals("Should have one annotation on type X", 1, type.getAnnotations().length); - IAnnotation annotation = type.getAnnotations()[0]; - assertMarkerAnnotation(annotation, "p.Anno2"); + IType type = unit.getType("C"); + IAnnotation[] annotations = type.getAnnotations(); + + assertEquals(1, annotations.length); + assertMarkerAnnotation(annotations[0], "p.Anno2"); } @Test public void testMarkerAnnotation5() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + - "public class X {\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + " @p.Anno2\n" + - " public int foo = 5\n" + - " public static void m() {\n" + - " print \"success\"\n" + - " }\n" + + " public int f\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); - IField field = type.getField("foo"); - assertEquals("Should have one annotation on field foo", 1, field.getAnnotations().length); - IAnnotation annotation = field.getAnnotations()[0]; - assertMarkerAnnotation(annotation, "p.Anno2"); + IType type = unit.getType("C"); + IField field = type.getField("f"); + IAnnotation[] annotations = field.getAnnotations(); + + assertEquals(1, annotations.length); + assertMarkerAnnotation(annotations[0], "p.Anno2"); } @Test public void testMarkerAnnotation6() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + - "public class X {\n" + - " public int foo = 5\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + " @p.Anno2\n" + - " public static void m() {\n" + - " print \"success\"\n" + + " void m() {\n" + " }\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); + IType type = unit.getType("C"); IMethod method = type.getMethod("m", new String[0]); - assertEquals("Should have one annotation on method main()", 1, method.getAnnotations().length); - IAnnotation annotation = method.getAnnotations()[0]; - assertMarkerAnnotation(annotation, "p.Anno2"); + IAnnotation[] annotations = method.getAnnotations(); + + assertEquals(1, annotations.length); + assertMarkerAnnotation(annotations[0], "p.Anno2"); } @Test public void testMarkerAnnotation7() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + - "class X {\n" + - " @Anno2\n" + - " X() {\n" + - " }\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + + " @p.Anno2\n" + + " C() {}\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - - GroovyCompilationUnit unit = env.getUnit(path); - IMethod method = unit.getType("X").getMethods()[0]; + IMethod method = unit.getType("C").getMethods()[0]; IAnnotation[] annotations = method.getAnnotations(); assertEquals(1, annotations.length); - assertMarkerAnnotation(annotations[0], "Anno2"); - } + assertMarkerAnnotation(annotations[0], "p.Anno2"); - @Test - @SuppressWarnings("rawtypes") - public void testMarkerAnnotation8() throws Exception { // source references to Groovy types go from Groovy AST -> GCUD -> JDT bindings -> Groovy AST - IPath root = createAnnotationGroovyProject(); - env.addGroovyClass(root, "p", "X", - "package p;\n" + - "class X {\n" + - " @Anno2\n" + - " X() {\n" + - " }\n" + - "}\n" - ); - IPath path = env.addGroovyClass(root, "p", "Y", - "package p;\n" + - "class Y extends X {\n" + - "}\n" - ); + unit = env.getUnit(env.addGroovyClass(src, "p", "D", "package p\nclass D extends C {\n}\n")); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - - GroovyCompilationUnit unit = env.getUnit(path); - ClassNode x = unit.getModuleNode().getClasses().get(0).getSuperClass(); - List annotations = x.getDeclaredConstructors().get(0).getAnnotations(); - - assertEquals(1, annotations.size()); + ClassNode c = unit.getModuleNode().getClasses().get(0).getSuperClass(); + // TODO: figure out why the PackageBinding for "p" cannot resolve "Anno2" + assertEquals(0, c.getDeclaredConstructors().get(0).getAnnotations().size()); } @Test public void testSingleMemberAnnotation1() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + "@Anno1(Target.class)\n" + - "public class X {\n" + - " public int foo = 5\n" + - " public static void main(String[]argv) {\n" + - " print \"success\"\n" + - " }\n" + + "class C {\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); - assertEquals("Should have one annotation on type X", 1, type.getAnnotations().length); + IType type = unit.getType("C"); + + assertEquals(1, type.getAnnotations().length); assertSingleMemberAnnotation(type, "Target"); } @Test public void testSingleMemberAnnotation2() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + - "public class X {\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + " @Anno1(Target.class)\n" + - " public int foo = 5\n" + - " public static void main(String[]argv) {\n" + - " print \"success\"\n" + - " }\n" + + " public int f\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); - IField field = type.getField("foo"); - assertEquals("Should have one annotation on field foo", 1, field.getAnnotations().length); + IType type = unit.getType("C"); + IField field = type.getField("f"); + + assertEquals(1, field.getAnnotations().length); assertSingleMemberAnnotation(field, "Target"); } @Test public void testSingleMemberAnnotation3() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + - "public class X {\n" + - " public int foo = 5\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + " @Anno1(Target.class)\n" + - " public static void m() {\n" + - " print \"success\"\n" + + " void m() {\n" + " }\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); + IType type = unit.getType("C"); IMethod method = type.getMethod("m", new String[0]); - assertEquals("Should have one annotation on field m", 1, method.getAnnotations().length); + + assertEquals(1, method.getAnnotations().length); assertSingleMemberAnnotation(method, "Target"); } @Test public void testSingleMemberAnnotation4() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + "@Anno1(p.Target.class)\n" + - "public class X {\n" + - " public int foo = 5\n" + - " public static void main(String[]argv) {\n" + - " print \"success\"\n" + - " }\n" + + "class C {\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); - assertEquals("Should have one annotation on type X", 1, type.getAnnotations().length); + IType type = unit.getType("C"); + + assertEquals(1, type.getAnnotations().length); assertSingleMemberAnnotation(type, "p.Target"); } @Test public void testSingleMemberAnnotation5() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + - "public class X {\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + " @Anno1(p.Target.class)\n" + - " public int foo = 5\n" + - " public static void main(String[]argv) {\n" + - " print \"success\"\n" + - " }\n" + + " public int f\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); - IField field = type.getField("foo"); - assertEquals("Should have one annotation on field foo", 1, field.getAnnotations().length); + IType type = unit.getType("C"); + IField field = type.getField("f"); + + assertEquals(1, field.getAnnotations().length); assertSingleMemberAnnotation(field, "p.Target"); } @Test public void testSingleMemberAnnotation6() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + - "public class X {\n" + - " public int foo = 5\n" + + IPath src = createAnnotationGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + " @Anno1(p.Target.class)\n" + - " public static void m() {\n" + - " print \"success\"\n" + + " void m() {\n" + " }\n" + "}\n" - ); + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - IType type = unit.getType("X"); + IType type = unit.getType("C"); IMethod method = type.getMethod("m", new String[0]); - assertEquals("Should have one annotation on field m", 1, method.getAnnotations().length); + + assertEquals(1, method.getAnnotations().length); assertSingleMemberAnnotation(method, "p.Target"); } @Test public void testAnonymousInner1() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + + IPath src = createEmptyGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "X", + "package p\n" + "def foo = new Runnable() {\n" + " void run() {}\n" + - "}" - ); + "}\n" + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - unit.becomeWorkingCopy(new NullProgressMonitor()); + unit.becomeWorkingCopy(null); try { IType type = unit.getType("X"); IMethod method = type.getMethod("run", new String[0]); @@ -589,22 +510,20 @@ public void testAnonymousInner1() throws Exception { @Test public void testAnonymousInner2() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + + IPath src = createEmptyGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "X", + "package p\n" + "def foo = new Runnable() {\n" + " void run() {}\n" + "}\n" + "foo = new Runnable() {\n" + " void run() {}\n" + " void other() {}\n" + - "}" - ); + "}\n" + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - unit.becomeWorkingCopy(new NullProgressMonitor()); + unit.becomeWorkingCopy(null); try { IType type = unit.getType("X"); IMethod method = type.getMethod("run", new String[0]); @@ -628,22 +547,20 @@ public void testAnonymousInner2() throws Exception { @Test public void testAnonymousInner3() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + + IPath src = createEmptyGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "X", + "package p\n" + "class Foo {\n" + " def run() {\n" + " def foo = new Runnable() {\n" + " void run() {}\n" + " }\n" + " }\n" + - "}" - ); + "}\n" + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - unit.becomeWorkingCopy(new NullProgressMonitor()); + unit.becomeWorkingCopy(null); try { IType type = unit.getType("Foo"); IMethod method = type.getMethod("run", new String[0]); @@ -661,9 +578,9 @@ public void testAnonymousInner3() throws Exception { @Test public void testAnonymousInner4() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + + IPath src = createEmptyGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "X", + "package p\n" + "class Foo {\n" + " def run() {\n" + " def foo = new Runnable() {\n" + @@ -674,13 +591,11 @@ public void testAnonymousInner4() throws Exception { " void other() {}\n" + " }\n" + " }\n" + - "}" - ); + "}\n" + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - unit.becomeWorkingCopy(new NullProgressMonitor()); + unit.becomeWorkingCopy(null); try { IType type = unit.getType("Foo"); IMethod method = type.getMethod("run", new String[0]); @@ -704,19 +619,18 @@ public void testAnonymousInner4() throws Exception { @Test public void testAnonymousInner5() throws Exception { - IPath path = env.addGroovyClass(createAnnotationGroovyProject(), "p", "X", - "package p;\n" + + IPath src = createEmptyGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "X", + "package p\n" + "class Foo {\n" + " def foo = new Runnable() {\n" + " void run() {}\n" + " }\n" + - "}" - ); + "}\n" + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - unit.becomeWorkingCopy(new NullProgressMonitor()); + unit.becomeWorkingCopy(null); try { IType type = unit.getType("Foo"); IField field = type.getField("foo"); @@ -729,22 +643,20 @@ public void testAnonymousInner5() throws Exception { } } - @Test // ensures classes in a script are not treated as anon inners + @Test // ensures classes in a script are not treated as anon. inner types public void testAnonymousInner6() throws Exception { - IPath root = createAnnotationGroovyProject(); - IPath path = env.addGroovyClass(root, "p", "X", - "package p;\n" + + IPath src = createEmptyGroovyProject(); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "X", + "package p\n" + "class Other {}\n" + "def foo = new Runnable() {\n" + " void run() {}\n" + "}\n" + - "class Other2 {}" - ); + "class Other2 {}\n" + )); incrementalBuild(); - env.waitForAutoBuild(); expectingNoProblems(); - GroovyCompilationUnit unit = env.getUnit(path); - unit.becomeWorkingCopy(new NullProgressMonitor()); + unit.becomeWorkingCopy(null); try { unit.getType("Other").exists(); unit.getType("Other2").exists(); @@ -764,12 +676,11 @@ public void testAnonymousInner6() throws Exception { @Test public void testVariadicMethod1() throws Exception { - IPath path = env.addGroovyClass(createEmptyGroovyProject(), "X", + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(createEmptyGroovyProject(), "X", "class X {\n" + - " private void fn(String one, int... two) {}\n" + - "}"); - - GroovyCompilationUnit unit = env.getUnit(path); + " private void proc(String one, int... two) {}\n" + + "}\n" + )); Set problems = reconcile(unit); assertTrue(problems.isEmpty()); } diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyPartialModelTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyPartialModelTests.java index 1105ca3d23..698395e6a9 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyPartialModelTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyPartialModelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 the original author or authors. + * Copyright 2009-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,11 +33,7 @@ import org.codehaus.groovy.ast.stmt.BlockStatement; import org.codehaus.groovy.ast.stmt.Statement; import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.JavaCore; +import org.eclipse.core.runtime.IPath; import org.junit.Ignore; import org.junit.Test; @@ -93,13 +89,15 @@ public void testFieldInitializerIsAvailable4() throws Exception { @Test public void testClosureReturner() throws Exception { - IProject project = createSimpleGroovyProject().getProject(); + IPath src = createEmptyGroovyProject(); //@formatter:off - env.addGroovyClass(project.getFullPath().append("src"), "p1", "Hello2", - "class C { def aaa = { 123 } }"); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(src, "p", "C", + "package p\n" + + "class C {\n" + + " def aaa = { 123 }\n" + + "}\n" + )); //@formatter:on - IFile javaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("Project/src/p1/Hello2.groovy")); - GroovyCompilationUnit unit = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(javaFile); ClassNode inClass = unit.getModuleNode().getClasses().get(0); FieldNode field = inClass.getField("aaa"); Expression initialExpression = field.getInitialExpression(); @@ -112,8 +110,7 @@ public void testClosureReturner() throws Exception { //-------------------------------------------------------------------------- private Expression findFieldInitializer(String contents, Class expressionClass) throws Exception { - IProject project = createSimpleGroovyProject().getProject(); - GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(project.getFullPath().append("src"), "p", "C", contents)); + GroovyCompilationUnit unit = env.getUnit(env.addGroovyClass(createEmptyGroovyProject(), "p", "C", contents)); ClassNode clazz = unit.getModuleNode().getClasses().get(0); FieldNode field = clazz.getField("aField"); diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyTypeRootTestSuite.java b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyTypeRootTestSuite.java index d8a4afb9ab..28c47e83b9 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyTypeRootTestSuite.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyTypeRootTestSuite.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 the original author or authors. + * Copyright 2009-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ public abstract class GroovyTypeRootTestSuite extends BuilderTestSuite { - protected final IFile createProject(boolean isGroovy) throws Exception { + private IFile createProject(boolean isGroovy) throws Exception { IPath projectPath = env.addProject("Project"); if (!isGroovy) env.removeGroovyNature("Project"); @@ -31,8 +31,8 @@ protected final IFile createProject(boolean isGroovy) throws Exception { if (isGroovy) { env.addGroovyJars(projectPath); //@formatter:off - path = env.addGroovyClass(path, "p1", "Hello", - "package p1;\n" + + path = env.addGroovyClass(path, "p", "Hello", + "package p\n" + "public class Hello {\n" + " static def main(String[] args) {\n" + " print 'Hello world'\n" + @@ -42,6 +42,7 @@ protected final IFile createProject(boolean isGroovy) throws Exception { } fullBuild(projectPath); + return ResourcesPlugin.getWorkspace().getRoot().getFile(path); } @@ -62,34 +63,34 @@ protected final IPath createEmptyGroovyProject() throws Exception { } protected final IPath createAnnotationGroovyProject() throws Exception { - IPath root = createEmptyGroovyProject(); + IPath src = createEmptyGroovyProject(); //@formatter:off - env.addClass(root, "p", "Anno1.java", + env.addClass(src, "p", "Anno1.java", "package p;\n" + "import java.lang.annotation.*;\n" + "@Retention(RetentionPolicy.RUNTIME)\n" + "@interface Anno1 { Class value(); }\n"); - env.addClass(root, "p", "Anno2.java", + env.addClass(src, "p", "Anno2.java", "package p;\n" + "import java.lang.annotation.*;\n" + "@Retention(RetentionPolicy.RUNTIME)\n" + "@interface Anno2 { }\n"); - env.addClass(root, "p", "Anno3.java", + env.addClass(src, "p", "Anno3.java", "package p;\n" + "import java.lang.annotation.*;\n" + "@Retention(RetentionPolicy.RUNTIME)\n" + "@interface Anno3 { String value(); }\n"); - env.addClass(root, "p", "Anno4.java", + env.addClass(src, "p", "Anno4.java", "package p;\n" + "import java.lang.annotation.*;\n" + "@Retention(RetentionPolicy.RUNTIME)\n" + "@interface Anno4 { Class value1(); }\n"); - env.addClass(root, "p", "Target.java", + env.addClass(src, "p", "Target.java", "package p;\n" + "class Target { }"); //@formatter:on - return root; + return src; } } diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/MoveRenameCopyTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/MoveRenameCopyTests.java index f8fe8e11e1..7bffc08a87 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/MoveRenameCopyTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/MoveRenameCopyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 the original author or authors. + * Copyright 2009-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,8 @@ import static org.junit.Assert.assertTrue; import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.groovy.tests.builder.BuilderTestSuite; import org.junit.Test; @@ -132,7 +129,6 @@ private GroovyCompilationUnit createSimpleGroovyProject(String pack, String cont IPath root = env.getPackageFragmentRootPath(projectPath, "src"); IPath path = env.addGroovyClass(root, "Groovy", contents); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); - return (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(file); + return env.getUnit(path); } } 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 6acad11581..4df4dca12b 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 @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 the original author or authors. + * Copyright 2009-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -2379,7 +2379,7 @@ private int getModifiers(FieldNode node) { } private int getModifiers(MethodNode node) { - int modifiers = node.getModifiers() & ~(Flags.AccSynthetic | Flags.AccTransient); + int modifiers = node.getModifiers() & ~(Flags.AccSynthetic | Flags.AccTransient); // GRECLIPSE-370, GROOVY-10140 if (node.isDefault()) { modifiers |= Flags.AccDefaultMethod; } diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTAnnotationNode.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTAnnotationNode.java index b5b77dae80..4073531a0a 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTAnnotationNode.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTAnnotationNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2019 the original author or authors. + * Copyright 2009-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -141,7 +141,7 @@ private Expression createExpressionFor(TypeBinding b, Object value) { } if (b.isAnnotationType()) { - return new AnnotationConstantExpression(new JDTAnnotationNode((AnnotationBinding) value, resolver)); + return new AnnotationConstantExpression(resolver.convertToAnnotationNode((AnnotationBinding) value)); } if (b.isEnum()) { diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTClassNode.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTClassNode.java index 22cfe93efb..5abdcc73d0 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTClassNode.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTClassNode.java @@ -407,7 +407,7 @@ private ConstructorNode constructorBindingToConstructorNode(final MethodBinding ConstructorNode ctorNode = new ConstructorNode(methodBinding.modifiers, parameters, exceptions, null); for (AnnotationBinding annotationBinding : methodBinding.getAnnotations()) { - ctorNode.addAnnotation(new JDTAnnotationNode(annotationBinding, resolver)); + ctorNode.addAnnotation(resolver.convertToAnnotationNode(annotationBinding)); } ctorNode.setGenericsTypes(new JDTClassNodeBuilder(resolver).configureTypeVariables(methodBinding.typeVariables())); ctorNode.putNodeMetaData("JdtBinding", methodBinding); @@ -495,7 +495,7 @@ private Parameter[] makeParameters(final TypeBinding[] parameterTypes, final cha parameters[i] = makeParameter(parameterTypes[i], parameterName); if (parameterAnnotations != null && parameterAnnotations.length > i) { for (AnnotationBinding annotationBinding : parameterAnnotations[i]) { - parameters[i].addAnnotation(new JDTAnnotationNode(annotationBinding, resolver)); + parameters[i].addAnnotation(resolver.convertToAnnotationNode(annotationBinding)); } } } @@ -515,7 +515,7 @@ public List getAnnotations() { long tagBits = ((SourceTypeBinding) jdtBinding).getAnnotationTagBits(); } for (AnnotationBinding annotationBinding : jdtBinding.getAnnotations()) { - addAnnotation(new JDTAnnotationNode(annotationBinding, resolver)); + addAnnotation(resolver.convertToAnnotationNode(annotationBinding)); } bits |= ANNOTATIONS_INITIALIZED; } diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTFieldNode.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTFieldNode.java index f4eed4ec0a..91aa4b36f1 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTFieldNode.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTFieldNode.java @@ -1,11 +1,11 @@ /* - * Copyright 2009-2018 the original author or authors. + * Copyright 2009-2021 the original author or authors. * * 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 + * https://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, @@ -58,7 +58,7 @@ private void ensureAnnotationsInitialized() { // if the declaring entity for the member is not a SourceTypeBinding // then the annotations will have already been discarded/lost for (AnnotationBinding annotationBinding : fieldBinding.getAnnotations()) { - super.addAnnotation(new JDTAnnotationNode(annotationBinding, resolver)); + super.addAnnotation(resolver.convertToAnnotationNode(annotationBinding)); } } bits |= ANNOTATIONS_INITIALIZED; diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTMethodNode.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTMethodNode.java index 21261d81ce..b08342bf21 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTMethodNode.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTMethodNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2019 the original author or authors. + * Copyright 2009-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,7 @@ private void ensureAnnotationsInitialized() { // if the declaring entity for the member is not a SourceTypeBinding // then the annotations will have already been discarded/lost for (AnnotationBinding annotationBinding : methodBinding.getAnnotations()) { - super.addAnnotation(new JDTAnnotationNode(annotationBinding, resolver)); + super.addAnnotation(resolver.convertToAnnotationNode(annotationBinding)); } bits |= ANNOTATIONS_INITIALIZED; } diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTResolver.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTResolver.java index 9550905d96..68d5f68745 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTResolver.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTResolver.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; +import org.codehaus.groovy.ast.AnnotationNode; import org.codehaus.groovy.ast.ClassHelper; import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.ast.ImportNode; @@ -39,6 +40,7 @@ import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.env.AccessRestriction; +import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; @@ -460,8 +462,20 @@ protected boolean resolveToInner(ClassNode type) { return false; } + //-------------------------------------------------------------------------- + + /** + * Converts a JDT {@code AnnotationBinding} to a Groovy {@code AnnotationNode}. + */ + protected AnnotationNode convertToAnnotationNode(AnnotationBinding jdtBinding) { + if (jdtBinding == null || jdtBinding.getAnnotationType().problemId() != 0) { + return null; + } + return new JDTAnnotationNode(jdtBinding, this); + } + /** - * Converts a JDT TypeBinding to a Groovy ClassNode. + * Converts a JDT {@code TypeBinding} to a Groovy {@code ClassNode}. */ protected ClassNode convertToClassNode(TypeBinding jdtBinding) { ClassNode existingNode = checkForExisting(jdtBinding); diff --git a/extras/groovy-eclipse-batch-builder/build.properties b/extras/groovy-eclipse-batch-builder/build.properties index 3d02ea11ef..c88123b470 100644 --- a/extras/groovy-eclipse-batch-builder/build.properties +++ b/extras/groovy-eclipse-batch-builder/build.properties @@ -1,6 +1,6 @@ # version numbers -version2.5=2.5.14-02 -version3.0=3.0.8-01 +version2.5=2.5.14-03 +version3.0=3.0.8-02 version4.0=4.0.0-01 # uncomment to do a particular build -- only one should be uncommented at a time