JDK-6425592 : JSR 269: please provide RoundEnvironment.getElementsAnnotatedWith(Class)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.annotation.processing
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-05-14
  • Updated: 2017-05-16
  • Resolved: 2006-07-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b91Fixed
Description
javax.annotation.processing.RoundEnvironment.getElementsAnnotatedWith(TypeElement)
is a bit hard to use.  This would be simpler:

roundEnv.getElementsAnnotatedWith(MyAnnotation.class);

Comments
SUGGESTED FIX src/share/classes/javax/annotation/processing>sccs sccsdiff -r1.2 -r1.3 RoundEnvironment.java ------- RoundEnvironment.java ------- 12a13 > import java.lang.annotation.Annotation; 68a70,83 > > /** > * Returns the elements annotated with the given annotation type. > * Only type elements <i>included</i> in this round of annotation > * processing, or declarations of members, parameters, or type > * parameters declared within those, are returned. Included type > * elements are {@linkplain #getSpecifiedTypeElements specified > * types} and any types nested within them. > * > * @param a annotation type being requested > * @return the elements annotated with the given annotation type, > * or an empty set if there are none > */ > Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a); src/share/classes/com/sun/tools/javac/processing>sccs sccsdiff -r1.3 -r1.4 JavacRoundEnvironment.java ------- JavacRoundEnvironment.java ------- 12a13 > import java.lang.annotation.Annotation; 17d17 < import javax.annotation.processing.*; 37a38,39 > private ProcessingEnvironment processingEnv; > 42c44,45 < Set<? extends TypeElement> specifiedTypeElements) { --- > Set<? extends TypeElement> specifiedTypeElements, > ProcessingEnvironment processingEnv) { 46a50 > this.processingEnv = processingEnv; 136a141,156 > > /** > * {@inheritdoc} > */ > public Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a) { > String name = a.getCanonicalName(); > if (name == null) > return Collections.emptySet(); > else { > TypeElement annotationType = processingEnv.getElementUtils().getTypeElement(name); > if (annotationType == null) > return Collections.emptySet(); > else > return getElementsAnnotatedWith(annotationType); > } > } See bug 6411919 for changes to src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
27-06-2006

EVALUATION I think two overloaded getElementsAnnotedWith method could be justified: 1) The existing one that takes TypeMirrors, which is the type of object passed into the Process method 2) A new method that also took Annotation.class arguments
15-05-2006

EVALUATION For some common usage patterns (at least I keep running into them), this method would be very useful indeed.
14-05-2006