--- old/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java 2013-06-27 22:57:56.000000000 -0700 +++ new/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java 2013-06-27 22:57:56.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; @@ -762,12 +759,30 @@ } @Override - public Set scan(Element e, Set p) { + 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-06-27 22:57:56.000000000 -0700 +++ new/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java 2013-06-27 22:57:56.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/AbstractProcessor.java 2013-06-27 22:57:57.000000000 -0700 +++ new/src/share/classes/javax/annotation/processing/AbstractProcessor.java 2013-06-27 22:57:57.000000000 -0700 @@ -38,7 +38,7 @@ * superclass for most concrete annotation processors. This class * examines annotation values to compute the {@linkplain * #getSupportedOptions options}, {@linkplain - * #getSupportedAnnotationTypes annotations}, and {@linkplain + * #getSupportedAnnotationTypes annotation types}, and {@linkplain * #getSupportedSourceVersion source version} supported by its * subtypes. * --- old/src/share/classes/javax/annotation/processing/Processor.java 2013-06-27 22:57:57.000000000 -0700 +++ new/src/share/classes/javax/annotation/processing/Processor.java 2013-06-27 22:57:57.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,8 @@ package javax.annotation.processing; import java.util.Set; +import javax.lang.model.util.Elements; +import javax.lang.model.AnnotatedConstruct; import javax.lang.model.element.*; import javax.lang.model.SourceVersion; @@ -88,11 +90,12 @@ * configuration mechanisms, such as command line options; for * details, refer to the particular tool's documentation. Which * processors the tool asks to {@linkplain #process run} is a function - * of what annotations are present on the {@linkplain + * of the types of the annotations {@linkplain AnnotatedConstruct present} + * on the {@linkplain * RoundEnvironment#getRootElements root elements}, what {@linkplain * #getSupportedAnnotationTypes annotation types a processor * processes}, and whether or not a processor {@linkplain #process - * claims the annotations it processes}. A processor will be asked to + * claims the annotation types it processes}. A processor will be asked to * process a subset of the annotation types it supports, possibly an * empty set. * @@ -106,6 +109,32 @@ * processing {@code "*"} can claim the (empty) set of annotation * types. * + *

An annotation type is considered present if there is at least + * one annotation of that type present on an element enclosed within + * the root elements of a round. Annotations on {@linkplain + * ElementType#TYPE_USE type uses}, as opposed to annotations on + * elements, are not considered as part of the + * computation. For this purpose, a type parameter is considered to be + * enclosed by its {@linkplain TypeParameter#getGenericElement generic + * element}. + * + *

An annotation is present if it meets the definition of being + * present given in {@link AnnotatedConstruct}. In brief, an + * annotation is considered present for the purposes of discovery if + * it is directly present or present via inheritance. An annotation is + * not considered present by virtue of being wrapped by a + * container annotation. Operationally, this is equivalent to an + * annotation being present on an element if and only if it would be + * included in the results of {@link + * Elements#getAllAnnotationMirrors()} called on that element. Since + * annotations inside container annotations are not considered + * present, to properly process {@linkplain + * java.lang.annotation.Repeatable repeatable annotation types}, + * processors are advised to include both the repeatable annotation + * type and its containing annotation type in the set of {@linkplain + * #getSupportedAnnotationTypes() supported annotation types} of a + * processor. + * *

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 @@ -257,10 +286,10 @@ /** * Processes a set of annotation types on type elements * originating from the prior round and returns whether or not - * these annotations are claimed by this processor. If {@code - * true} is returned, the annotations are claimed and subsequent + * these annotation types are claimed by this processor. If {@code + * true} is returned, the annotation types are claimed and subsequent * processors will not be asked to process them; if {@code false} - * is returned, the annotations are unclaimed and subsequent + * is returned, the annotation types are unclaimed and subsequent * processors may be asked to process them. A processor may * always return the same boolean value or may vary the result * based on chosen criteria. @@ -271,7 +300,7 @@ * * @param annotations the annotation types requested to be processed * @param roundEnv environment for information about the current and prior round - * @return whether or not the set of annotations are claimed by this processor + * @return whether or not the set of annotation types are claimed by this processor */ boolean process(Set annotations, RoundEnvironment roundEnv); --- old/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java 2013-06-27 22:57:57.000000000 -0700 +++ new/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java 2013-06-27 22:57:57.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-06-26 11:54:08.305759625 -0700 +++ new/test/tools/javac/processing/environment/round/TpAnno.java 2013-06-27 22:57:58.000000000 -0700 @@ -0,0 +1,29 @@ +/* + * 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 java.lang.annotation.*; +import static java.lang.annotation.RetentionPolicy.*; + +@Retention(RUNTIME) +@Target(ElementType.TYPE_PARAMETER) +public @interface TpAnno {} --- /dev/null 2013-06-26 11:54:08.305759625 -0700 +++ new/test/tools/javac/processing/environment/round/TypeParameterAnnotations.java 2013-06-27 22:57:58.000000000 -0700 @@ -0,0 +1,37 @@ +/* + * 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;} +}