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

Print this page




  66     public boolean process(Set<? extends TypeElement> tes,
  67                            RoundEnvironment renv) {
  68 
  69         for(Element element : renv.getRootElements()) {
  70             print(element);
  71         }
  72 
  73         // Just print the elements, nothing more to do.
  74         return true;
  75     }
  76 
  77     void print(Element element) {
  78         new PrintingElementVisitor(writer, processingEnv.getElementUtils()).
  79             visit(element).flush();
  80     }
  81 
  82     /**
  83      * Used for the -Xprint option and called by Elements.printElements
  84      */
  85     public static class PrintingElementVisitor
  86         extends SimpleElementVisitor6<PrintingElementVisitor, Boolean> {
  87         int indentation; // Indentation level;
  88         final PrintWriter writer;
  89         final Elements elementUtils;
  90 
  91         public PrintingElementVisitor(Writer w, Elements elementUtils) {
  92             super();
  93             this.writer = new PrintWriter(w);
  94             this.elementUtils = elementUtils;
  95             indentation = 0;
  96         }
  97 
  98         @Override
  99         protected PrintingElementVisitor defaultAction(Element e, Boolean newLine) {
 100             if (newLine != null && newLine)
 101                 writer.println();
 102             printDocComment(e);
 103             printModifiers(e);
 104             return this;
 105         }
 106 
 107         @Override
 108         public PrintingElementVisitor visitExecutable(ExecutableElement e, Boolean p) {
 109             ElementKind kind = e.getKind();
 110 
 111             if (kind != STATIC_INIT &&
 112                 kind != INSTANCE_INIT) {
 113                 Element enclosing = e.getEnclosingElement();
 114 
 115                 // Don't print out the constructor of an anonymous class
 116                 if (kind == CONSTRUCTOR &&
 117                     enclosing != null &&
 118                     NestingKind.ANONYMOUS ==
 119                     // Use an anonymous class to determine anonymity!
 120                     (new SimpleElementVisitor6<NestingKind, Void>() {
 121                         @Override
 122                         public NestingKind visitType(TypeElement e, Void p) {
 123                             return e.getNestingKind();
 124                         }
 125                     }).visit(enclosing))
 126                     return this;
 127 
 128                 defaultAction(e, true);
 129                 printFormalTypeParameters(e, true);
 130 
 131                 switch(kind) {
 132                     case CONSTRUCTOR:
 133                     // Print out simple name of the class
 134                     writer.print(e.getEnclosingElement().getSimpleName());
 135                     break;
 136 
 137                     case METHOD:
 138                     writer.print(e.getReturnType().toString());
 139                     writer.print(" ");
 140                     writer.print(e.getSimpleName().toString());




  66     public boolean process(Set<? extends TypeElement> tes,
  67                            RoundEnvironment renv) {
  68 
  69         for(Element element : renv.getRootElements()) {
  70             print(element);
  71         }
  72 
  73         // Just print the elements, nothing more to do.
  74         return true;
  75     }
  76 
  77     void print(Element element) {
  78         new PrintingElementVisitor(writer, processingEnv.getElementUtils()).
  79             visit(element).flush();
  80     }
  81 
  82     /**
  83      * Used for the -Xprint option and called by Elements.printElements
  84      */
  85     public static class PrintingElementVisitor
  86         extends SimpleElementVisitor7<PrintingElementVisitor, Boolean> {
  87         int indentation; // Indentation level;
  88         final PrintWriter writer;
  89         final Elements elementUtils;
  90 
  91         public PrintingElementVisitor(Writer w, Elements elementUtils) {
  92             super();
  93             this.writer = new PrintWriter(w);
  94             this.elementUtils = elementUtils;
  95             indentation = 0;
  96         }
  97 
  98         @Override
  99         protected PrintingElementVisitor defaultAction(Element e, Boolean newLine) {
 100             if (newLine != null && newLine)
 101                 writer.println();
 102             printDocComment(e);
 103             printModifiers(e);
 104             return this;
 105         }
 106 
 107         @Override
 108         public PrintingElementVisitor visitExecutable(ExecutableElement e, Boolean p) {
 109             ElementKind kind = e.getKind();
 110 
 111             if (kind != STATIC_INIT &&
 112                 kind != INSTANCE_INIT) {
 113                 Element enclosing = e.getEnclosingElement();
 114 
 115                 // Don't print out the constructor of an anonymous class
 116                 if (kind == CONSTRUCTOR &&
 117                     enclosing != null &&
 118                     NestingKind.ANONYMOUS ==
 119                     // Use an anonymous class to determine anonymity!
 120                     (new SimpleElementVisitor7<NestingKind, Void>() {
 121                         @Override
 122                         public NestingKind visitType(TypeElement e, Void p) {
 123                             return e.getNestingKind();
 124                         }
 125                     }).visit(enclosing))
 126                     return this;
 127 
 128                 defaultAction(e, true);
 129                 printFormalTypeParameters(e, true);
 130 
 131                 switch(kind) {
 132                     case CONSTRUCTOR:
 133                     // Print out simple name of the class
 134                     writer.print(e.getEnclosingElement().getSimpleName());
 135                     break;
 136 
 137                     case METHOD:
 138                     writer.print(e.getReturnType().toString());
 139                     writer.print(" ");
 140                     writer.print(e.getSimpleName().toString());