com.sun.tools.javac.model.JavacTypes Java Examples

The following examples show how to use com.sun.tools.javac.model.JavacTypes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestContext.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #2
Source File: Env.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
    currPath = path;
    currDocComment = comment;
    currElement = trees.getElement(currPath);
    currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);

    AccessKind ak = AccessKind.PUBLIC;
    for (TreePath p = path; p != null; p = p.getParentPath()) {
        Element e = trees.getElement(p);
        if (e != null && e.getKind() != ElementKind.PACKAGE) {
            ak = min(ak, AccessKind.of(e.getModifiers()));
        }
    }
    currAccess = ak;
}
 
Example #3
Source File: TestContext.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #4
Source File: TestContext.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #5
Source File: Env.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
    currPath = path;
    currDocComment = comment;
    currElement = trees.getElement(currPath);
    currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);

    AccessKind ak = AccessKind.PUBLIC;
    for (TreePath p = path; p != null; p = p.getParentPath()) {
        Element e = trees.getElement(p);
        if (e != null && e.getKind() != ElementKind.PACKAGE) {
            ak = min(ak, AccessKind.of(e.getModifiers()));
        }
    }
    currAccess = ak;
}
 
Example #6
Source File: Env.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
    currPath = path;
    currDocComment = comment;
    currElement = trees.getElement(currPath);
    currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);

    AccessKind ak = AccessKind.PUBLIC;
    for (TreePath p = path; p != null; p = p.getParentPath()) {
        Element e = trees.getElement(p);
        if (e != null && e.getKind() != ElementKind.PACKAGE) {
            ak = min(ak, AccessKind.of(e.getModifiers()));
        }
    }
    currAccess = ak;
}
 
Example #7
Source File: Env.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
    currPath = path;
    currDocComment = comment;
    currElement = trees.getElement(currPath);
    currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);

    AccessKind ak = AccessKind.PUBLIC;
    for (TreePath p = path; p != null; p = p.getParentPath()) {
        Element e = trees.getElement(p);
        if (e != null && e.getKind() != ElementKind.PACKAGE) {
            ak = min(ak, AccessKind.of(e.getModifiers()));
        }
    }
    currAccess = ak;
}
 
Example #8
Source File: Env.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
    currPath = path;
    currDocComment = comment;
    currElement = trees.getElement(currPath);
    currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);

    AccessKind ak = AccessKind.PUBLIC;
    for (TreePath p = path; p != null; p = p.getParentPath()) {
        Element e = trees.getElement(p);
        if (e != null && e.getKind() != ElementKind.PACKAGE) {
            ak = min(ak, AccessKind.of(e.getModifiers()));
        }
    }
    currAccess = ak;
}
 
Example #9
Source File: Env.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
    currPath = path;
    currDocComment = comment;
    currElement = trees.getElement(currPath);
    currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);

    AccessKind ak = AccessKind.PUBLIC;
    for (TreePath p = path; p != null; p = p.getParentPath()) {
        Element e = trees.getElement(p);
        if (e != null && e.getKind() != ElementKind.PACKAGE) {
            ak = min(ak, AccessKind.of(e.getModifiers()));
        }
    }
    currAccess = ak;
}
 
