diff --git a/JCL/javax23api/src/javax/lang/model/util/Types.java b/JCL/javax23api/src/javax/lang/model/util/Types.java index c62c3b0b8f0..087a896fd1d 100644 --- a/JCL/javax23api/src/javax/lang/model/util/Types.java +++ b/JCL/javax23api/src/javax/lang/model/util/Types.java @@ -48,4 +48,7 @@ DeclaredType getDeclaredType(DeclaredType containing, TypeElement typeElem, TypeMirror... typeArgs); TypeMirror asMemberOf(DeclaredType containing, Element element); + default T stripAnnotations(T t) { + throw new UnsupportedOperationException(); + } } diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar index 4270e97d59a..c3b8570be26 100644 Binary files a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar and b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar differ diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/javax23api.jar b/org.eclipse.jdt.compiler.apt.tests/lib/javax23api.jar index 092d51a765d..f7ca9689573 100644 Binary files a/org.eclipse.jdt.compiler.apt.tests/lib/javax23api.jar and b/org.eclipse.jdt.compiler.apt.tests/lib/javax23api.jar differ diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java23ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java23ElementProcessor.java index b1f55927621..062969faba7 100644 --- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java23ElementProcessor.java +++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java23ElementProcessor.java @@ -27,9 +27,14 @@ import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Elements.DocCommentKind; import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor; @@ -206,6 +211,53 @@ public void testMarkdownContent3() throws IOException { + "@param p parameter", docComment); } + public void testStripAnnotations() { + String typeName = "my.mod.Main3"; + String annotationName = "my.annot.MyAnnotation"; + TypeElement typeElement = _elementUtils.getTypeElement(typeName); + List interfaces = typeElement.getInterfaces(); + assertEquals("Wrong no of super interfaces", 1, interfaces.size()); + TypeMirror superclass = interfaces.get(0); + List annotations = superclass.getAnnotationMirrors(); + assertEquals("Incorrect no of annotations", 1, annotations.size()); + TypeMirror withoutAnnotations = _typeUtils.stripAnnotations(superclass); + assertTrue("Type should not have any annotations", withoutAnnotations.getAnnotationMirrors().isEmpty()); + assertTrue("Should be of the same type", _typeUtils.isSameType(superclass, withoutAnnotations)); + List methods = ElementFilter.methodsIn(typeElement.getEnclosedElements()); + for (ExecutableElement method : methods) { + if (method.getSimpleName().toString().equals("run")) { + continue; + } + TypeMirror typeMirror = method.getReturnType(); + + TypeMirror expAnnotation = _elementUtils.getTypeElement(annotationName).asType(); + annotations = typeMirror.getAnnotationMirrors(); + assertEquals("Incorrect no of annotations", 1, annotations.size()); + DeclaredType annotationType = typeMirror.getAnnotationMirrors().get(0).getAnnotationType(); + assertTrue("Incorrecton annotation type", _typeUtils.isSameType(expAnnotation, annotationType)); + + // after stripAnnotations() TypeMirror should not have any annotations. + withoutAnnotations = _typeUtils.stripAnnotations(typeMirror); + assertTrue("Type should not have any annotations", withoutAnnotations.getAnnotationMirrors().isEmpty()); + + TypeMirror typeMirror1 = null; + if (typeMirror.getKind() != TypeKind.WILDCARD) { + assertTrue("Should be of the same type", _typeUtils.isSameType(typeMirror, withoutAnnotations)); + } else { + typeMirror1 = _typeUtils.getWildcardType(typeMirror, null); + annotations = typeMirror.getAnnotationMirrors(); + assertTrue("Type should not have any annotations", typeMirror1.getAnnotationMirrors().isEmpty()); + } + + typeMirror1 = _typeUtils.erasure(typeMirror); + annotations = typeMirror.getAnnotationMirrors(); + assertEquals("Incorrect no of annotations", 1, annotations.size()); + + typeMirror1 = _typeUtils.getArrayType(typeMirror); + annotations = typeMirror.getAnnotationMirrors(); + assertEquals("Incorrect no of annotations", 1, annotations.size()); + } + } @Override public void reportError(String msg) { throw new AssertionFailedError(msg); @@ -253,6 +305,11 @@ public void assertNotNull(String msg, Object obj) { reportError(msg); } } + public void assertTrue(String msg, boolean result) { + if (!result) { + reportError(msg); + } + } private static class AssertionFailedError extends Error { private static final long serialVersionUID = 1L; diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules23/module.main/my/annot/MyAnnotation.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules23/module.main/my/annot/MyAnnotation.java new file mode 100644 index 00000000000..cc1a9b9435a --- /dev/null +++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules23/module.main/my/annot/MyAnnotation.java @@ -0,0 +1,7 @@ +package my.annot; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +@Target(ElementType.TYPE_USE) +public @interface MyAnnotation { + String value() default ""; +} \ No newline at end of file diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules23/module.main/my/mod/Main3.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules23/module.main/my/mod/Main3.java new file mode 100644 index 00000000000..1172cb1fa7d --- /dev/null +++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules23/module.main/my/mod/Main3.java @@ -0,0 +1,41 @@ +package my.mod; + +import my.annot.*; + +public class Main3 implements @MyAnnotation Runnable { + + public void run() { + } + + public static @MyAnnotation("1") int method1() { + return 0; + } + + public static @MyAnnotation("2") Integer method2() { + return null; + } + + public static @MyAnnotation("3") String method3() { + return null; + } + + public static String @MyAnnotation("4") [] method4() { + return null; + } + + public static java.util.@MyAnnotation("5") Set<@MyAnnotation("6") String> method5() { + return null; + } + + public static <@MyAnnotation("7") T extends @MyAnnotation("8") String> @MyAnnotation("9") T method6() { + return null; + } + + public static java.util.@MyAnnotation("10") Set<@MyAnnotation("11") ? extends @MyAnnotation("12") Number> method7() { + return null; + } + + public static <@MyAnnotation("13") S extends Number & Runnable> @MyAnnotation("14") S method8() { + return null; + } +} \ No newline at end of file diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java23ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java23ElementsTests.java index f8551d8647a..b4d5f1a5113 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java23ElementsTests.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java23ElementsTests.java @@ -54,6 +54,14 @@ public void testMarkdownContent3Javac() throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); internalTestWithBinary(compiler, MODULE_PROC, "23", "testMarkdownContent3", null, "modules23", false); } + public void testStripAnnotations() throws IOException { + JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); + internalTestWithBinary(compiler, MODULE_PROC, "23", "testStripAnnotations", null, "modules23", false); + } + public void testStripAnnotationsJavac() throws IOException { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + internalTestWithBinary(compiler, MODULE_PROC, "23", "testStripAnnotations", null, "modules23", false); + } @SuppressWarnings({ "rawtypes", "unchecked" }) protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea, boolean processBinariesAgain) throws IOException { diff --git a/org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF index 935a43ecfd9..c5f3056e24d 100644 --- a/org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.compiler.tool.tests -Bundle-Version: 1.4.600.qualifier +Bundle-Version: 1.4.700.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-17 diff --git a/org.eclipse.jdt.compiler.tool.tests/lib/javax23api.jar b/org.eclipse.jdt.compiler.tool.tests/lib/javax23api.jar index 092d51a765d..f7ca9689573 100644 Binary files a/org.eclipse.jdt.compiler.tool.tests/lib/javax23api.jar and b/org.eclipse.jdt.compiler.tool.tests/lib/javax23api.jar differ diff --git a/org.eclipse.jdt.compiler.tool.tests/pom.xml b/org.eclipse.jdt.compiler.tool.tests/pom.xml index 9f094788a42..568fc0527a2 100644 --- a/org.eclipse.jdt.compiler.tool.tests/pom.xml +++ b/org.eclipse.jdt.compiler.tool.tests/pom.xml @@ -1,6 +1,6 @@