< prev index next >

langtools/test/tools/javac/processing/model/TestSymtabItems.java

Print this page




  30  *          jdk.compiler/com.sun.tools.javac.main
  31  *          jdk.compiler/com.sun.tools.javac.model
  32  *          jdk.compiler/com.sun.tools.javac.util
  33  */
  34 
  35 import java.lang.reflect.Field;
  36 
  37 import javax.lang.model.element.Element;
  38 import javax.lang.model.element.ExecutableElement;
  39 import javax.lang.model.element.ModuleElement;
  40 import javax.lang.model.element.PackageElement;
  41 import javax.lang.model.element.TypeElement;
  42 import javax.lang.model.element.TypeParameterElement;
  43 import javax.lang.model.element.UnknownElementException;
  44 import javax.lang.model.element.VariableElement;
  45 import javax.lang.model.type.TypeMirror;
  46 import javax.lang.model.type.UnknownTypeException;
  47 import javax.lang.model.util.*;
  48 
  49 import com.sun.tools.javac.code.Symbol.ClassSymbol;


  50 import com.sun.tools.javac.code.Symtab;
  51 import com.sun.tools.javac.file.JavacFileManager;
  52 import com.sun.tools.javac.main.JavaCompiler;
  53 import com.sun.tools.javac.model.JavacTypes;
  54 import com.sun.tools.javac.util.Context;
  55 
  56 /**
  57  * Scan javac Symtab looking for TypeMirrors and Elements, and ensure that
  58  * no exceptions are thrown when used with javax.lang.model visitors.
  59  *
  60  */
  61 public class TestSymtabItems {
  62     public static void main(String... args) throws Exception {
  63         new TestSymtabItems().run();
  64     }
  65 
  66     void run() throws Exception {
  67         Context c = new Context();
  68         JavacFileManager.preRegister(c);
  69         Symtab syms = Symtab.instance(c);


 110 
 111     void print(String label, TypeMirror t, Types types) {
 112         TypePrinter tp = new TypePrinter();
 113         System.err.println("Test " + label);
 114         tp.visit(t, types);
 115         System.err.println();
 116     }
 117 
 118     void error(String msg) {
 119         System.err.println("Error: " + msg);
 120         errors++;
 121     }
 122 
 123     int errors;
 124 
 125     class ElemPrinter extends ElementScanner9<Void, Void> {
 126         @Override
 127         public Void visitModule(ModuleElement e, Void p) {
 128             show("module", e);
 129             indent(+1);




 130             super.visitModule(e, p);

 131             indent(-1);
 132             return null;
 133         }
 134 
 135         @Override
 136         public Void visitPackage(PackageElement e, Void p) {
 137             show("package", e);
 138             indent(+1);
 139             super.visitPackage(e, p);
 140             indent(-1);
 141             return null;
 142         }
 143 
 144         @Override
 145         public Void visitType(TypeElement e, Void p) {
 146             show("type", e);
 147             indent(+1);
 148             super.visitType(e, p);
 149             indent(-1);
 150             return null;




  30  *          jdk.compiler/com.sun.tools.javac.main
  31  *          jdk.compiler/com.sun.tools.javac.model
  32  *          jdk.compiler/com.sun.tools.javac.util
  33  */
  34 
  35 import java.lang.reflect.Field;
  36 
  37 import javax.lang.model.element.Element;
  38 import javax.lang.model.element.ExecutableElement;
  39 import javax.lang.model.element.ModuleElement;
  40 import javax.lang.model.element.PackageElement;
  41 import javax.lang.model.element.TypeElement;
  42 import javax.lang.model.element.TypeParameterElement;
  43 import javax.lang.model.element.UnknownElementException;
  44 import javax.lang.model.element.VariableElement;
  45 import javax.lang.model.type.TypeMirror;
  46 import javax.lang.model.type.UnknownTypeException;
  47 import javax.lang.model.util.*;
  48 
  49 import com.sun.tools.javac.code.Symbol.ClassSymbol;
  50 import com.sun.tools.javac.code.Symbol.Completer;
  51 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
  52 import com.sun.tools.javac.code.Symtab;
  53 import com.sun.tools.javac.file.JavacFileManager;
  54 import com.sun.tools.javac.main.JavaCompiler;
  55 import com.sun.tools.javac.model.JavacTypes;
  56 import com.sun.tools.javac.util.Context;
  57 
  58 /**
  59  * Scan javac Symtab looking for TypeMirrors and Elements, and ensure that
  60  * no exceptions are thrown when used with javax.lang.model visitors.
  61  *
  62  */
  63 public class TestSymtabItems {
  64     public static void main(String... args) throws Exception {
  65         new TestSymtabItems().run();
  66     }
  67 
  68     void run() throws Exception {
  69         Context c = new Context();
  70         JavacFileManager.preRegister(c);
  71         Symtab syms = Symtab.instance(c);


 112 
 113     void print(String label, TypeMirror t, Types types) {
 114         TypePrinter tp = new TypePrinter();
 115         System.err.println("Test " + label);
 116         tp.visit(t, types);
 117         System.err.println();
 118     }
 119 
 120     void error(String msg) {
 121         System.err.println("Error: " + msg);
 122         errors++;
 123     }
 124 
 125     int errors;
 126 
 127     class ElemPrinter extends ElementScanner9<Void, Void> {
 128         @Override
 129         public Void visitModule(ModuleElement e, Void p) {
 130             show("module", e);
 131             indent(+1);
 132             if (e.getQualifiedName().contentEquals("jdk.incubator.mvt")) {
 133                 //completion of a module with 'requires' directive will fail at this stage.
 134                 ((ModuleSymbol) e).completer = Completer.NULL_COMPLETER;
 135             } else {
 136                 super.visitModule(e, p);
 137             }
 138             indent(-1);
 139             return null;
 140         }
 141 
 142         @Override
 143         public Void visitPackage(PackageElement e, Void p) {
 144             show("package", e);
 145             indent(+1);
 146             super.visitPackage(e, p);
 147             indent(-1);
 148             return null;
 149         }
 150 
 151         @Override
 152         public Void visitType(TypeElement e, Void p) {
 153             show("type", e);
 154             indent(+1);
 155             super.visitType(e, p);
 156             indent(-1);
 157             return null;


< prev index next >