Example #10
Source File: ManTypes.java    From manifold with Apache License 2.0 6 votes vote down vote up
private void reassignEarlyHolders8( Context context )
{
  ReflectUtil.field( Annotate.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Attr.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Check.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( DeferredAttr.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Flow.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Gen.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Infer.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavaCompiler.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacTrees.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacTypes.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacElements.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( LambdaToMethod.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Lower.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( ManResolve.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( MemberEnter.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( RichDiagnosticFormatter.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( TransTypes.instance( context ), TYPES_FIELD ).set( this );
}
 
Example #11
Source File: TestContext.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #12
Source File: TestContext.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #13
Source File: Utils.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return true if the given Element is deprecated for removal.
 *
 * @param e the Element to check.
 * @return true if the given Element is deprecated for removal.
 */
public boolean isDeprecatedForRemoval(Element e) {
    List<? extends AnnotationMirror> annotationList = e.getAnnotationMirrors();
    JavacTypes jctypes = ((DocEnvImpl) configuration.docEnv).toolEnv.typeutils;
    for (AnnotationMirror anno : annotationList) {
        if (jctypes.isSameType(anno.getAnnotationType().asElement().asType(), getDeprecatedType())) {
            Map<? extends ExecutableElement, ? extends AnnotationValue> pairs = anno.getElementValues();
            if (!pairs.isEmpty()) {
                for (ExecutableElement element : pairs.keySet()) {
                    if (element.getSimpleName().contentEquals("forRemoval")) {
                        return Boolean.parseBoolean((pairs.get(element)).toString());
                    }
                }
            }
        }
    }
    return false;
}
 
Example #14
Source File: Env.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
    currPath = path;
    currDocComment = comment;
    currElement = trees.getElement(currPath);
    currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);

    AccessKind ak = AccessKind.PUBLIC;
    for (TreePath p = path; p != null; p = p.getParentPath()) {
        Element e = trees.getElement(p);
        if (e != null && e.getKind() != ElementKind.PACKAGE && e.getKind() != ElementKind.MODULE) {
            ak = min(ak, AccessKind.of(e.getModifiers()));
        }
    }
    currAccess = ak;
}
 
Example #15
Source File: ElementUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**Return variables declared in the given scope.
 */
public Iterable<? extends Element> getLocalVars(Scope scope, ElementAcceptor acceptor) {
    ArrayList<Element> members = new ArrayList<Element>();
    Elements elements = JavacElements.instance(ctx);
    Types types = JavacTypes.instance(ctx);
    while(scope != null && scope.getEnclosingClass() != null) {
        for (Element local : scope.getLocalElements()) {
            if (acceptor == null || acceptor.accept(local, null)) {
                if (!isHidden(local, members, elements, types)) {
                    members.add(local);
                }
            }
        }
        scope = scope.getEnclosingScope();
    }
    return members;
}
 
Example #16
Source File: Env.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
    currPath = path;
    currDocComment = comment;
    currElement = trees.getElement(currPath);
    currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);

    AccessKind ak = AccessKind.PUBLIC;
    for (TreePath p = path; p != null; p = p.getParentPath()) {
        Element e = trees.getElement(p);
        if (e != null && e.getKind() != ElementKind.PACKAGE) {
            ak = min(ak, AccessKind.of(e.getModifiers()));
        }
    }
    currAccess = ak;
}
 
Example #17
Source File: TestContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #18
Source File: JNIWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void lazyInit() {
    if (mangler == null) {
        elements = JavacElements.instance(context);
        types = JavacTypes.instance(context);
        mangler = new Mangle(elements, types);
    }
}
 
Example #19
Source File: JNIWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void lazyInit() {
    if (mangler == null) {
        elements = JavacElements.instance(context);
        types = JavacTypes.instance(context);
        mangler = new Mangle(elements, types);
    }
}
 
Example #20
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected JavacProcessingEnvironment(Context context) {
    this.context = context;
    context.put(JavacProcessingEnvironment.class, this);
    log = Log.instance(context);
    source = Source.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    options = Options.instance(context);
    printProcessorInfo = options.isSet(XPRINTPROCESSORINFO);
    printRounds = options.isSet(XPRINTROUNDS);
    verbose = options.isSet(VERBOSE);
    lint = Lint.instance(context).isEnabled(PROCESSING);
    if (options.isSet(PROC, "only") || options.isSet(XPRINT)) {
        JavaCompiler compiler = JavaCompiler.instance(context);
        compiler.shouldStopPolicyIfNoError = CompileState.PROCESS;
    }
    fatalErrors = options.isSet("fatalEnterError");
    showResolveErrors = options.isSet("showResolveErrors");
    werror = options.isSet(WERROR);
    platformAnnotations = initPlatformAnnotations();

    // Initialize services before any processors are initialized
    // in case processors use them.
    filer = new JavacFiler(context);
    messager = new JavacMessager(context, this);
    elementUtils = JavacElements.instance(context);
    typeUtils = JavacTypes.instance(context);
    processorOptions = initProcessorOptions(context);
    unmatchedProcessorOptions = initUnmatchedProcessorOptions();
    messages = JavacMessages.instance(context);
    taskListener = MultiTaskListener.instance(context);
    initProcessorClassLoader();
}
 
Example #21
Source File: TestSymtabItems.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void run() throws Exception {
        Context c = new Context();
        JavacFileManager.preRegister(c);
        Symtab syms = Symtab.instance(c);
        JavacTypes types = JavacTypes.instance(c);
        JavaCompiler.instance(c);  // will init ClassReader.sourceCompleter

//        print("noSymbol", syms.noSymbol);
//        print("errSymbol", syms.errSymbol);
//        print("unknownSymbol", syms.unknownSymbol);
//        print("botType", syms.botType);
//        print("errType", syms.errType);
//        print("unknownType", syms.unknownType);

        for (Field f: Symtab.class.getDeclaredFields()) {
//            System.err.println(f.getType() + " " + f.getName());

            // Temporarily ignore methodHandle and transientMethodHandle
            // during API evolution
            if (f.getName().toLowerCase().contains("methodhandle"))
                continue;

            Class<?> ft = f.getType();
            if (TypeMirror.class.isAssignableFrom(ft))
                print(f.getName(), (TypeMirror) f.get(syms), types);
            else if(Element.class.isAssignableFrom(ft))
                print(f.getName(), (Element) f.get(syms));
        }

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    }
 
Example #22
Source File: AbstractCodingRulesAnalyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public AbstractCodingRulesAnalyzer(JavacTask task) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    options = Options.instance(context);
    rawDiagnostics = options.isSet("rawDiagnostics");
    diags = JCDiagnostic.Factory.instance(context);
    messages = new Messages();
    syms = Symtab.instance(context);
    elements = JavacElements.instance(context);
    types = JavacTypes.instance(context);
}
 
Example #23
Source File: JNIWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void lazyInit() {
    if (mangler == null) {
        elements = JavacElements.instance(context);
        types = JavacTypes.instance(context);
        mangler = new Mangle(elements, types);
    }
}
 
Example #24
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 5 votes vote down vote up
JavaEnvironment(Context context, List<String> typeElementsNames) {
  this.javacTypes = JavacTypes.instance(context);
  this.internalTypes = Types.instance(context);
  this.elements = JavacElements.instance(context);

  initWellKnownTypes(typeElementsNames);
}
 
Example #25
Source File: JavacProcessingEnvironment.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) {
    this.context = context;
    log = Log.instance(context);
    source = Source.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    options = Options.instance(context);
    printProcessorInfo = options.isSet(XPRINTPROCESSORINFO);
    printRounds = options.isSet(XPRINTROUNDS);
    verbose = options.isSet(VERBOSE);
    lint = Lint.instance(context).isEnabled(PROCESSING);
    procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT);
    fatalErrors = options.isSet("fatalEnterError");
    showResolveErrors = options.isSet("showResolveErrors");
    werror = options.isSet(WERROR);
    platformAnnotations = initPlatformAnnotations();
    foundTypeProcessors = false;

    // Initialize services before any processors are initialized
    // in case processors use them.
    filer = new JavacFiler(context);
    messager = new JavacMessager(context, this);
    elementUtils = JavacElements.instance(context);
    typeUtils = JavacTypes.instance(context);
    processorOptions = initProcessorOptions(context);
    unmatchedProcessorOptions = initUnmatchedProcessorOptions();
    messages = JavacMessages.instance(context);
    initProcessorIterator(context, processors);
}
 
