diff options
author | Jay Arthanareeswaran | 2021-11-17 14:18:30 +0000 |
---|---|---|
committer | Jay Arthanareeswaran | 2022-01-17 08:57:26 +0000 |
commit | d17fdf41aa6b567af200ea8ae43282715d8d5c6a (patch) | |
tree | 1097c01fe917ac162e10ab2c193ff6e8a96e6a39 | |
parent | d041f3803d811a0e9790d305639e77e557feceab (diff) | |
download | eclipse.jdt.core-d17fdf41aa6b567af200ea8ae43282715d8d5c6a.tar.gz eclipse.jdt.core-d17fdf41aa6b567af200ea8ae43282715d8d5c6a.tar.xz eclipse.jdt.core-d17fdf41aa6b567af200ea8ae43282715d8d5c6a.zip |
Bug 544288 - [1.8][compiler] Annotation with TYPE_USE not properly
handled by TypeUtils (different to javac)
Change-Id: I471bb293b560cbf1b9419e47852a70d8a14d2374
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
Also-By: Stephan Herrmann<stephan.herrmann@berlin.de>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/187828
Tested-by: JDT Bot <jdt-bot@eclipse.org>
7 files changed, 109 insertions, 3 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar Binary files differindex f7a109b23f..7a4e6bde0f 100644 --- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar +++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java index 0f29d4227f..81056d1ec7 100644 --- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java +++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 IBM Corporation. + * Copyright (c) 2013, 2021 IBM Corporation. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -78,7 +78,8 @@ import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor; "org.eclipse.jdt.compiler.apt.tests.annotations.Foo", "org.eclipse.jdt.compiler.apt.tests.annotations.FooContainer", "org.eclipse.jdt.compiler.apt.tests.annotations.IFoo", "org.eclipse.jdt.compiler.apt.tests.annotations.IFooContainer", "org.eclipse.jdt.compiler.apt.tests.annotations.Goo", "org.eclipse.jdt.compiler.apt.tests.annotations.GooNonContainer", - "org.eclipse.jdt.compiler.apt.tests.annotations.FooNonContainer", "targets.filer8.PackageAnnot"}) + "org.eclipse.jdt.compiler.apt.tests.annotations.FooNonContainer", "targets.filer8.PackageAnnot", + "java.lang.Deprecated"}) @SupportedSourceVersion(SourceVersion.RELEASE_8) public class Java8ElementProcessor extends BaseProcessor { @@ -180,6 +181,7 @@ public class Java8ElementProcessor extends BaseProcessor { testBug520540(); testBug526288(); testEnumConstArguments(); + testBug544288(); } public void testLambdaSpecifics() { @@ -1075,6 +1077,20 @@ public class Java8ElementProcessor extends BaseProcessor { assertNotNull("Method should not be null", method); verifyAnnotations(method, new String[]{"@Deprecated()"}); } + public void testBug544288() { + TypeElement type = _elementUtils.getTypeElement("targets.bug544288.TestEntity"); + List<? extends Element> members = _elementUtils.getAllMembers(type); + VariableElement field = null; + for (Element member : members) { + if ("fieldWithTypeUse".equals(member.getSimpleName().toString())) { + field = (VariableElement) member; + } + } + assertNotNull("Should not be null", field); + TypeMirror asType = field.asType(); + Element asElement = _typeUtils.asElement(asType); + verifyAnnotations(asElement, new String[]{"@Deprecated()"}); + } private void createPackageBinary() throws IOException { String path = packageName.replace('.', '/'); ClassLoader loader = getClass().getClassLoader(); diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug544288/TestEmbeddable.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug544288/TestEmbeddable.java new file mode 100644 index 0000000000..02ad77b57e --- /dev/null +++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug544288/TestEmbeddable.java @@ -0,0 +1,7 @@ +package targets.bug544288; + +@Deprecated +public class TestEmbeddable { + + String value; +} diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug544288/TestEntity.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug544288/TestEntity.java new file mode 100644 index 0000000000..969d3ce687 --- /dev/null +++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug544288/TestEntity.java @@ -0,0 +1,67 @@ +package targets.bug544288; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.LOCAL_VARIABLE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.MODULE; +import static java.lang.annotation.ElementType.PACKAGE; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.ElementType.TYPE_PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; + +import java.lang.annotation.Target; + + +@Deprecated +public class TestEntity { + + @ATypeUse + TestEmbeddable fieldWithTypeUse; + + @Target({ FIELD, TYPE }) + public @interface AType { + } + + @Target({ FIELD }) + public @interface AField { + } + + @Target({ FIELD, METHOD }) + public @interface AMethod { + } + + @Target({ FIELD, PARAMETER }) + public @interface AParameter { + } + + @Target({ FIELD, CONSTRUCTOR }) + public @interface AConstructor { + } + + @Target({ FIELD, LOCAL_VARIABLE }) + public @interface ALocalVariable { + } + + @Target({ FIELD, ANNOTATION_TYPE }) + public @interface AAnnotationType { + } + + @Target({ FIELD, PACKAGE }) + public @interface APackage { + } + + @Target({ FIELD, TYPE_PARAMETER }) + public @interface ATypeParameter { + } + + @Target({ FIELD, TYPE_USE }) + public @interface ATypeUse { + } + + @Target({ FIELD, MODULE }) + public @interface AModule { + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java index 56a4184822..b9d3dbb8a6 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java @@ -294,6 +294,10 @@ public class BatchTestUtils { System.err.println("Compilation failed: " + errorOutput); junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false); } + // Check the APT result for the source round already + if (!"succeeded".equals(System.getProperty(processor))) { + return; + } List<String> classes = new ArrayList<>(); try { System.clearProperty(processor); diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java index 3938944857..269bdf0743 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java @@ -402,6 +402,18 @@ public class Java8ElementsTests extends TestCase { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); internalTestWithBinary(compiler, JAVA8_ANNOTATION_PROC, "testMethodAnnotation", null, "model9", "9"); } + public void testBug544288Javac() throws Exception { + if (!canRunJava9()) + return; + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + internalTestWithBinary(compiler, JAVA8_ANNOTATION_PROC, "testBug544288", null, "bug544288", "9"); + } + public void testBug544288() throws Exception { + if (!canRunJava9()) + return; + JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); + internalTestWithBinary(compiler, JAVA8_ANNOTATION_PROC, "testBug544288", null, "bug544288", "9"); + } private void internalTest(JavaCompiler compiler, String processor, String testMethod) throws IOException { internalTest(compiler, processor, testMethod, null); } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java index cf06571b88..e00f629e11 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java @@ -1064,7 +1064,7 @@ public final int getAccessFlags() { */ @Override public AnnotationBinding[] getAnnotations() { - return retrieveAnnotations(this); + return retrieveAnnotations(prototype()); } /** |