United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6425592 JSR 269: please provide RoundEnvironment.getElementsAnnotatedWith(Class<? extends Annotation>)
JDK-6425592 : JSR 269: please provide RoundEnvironment.getElementsAnnotatedWith(Class)

Details
Type:
Bug
Submit Date:
2006-05-14
Status:
Closed
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2006-07-01
Component:
core-libs
OS:
generic
Sub-Component:
javax.annotation.processing
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports

Sub Tasks

Description
javax.annotation.processing.RoundEnvironment.getElementsAnnotatedWith(TypeElement)
is a bit hard to use.  This would be simpler:

roundEnv.getElementsAnnotatedWith(MyAnnotation.class);

                                    

Comments
EVALUATION

For some common usage patterns (at least I keep running into them), 
this method would be very useful indeed.
                                     
2006-05-14
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
                                     
2006-05-15
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
                                     
2006-06-27



Hardware and Software, Engineered to Work Together