Example #26
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected JavacProcessingEnvironment(Context context) {
    this.context = context;
    context.put(JavacProcessingEnvironment.class, this);
    log = Log.instance(context);
    source = Source.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    options = Options.instance(context);
    printProcessorInfo = options.isSet(XPRINTPROCESSORINFO);
    printRounds = options.isSet(XPRINTROUNDS);
    verbose = options.isSet(VERBOSE);
    lint = Lint.instance(context).isEnabled(PROCESSING);
    if (options.isSet(PROC, "only") || options.isSet(XPRINT)) {
        JavaCompiler compiler = JavaCompiler.instance(context);
        compiler.shouldStopPolicyIfNoError = CompileState.PROCESS;
    }
    fatalErrors = options.isSet("fatalEnterError");
    showResolveErrors = options.isSet("showResolveErrors");
    werror = options.isSet(WERROR);
    platformAnnotations = initPlatformAnnotations();

    // Initialize services before any processors are initialized
    // in case processors use them.
    filer = new JavacFiler(context);
    messager = new JavacMessager(context, this);
    elementUtils = JavacElements.instance(context);
    typeUtils = JavacTypes.instance(context);
    processorOptions = initProcessorOptions(context);
    unmatchedProcessorOptions = initUnmatchedProcessorOptions();
    messages = JavacMessages.instance(context);
    taskListener = MultiTaskListener.instance(context);
    initProcessorClassLoader();
}
 
