langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java
changeset 26266 2d24bda701dc
parent 25874 83c19f00452c
child 31751 ec251536a004
equal deleted inserted replaced
26265:46aacfffd3b5 26266:2d24bda701dc
    28 import java.lang.annotation.Annotation;
    28 import java.lang.annotation.Annotation;
    29 import javax.annotation.processing.*;
    29 import javax.annotation.processing.*;
    30 import javax.lang.model.element.*;
    30 import javax.lang.model.element.*;
    31 import javax.lang.model.util.*;
    31 import javax.lang.model.util.*;
    32 import java.util.*;
    32 import java.util.*;
       
    33 
       
    34 import com.sun.tools.javac.util.DefinedBy;
       
    35 import com.sun.tools.javac.util.DefinedBy.Api;
    33 
    36 
    34 /**
    37 /**
    35  * Object providing state about a prior round of annotation processing.
    38  * Object providing state about a prior round of annotation processing.
    36  *
    39  *
    37  * <p>The methods in this class do not take type annotations into account,
    40  * <p>The methods in this class do not take type annotations into account,
    67                              errorRaised,
    70                              errorRaised,
    68                              rootElements,
    71                              rootElements,
    69                              processingOver);
    72                              processingOver);
    70     }
    73     }
    71 
    74 
       
    75     @DefinedBy(Api.ANNOTATION_PROCESSING)
    72     public boolean processingOver() {
    76     public boolean processingOver() {
    73         return processingOver;
    77         return processingOver;
    74     }
    78     }
    75 
    79 
    76     /**
    80     /**
    78      * of processing; returns {@code false} otherwise.
    82      * of processing; returns {@code false} otherwise.
    79      *
    83      *
    80      * @return {@code true} if an error was raised in the prior round
    84      * @return {@code true} if an error was raised in the prior round
    81      * of processing; returns {@code false} otherwise.
    85      * of processing; returns {@code false} otherwise.
    82      */
    86      */
       
    87     @DefinedBy(Api.ANNOTATION_PROCESSING)
    83     public boolean errorRaised() {
    88     public boolean errorRaised() {
    84         return errorRaised;
    89         return errorRaised;
    85     }
    90     }
    86 
    91 
    87     /**
    92     /**
    88      * Returns the type elements specified by the prior round.
    93      * Returns the type elements specified by the prior round.
    89      *
    94      *
    90      * @return the types elements specified by the prior round, or an
    95      * @return the types elements specified by the prior round, or an
    91      * empty set if there were none
    96      * empty set if there were none
    92      */
    97      */
       
    98     @DefinedBy(Api.ANNOTATION_PROCESSING)
    93     public Set<? extends Element> getRootElements() {
    99     public Set<? extends Element> getRootElements() {
    94         return rootElements;
   100         return rootElements;
    95     }
   101     }
    96 
   102 
    97     private static final String NOT_AN_ANNOTATION_TYPE =
   103     private static final String NOT_AN_ANNOTATION_TYPE =
   107      *
   113      *
   108      * @param a  annotation type being requested
   114      * @param a  annotation type being requested
   109      * @return the elements annotated with the given annotation type,
   115      * @return the elements annotated with the given annotation type,
   110      * or an empty set if there are none
   116      * or an empty set if there are none
   111      */
   117      */
       
   118     @DefinedBy(Api.ANNOTATION_PROCESSING)
   112     public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) {
   119     public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) {
   113         Set<Element> result = Collections.emptySet();
   120         Set<Element> result = Collections.emptySet();
   114         if (a.getKind() != ElementKind.ANNOTATION_TYPE)
   121         if (a.getKind() != ElementKind.ANNOTATION_TYPE)
   115             throw new IllegalArgumentException(NOT_AN_ANNOTATION_TYPE + a);
   122             throw new IllegalArgumentException(NOT_AN_ANNOTATION_TYPE + a);
   116 
   123 
   131 
   138 
   132         AnnotationSetScanner(Set<Element> defaultSet) {
   139         AnnotationSetScanner(Set<Element> defaultSet) {
   133             super(defaultSet);
   140             super(defaultSet);
   134         }
   141         }
   135 
   142 
   136         @Override
   143         @Override @DefinedBy(Api.LANGUAGE_MODEL)
   137         public Set<Element> visitType(TypeElement e, TypeElement p) {
   144         public Set<Element> visitType(TypeElement e, TypeElement p) {
   138             // Type parameters are not considered to be enclosed by a type
   145             // Type parameters are not considered to be enclosed by a type
   139             scan(e.getTypeParameters(), p);
   146             scan(e.getTypeParameters(), p);
   140             return super.visitType(e, p);
   147             return super.visitType(e, p);
   141         }
   148         }
   142 
   149 
   143         @Override
   150         @Override @DefinedBy(Api.LANGUAGE_MODEL)
   144         public Set<Element> visitExecutable(ExecutableElement e, TypeElement p) {
   151         public Set<Element> visitExecutable(ExecutableElement e, TypeElement p) {
   145             // Type parameters are not considered to be enclosed by an executable
   152             // Type parameters are not considered to be enclosed by an executable
   146             scan(e.getTypeParameters(), p);
   153             scan(e.getTypeParameters(), p);
   147             return super.visitExecutable(e, p);
   154             return super.visitExecutable(e, p);
   148         }
   155         }
   149 
   156 
   150         @Override
   157         @Override @DefinedBy(Api.LANGUAGE_MODEL)
   151         public Set<Element> scan(Element e, TypeElement p) {
   158         public Set<Element> scan(Element e, TypeElement p) {
   152             java.util.List<? extends AnnotationMirror> annotationMirrors =
   159             java.util.List<? extends AnnotationMirror> annotationMirrors =
   153                 processingEnv.getElementUtils().getAllAnnotationMirrors(e);
   160                 processingEnv.getElementUtils().getAllAnnotationMirrors(e);
   154             for (AnnotationMirror annotationMirror : annotationMirrors) {
   161             for (AnnotationMirror annotationMirror : annotationMirrors) {
   155                 if (p.equals(annotationMirror.getAnnotationType().asElement()))
   162                 if (p.equals(annotationMirror.getAnnotationType().asElement()))
   161     }
   168     }
   162 
   169 
   163     /**
   170     /**
   164      * {@inheritdoc}
   171      * {@inheritdoc}
   165      */
   172      */
       
   173     @DefinedBy(Api.ANNOTATION_PROCESSING)
   166     public Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a) {
   174     public Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a) {
   167         if (!a.isAnnotation())
   175         if (!a.isAnnotation())
   168             throw new IllegalArgumentException(NOT_AN_ANNOTATION_TYPE + a);
   176             throw new IllegalArgumentException(NOT_AN_ANNOTATION_TYPE + a);
   169         String name = a.getCanonicalName();
   177         String name = a.getCanonicalName();
   170         if (name == null)
   178         if (name == null)