src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java

Print this page




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.processing;
  27 
  28 import java.io.Closeable;
  29 import java.io.File;
  30 import java.io.PrintWriter;
  31 import java.io.StringWriter;
  32 import java.net.MalformedURLException;
  33 import java.net.URL;
  34 import java.util.*;
  35 import java.util.regex.*;
  36 
  37 import javax.annotation.processing.*;
  38 import javax.lang.model.SourceVersion;
  39 import javax.lang.model.element.AnnotationMirror;
  40 import javax.lang.model.element.Element;
  41 import javax.lang.model.element.PackageElement;
  42 import javax.lang.model.element.TypeElement;
  43 import javax.lang.model.util.*;
  44 import javax.tools.DiagnosticListener;
  45 import javax.tools.JavaFileManager;
  46 import javax.tools.JavaFileObject;
  47 import javax.tools.StandardJavaFileManager;
  48 import static javax.tools.StandardLocation.*;
  49 
  50 import com.sun.source.util.JavacTask;
  51 import com.sun.source.util.TaskEvent;
  52 import com.sun.tools.javac.api.BasicJavacTask;
  53 import com.sun.tools.javac.api.JavacTrees;
  54 import com.sun.tools.javac.api.MultiTaskListener;
  55 import com.sun.tools.javac.code.*;
  56 import com.sun.tools.javac.code.Symbol.*;
  57 import com.sun.tools.javac.file.FSInfo;
  58 import com.sun.tools.javac.file.JavacFileManager;
  59 import com.sun.tools.javac.jvm.*;
  60 import com.sun.tools.javac.jvm.ClassReader.BadClassFile;
  61 import com.sun.tools.javac.main.JavaCompiler;
  62 import com.sun.tools.javac.model.JavacElements;


 745     /**
 746      * Computes the set of annotations on the symbol in question.
 747      * Leave class public for external testing purposes.
 748      */
 749     public static class ComputeAnnotationSet extends
 750         ElementScanner8<Set<TypeElement>, Set<TypeElement>> {
 751         final Elements elements;
 752 
 753         public ComputeAnnotationSet(Elements elements) {
 754             super();
 755             this.elements = elements;
 756         }
 757 
 758         @Override
 759         public Set<TypeElement> visitPackage(PackageElement e, Set<TypeElement> p) {
 760             // Don't scan enclosed elements of a package
 761             return p;
 762         }
 763 
 764         @Override
 765         public Set<TypeElement> scan(Element e, Set<TypeElement> p) {













 766             for (AnnotationMirror annotationMirror :
 767                      elements.getAllAnnotationMirrors(e) ) {
 768                 Element e2 = annotationMirror.getAnnotationType().asElement();
 769                 p.add((TypeElement) e2);
 770             }





 771             return super.scan(e, p);
 772         }
 773     }
 774 
 775     private boolean callProcessor(Processor proc,
 776                                          Set<? extends TypeElement> tes,
 777                                          RoundEnvironment renv) {
 778         try {
 779             return proc.process(tes, renv);
 780         } catch (BadClassFile ex) {
 781             log.error("proc.cant.access.1", ex.sym, ex.getDetailValue());
 782             return false;
 783         } catch (CompletionFailure ex) {
 784             StringWriter out = new StringWriter();
 785             ex.printStackTrace(new PrintWriter(out));
 786             log.error("proc.cant.access", ex.sym, ex.getDetailValue(), out.toString());
 787             return false;
 788         } catch (ClientCodeException e) {
 789             throw e;
 790         } catch (Throwable t) {




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.processing;
  27 
  28 import java.io.Closeable;
  29 import java.io.File;
  30 import java.io.PrintWriter;
  31 import java.io.StringWriter;
  32 import java.net.MalformedURLException;
  33 import java.net.URL;
  34 import java.util.*;
  35 import java.util.regex.*;
  36 
  37 import javax.annotation.processing.*;
  38 import javax.lang.model.SourceVersion;
  39 import javax.lang.model.element.*;



  40 import javax.lang.model.util.*;
  41 import javax.tools.DiagnosticListener;
  42 import javax.tools.JavaFileManager;
  43 import javax.tools.JavaFileObject;
  44 import javax.tools.StandardJavaFileManager;
  45 import static javax.tools.StandardLocation.*;
  46 
  47 import com.sun.source.util.JavacTask;
  48 import com.sun.source.util.TaskEvent;
  49 import com.sun.tools.javac.api.BasicJavacTask;
  50 import com.sun.tools.javac.api.JavacTrees;
  51 import com.sun.tools.javac.api.MultiTaskListener;
  52 import com.sun.tools.javac.code.*;
  53 import com.sun.tools.javac.code.Symbol.*;
  54 import com.sun.tools.javac.file.FSInfo;
  55 import com.sun.tools.javac.file.JavacFileManager;
  56 import com.sun.tools.javac.jvm.*;
  57 import com.sun.tools.javac.jvm.ClassReader.BadClassFile;
  58 import com.sun.tools.javac.main.JavaCompiler;
  59 import com.sun.tools.javac.model.JavacElements;


 742     /**
 743      * Computes the set of annotations on the symbol in question.
 744      * Leave class public for external testing purposes.
 745      */
 746     public static class ComputeAnnotationSet extends
 747         ElementScanner8<Set<TypeElement>, Set<TypeElement>> {
 748         final Elements elements;
 749 
 750         public ComputeAnnotationSet(Elements elements) {
 751             super();
 752             this.elements = elements;
 753         }
 754 
 755         @Override
 756         public Set<TypeElement> visitPackage(PackageElement e, Set<TypeElement> p) {
 757             // Don't scan enclosed elements of a package
 758             return p;
 759         }
 760 
 761         @Override
 762         public Set<TypeElement> visitType(TypeElement e, Set<TypeElement> p) {
 763             // Type parameters are not considered to be enclosed by a type
 764             scan(e.getTypeParameters(), p);
 765             return scan(e.getEnclosedElements(), p);
 766         }
 767 
 768         @Override
 769         public Set<TypeElement> visitExecutable(ExecutableElement e, Set<TypeElement> p) {
 770             // Type parameters are not considered to be enclosed by an executable
 771             scan(e.getTypeParameters(), p);
 772             return scan(e.getEnclosedElements(), p);
 773         }
 774         
 775         void addAnnotations(Element e, Set<TypeElement> p) {
 776             for (AnnotationMirror annotationMirror :
 777                      elements.getAllAnnotationMirrors(e) ) {
 778                 Element e2 = annotationMirror.getAnnotationType().asElement();
 779                 p.add((TypeElement) e2);
 780             }
 781         }
 782 
 783         @Override
 784         public Set<TypeElement> scan(Element e, Set<TypeElement> p) {
 785             addAnnotations(e, p);
 786             return super.scan(e, p);
 787         }
 788     }
 789 
 790     private boolean callProcessor(Processor proc,
 791                                          Set<? extends TypeElement> tes,
 792                                          RoundEnvironment renv) {
 793         try {
 794             return proc.process(tes, renv);
 795         } catch (BadClassFile ex) {
 796             log.error("proc.cant.access.1", ex.sym, ex.getDetailValue());
 797             return false;
 798         } catch (CompletionFailure ex) {
 799             StringWriter out = new StringWriter();
 800             ex.printStackTrace(new PrintWriter(out));
 801             log.error("proc.cant.access", ex.sym, ex.getDetailValue(), out.toString());
 802             return false;
 803         } catch (ClientCodeException e) {
 804             throw e;
 805         } catch (Throwable t) {