Example #27
Source File: ScopeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyLambdaScopeCorrect(final String packageClause) throws Exception {
    JavacTool tool = JavacTool.create();
    JavaFileObject source = new SimpleJavaFileObject(URI.create("mem://Test.java"), Kind.SOURCE) {
        @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
            return packageClause + SOURCE_CODE;
        }
        @Override public boolean isNameCompatible(String simpleName, Kind kind) {
            return true;
        }
    };
    Iterable<? extends JavaFileObject> fos = Collections.singletonList(source);
    JavacTask task = tool.getTask(null, null, null, new ArrayList<String>(), null, fos);
    final Types types = JavacTypes.instance(((JavacTaskImpl) task).getContext());
    final Trees trees = Trees.instance(task);
    CompilationUnitTree cu = task.parse().iterator().next();

    task.analyze();

    new TreePathScanner<Void, Void>() {
        @Override public Void visitMemberSelect(MemberSelectTree node, Void p) {
            if (node.getIdentifier().contentEquals("correct")) {
                TypeMirror xType = trees.getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
                Scope scope = trees.getScope(getCurrentPath());
                for (Element l : scope.getLocalElements()) {
                    if (!l.getSimpleName().contentEquals("x")) continue;
                    if (!types.isSameType(xType, l.asType())) {
                        throw new IllegalStateException("Incorrect variable type in scope: " + l.asType() + "; should be: " + xType);
                    }
                }
            }
            return super.visitMemberSelect(node, p);
        }
    }.scan(cu, null);
}
 
Example #28
Source File: JNIWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void lazyInit() {
    if (mangler == null) {
        elements = JavacElements.instance(context);
        types = JavacTypes.instance(context);
        mangler = new Mangle(elements, types);
    }
}
 
Example #29
Source File: TestSymtabItems.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void run() throws Exception {
        Context c = new Context();
        JavacFileManager.preRegister(c);
        Symtab syms = Symtab.instance(c);
        JavacTypes types = JavacTypes.instance(c);
        JavaCompiler.instance(c);  // will init ClassReader.sourceCompleter

//        print("noSymbol", syms.noSymbol);
//        print("errSymbol", syms.errSymbol);
//        print("unknownSymbol", syms.unknownSymbol);
//        print("botType", syms.botType);
//        print("errType", syms.errType);
//        print("unknownType", syms.unknownType);

        for (Field f: Symtab.class.getDeclaredFields()) {
//            System.err.println(f.getType() + " " + f.getName());

            // Temporarily ignore methodHandle and transientMethodHandle
            // during API evolution
            if (f.getName().toLowerCase().contains("methodhandle"))
                continue;

            Class<?> ft = f.getType();
            if (TypeMirror.class.isAssignableFrom(ft))
                print(f.getName(), (TypeMirror) f.get(syms), types);
            else if(Element.class.isAssignableFrom(ft))
                print(f.getName(), (Element) f.get(syms));
        }

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    }
 
Example #30
Source File: TestSymtabItems.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void run() throws Exception {
        Context c = new Context();
        JavacFileManager.preRegister(c);
        Symtab syms = Symtab.instance(c);
        JavacTypes types = JavacTypes.instance(c);
        JavaCompiler.instance(c);  // will init ClassReader.sourceCompleter

//        print("noSymbol", syms.noSymbol);
//        print("errSymbol", syms.errSymbol);
//        print("unknownSymbol", syms.unknownSymbol);
//        print("botType", syms.botType);
//        print("errType", syms.errType);
//        print("unknownType", syms.unknownType);

        for (Field f: Symtab.class.getDeclaredFields()) {
//            System.err.println(f.getType() + " " + f.getName());

            // Temporarily ignore methodHandle and transientMethodHandle
            // during API evolution
            if (f.getName().toLowerCase().contains("methodhandle"))
                continue;

            //both noModule and unnamedModule claim the unnamed package, ignore noModule for now:
            if (f.getName().equals("noModule"))
                continue;

            f.setAccessible(true);
            Class<?> ft = f.getType();
            if (TypeMirror.class.isAssignableFrom(ft))
                print(f.getName(), (TypeMirror) f.get(syms), types);
            else if(Element.class.isAssignableFrom(ft))
                print(f.getName(), (Element) f.get(syms));
        }

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    }