--- old/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java 2013-03-26 16:16:36.000000000 -0700 +++ new/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java 2013-03-26 16:16:36.000000000 -0700 @@ -36,10 +36,7 @@ import javax.annotation.processing.*; import javax.lang.model.SourceVersion; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; +import javax.lang.model.element.*; import javax.lang.model.util.*; import javax.tools.DiagnosticListener; import javax.tools.JavaFileManager; @@ -759,13 +756,31 @@ return p; } - @Override - public Set scan(Element e, Set p) { + @Override + public Set visitType(TypeElement e, Set p) { + // Type parameters are not considered to be enclosed by a type + scan(e.getTypeParameters(), p); + return scan(e.getEnclosedElements(), p); + } + + @Override + public Set visitExecutable(ExecutableElement e, Set p) { + // Type parameters are not considered to be enclosed by an executable + scan(e.getTypeParameters(), p); + return scan(e.getEnclosedElements(), p); + } + + void addAnnotations(Element e, Set p) { for (AnnotationMirror annotationMirror : elements.getAllAnnotationMirrors(e) ) { Element e2 = annotationMirror.getAnnotationType().asElement(); p.add((TypeElement) e2); } + } + + @Override + public Set scan(Element e, Set p) { + addAnnotations(e, p); return super.scan(e, p); } } --- old/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java 2013-03-26 16:16:37.000000000 -0700 +++ new/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java 2013-03-26 16:16:37.000000000 -0700 @@ -147,6 +147,20 @@ } @Override + public Set visitType(TypeElement e, DeclaredType p) { + // Type parameters are not considered to be enclosed by a type + scan(e.getTypeParameters(), p) + return scan(e.getEnclosedElements(), p); + } + + @Override + public Set visitExecutable(ExecutableElement e, DeclaredType p) { + // Type parameters are not considered to be enclosed by an executable + scan(e.getTypeParameters(), p) + return scan(e.getEnclosedElements(), p); + } + + @Override public Set scan(Element e, DeclaredType p) { java.util.List annotationMirrors = processingEnv.getElementUtils().getAllAnnotationMirrors(e); @@ -157,7 +171,6 @@ e.accept(this, p); return annotatedElements; } - } /** --- old/src/share/classes/javax/annotation/processing/Processor.java 2013-03-26 16:16:37.000000000 -0700 +++ new/src/share/classes/javax/annotation/processing/Processor.java 2013-03-26 16:16:37.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package javax.annotation.processing; import java.util.Set; +import javax.lang.model.util.Elements; import javax.lang.model.element.*; import javax.lang.model.SourceVersion; @@ -106,6 +107,23 @@ * processing {@code "*"} can claim the (empty) set of annotation * types. * + *

An annotation type is considered present if there is an + * annotation of that type on a declaration enclosed within the root + * elements of a round. For this purpose, a type parameter is + * considered to be enclosed by its {@linkplain + * TypeParameter#getGenericElement generic element}. Annotations on + * {@linkplain ElementType#TYPE_USE type uses} are not + * considered as part of the computation. To be present, an annotation + * must be returnable by {@link Elements#getAllAnnotationMirrors()}, + * that is, the annotation must be present on the declaration of the + * element or present via inheritance. An annotation is not + * considered present by virtue of being wrapped by a container + * annotation. Therefore, to properly process {@linkplain + * java.lang.annotation.Repeatable repeatable annotation types}, + * processors are advised to include both the annotation and its + * container in the set of {@linkplain #getSupportedAnnotationTypes() + * supported annotation types}. + * *

Note that if a processor supports {@code "*"} and returns {@code * true}, all annotations are claimed. Therefore, a universal * processor being used to, for example, implement additional validity --- old/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java 2013-03-26 16:16:38.000000000 -0700 +++ new/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java 2013-03-26 16:16:37.000000000 -0700 @@ -30,11 +30,13 @@ * @build JavacTestingAbstractProcessor * @compile TestElementsAnnotatedWith.java * @compile InheritedAnnotation.java + * @compile TpAnno.java * @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java * @compile -processor TestElementsAnnotatedWith -proc:only BuriedAnnotations.java * @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java * @compile -processor TestElementsAnnotatedWith -proc:only C2.java * @compile -processor TestElementsAnnotatedWith -proc:only Foo.java + * @compile -processor TestElementsAnnotatedWith -proc:only TypeParameterAnnotations.java * @compile Foo.java * @compile/process -processor TestElementsAnnotatedWith -proc:only Foo */ --- /dev/null 2013-03-26 14:25:41.552411639 -0700 +++ new/test/tools/javac/processing/environment/round/TpAnno.java 2013-03-26 16:16:38.000000000 -0700 @@ -0,0 +1,30 @@ +import java.lang.annotation.*; +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import static java.lang.annotation.RetentionPolicy.*; + +@Retention(RUNTIME) +@Target(ElementType.TYPE_PARAMETER) +public @interface TpAnno { +} \ No newline at end of file --- /dev/null 2013-03-26 14:25:41.552411639 -0700 +++ new/test/tools/javac/processing/environment/round/TypeParameterAnnotations.java 2013-03-26 16:16:38.000000000 -0700 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Class to hold annotations for ElementsAnnotatedWithTest. + */ + +@AnnotatedElementInfo(annotationName="TpAnno", + expectedSize=4, + names={"T", "A", "B", "C"}) +public class TypeParameterAnnotations<@TpAnno T> { + private <@TpAnno A> TypeParameterAnnotations(A a) {;} + + public <@TpAnno B> void foo(B b) {return;} + + public static <@TpAnno C> void bar(C b) {return;} +} +