com.sun.tools.javac.tree.TreeInfo Java Examples

The following examples show how to use com.sun.tools.javac.tree.TreeInfo. 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: JavacTrees.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Symbol getElement(TreePath path) {
    JCTree tree = (JCTree) path.getLeaf();
    Symbol sym = TreeInfo.symbolFor(tree);
    if (sym == null) {
        if (TreeInfo.isDeclaration(tree)) {
            for (TreePath p = path; p != null; p = p.getParentPath()) {
                JCTree t = (JCTree) p.getLeaf();
                if (t.hasTag(JCTree.Tag.CLASSDEF)) {
                    JCClassDecl ct = (JCClassDecl) t;
                    if (ct.sym != null) {
                        if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
                            attr.attribClass(ct.pos(), ct.sym);
                            sym = TreeInfo.symbolFor(tree);
                        }
                        break;
                    }
                }
            }
        }
    }
    return sym;
}
 
Example #2
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
boolean validateTargetAnnotationValue(JCAnnotation a) {
    // special case: java.lang.annotation.Target must not have
    // repeated values in its value member
    if (a.annotationType.type.tsym != syms.annotationTargetType.tsym ||
            a.args.tail == null)
        return true;

    boolean isValid = true;
    if (!a.args.head.hasTag(ASSIGN)) return false; // error recovery
    JCAssign assign = (JCAssign) a.args.head;
    Symbol m = TreeInfo.symbol(assign.lhs);
    if (m.name != names.value) return false;
    JCTree rhs = assign.rhs;
    if (!rhs.hasTag(NEWARRAY)) return false;
    JCNewArray na = (JCNewArray) rhs;
    Set<Symbol> targets = new HashSet<>();
    for (JCTree elem : na.elems) {
        if (!targets.add(TreeInfo.symbol(elem))) {
            isValid = false;
            log.error(elem.pos(), Errors.RepeatedAnnotationTarget);
        }
    }
    return isValid;
}
 
Example #3
Source File: JavacTrees.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public JCTree getTree(Element element) {
    Symbol symbol = (Symbol) element;
    TypeSymbol enclosing = symbol.enclClass();
    Env<AttrContext> env = enter.getEnv(enclosing);
    if (env == null)
        return null;
    JCClassDecl classNode = env.enclClass;
    if (classNode != null) {
        if (TreeInfo.symbolFor(classNode) == element)
            return classNode;
        for (JCTree node : classNode.getMembers())
            if (TreeInfo.symbolFor(node) == element)
                return node;
    }
    return null;
}
 
Example #4
Source File: VeryPretty.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private VeryPretty(Context context, CodeStyle cs, Map<Tree, ?> tree2Tag, Map<Tree, DocCommentTree> tree2Doc, Map<?, int[]> tag2Span, String origText) {
names = Names.instance(context);
enclClass = null;
       commentHandler = CommentHandlerService.instance(context);
       operators = Operators.instance(context);
widthEstimator = new WidthEstimator(context);
       danglingElseChecker = new DanglingElseChecker();
       prec = TreeInfo.notExpression;
       this.cs = cs;
       out = new CharBuffer(cs.getRightMargin(), cs.getTabSize(), cs.expandTabToSpaces());
       out.addTrimObserver(this);
       this.indentSize = cs.getIndentSize();
       this.tree2Tag = tree2Tag;
       this.tree2Doc = tree2Doc == null ? Collections.EMPTY_MAP : tree2Doc;
       this.tag2Span = (Map<Object, int[]>) tag2Span;//XXX
       this.origText = origText;
       this.comments = CommentHandlerService.instance(context);
   }
 
Example #5
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void checkImportedPackagesObservable(final JCCompilationUnit toplevel) {
    OUTER: for (JCImport imp : toplevel.getImports()) {
        if (!imp.staticImport && TreeInfo.name(imp.qualid) == names.asterisk) {
            TypeSymbol tsym = ((JCFieldAccess)imp.qualid).selected.type.tsym;
            if (toplevel.modle.visiblePackages != null) {
                //TODO - unclear: selects like javax.* will get resolved from the current module
                //(as javax is not an exported package from any module). And as javax in the current
                //module typically does not contain any classes or subpackages, we need to go through
                //the visible packages to find a sub-package:
                for (PackageSymbol known : toplevel.modle.visiblePackages.values()) {
                    if (Convert.packagePart(known.fullname) == tsym.flatName())
                        continue OUTER;
                }
            }
            if (tsym.kind == PCK && tsym.members().isEmpty() && !tsym.exists()) {
                log.error(DiagnosticFlag.RESOLVE_ERROR, imp.pos, Errors.DoesntExist(tsym));
            }
        }
    }
}
 
Example #6
Source File: JavacTrees.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public JCTree getTree(Element element) {
    Symbol symbol = (Symbol) element;
    TypeSymbol enclosing = symbol.enclClass();
    Env<AttrContext> env = enter.getEnv(enclosing);
    if (env == null)
        return null;
    JCClassDecl classNode = env.enclClass;
    if (classNode != null) {
        if (TreeInfo.symbolFor(classNode) == element)
            return classNode;
        for (JCTree node : classNode.getMembers())
            if (TreeInfo.symbolFor(node) == element)
                return node;
    }
    return null;
}
 
Example #7
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitMethodDef(JCMethodDecl tree) {
    if (tree.body == null) return;
    Lint lintPrev = lint;

    lint = lint.augment(tree.sym);

    Assert.check(pendingExits.isEmpty());

    try {
        alive = true;
        scanStat(tree.body);

        if (alive && !tree.sym.type.getReturnType().hasTag(VOID))
            log.error(TreeInfo.diagEndPos(tree.body), Errors.MissingRetStmt);

        List<PendingExit> exits = pendingExits.toList();
        pendingExits = new ListBuffer<>();
        while (exits.nonEmpty()) {
            PendingExit exit = exits.head;
            exits = exits.tail;
            Assert.check(exit.tree.hasTag(RETURN));
        }
    } finally {
        lint = lintPrev;
    }
}
 
Example #8
Source File: JavacTrees.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public JCTree getTree(Element element) {
    Symbol symbol = (Symbol) element;
    TypeSymbol enclosing = symbol.enclClass();
    Env<AttrContext> env = enter.getEnv(enclosing);
    if (env == null)
        return null;
    JCClassDecl classNode = env.enclClass;
    if (classNode != null) {
        if (TreeInfo.symbolFor(classNode) == element)
            return classNode;
        for (JCTree node : classNode.getMembers())
            if (TreeInfo.symbolFor(node) == element)
                return node;
    }
    return null;
}
 
Example #9
Source File: JavacTrees.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public JCTree getTree(Element element) {
    Symbol symbol = (Symbol) element;
    TypeSymbol enclosing = symbol.enclClass();
    Env<AttrContext> env = enter.getEnv(enclosing);
    if (env == null)
        return null;
    JCClassDecl classNode = env.enclClass;
    if (classNode != null) {
        if (TreeInfo.symbolFor(classNode) == element)
            return classNode;
        for (JCTree node : classNode.getMembers())
            if (TreeInfo.symbolFor(node) == element)
                return node;
    }
    return null;
}
 
Example #10
Source File: Annotate.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Attribute getAnnotationClassValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
    Type result = attr.attribExpr(tree, env, expectedElementType);
    if (result.isErroneous()) {
        // Does it look like an unresolved class literal?
        if (TreeInfo.name(tree) == names._class &&
                ((JCFieldAccess) tree).selected.type.isErroneous()) {
            Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName();
            return new Attribute.UnresolvedClass(expectedElementType,
                    types.createErrorType(n,
                            syms.unknownSymbol, syms.classType));
        } else {
            return new Attribute.Error(result.getOriginalType());
        }
    }

    // Class literals look like field accesses of a field named class
    // at the tree level
    if (TreeInfo.name(tree) != names._class) {
        log.error(tree.pos(), "annotation.value.must.be.class.literal");
        return new Attribute.Error(syms.errType);
    }
    return new Attribute.Class(types,
            (((JCFieldAccess) tree).selected).type);
}
 
Example #11
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings("fallthrough")
void letInit(JCTree tree) {
    tree = TreeInfo.skipParens(tree);
    if (tree.hasTag(IDENT) || tree.hasTag(SELECT)) {
        Symbol sym = TreeInfo.symbol(tree);
        if (currentTree != null &&
                sym.kind == VAR &&
                sym.owner.kind == MTH &&
                ((VarSymbol)sym).pos < currentTree.getStartPosition()) {
            switch (currentTree.getTag()) {
                case CLASSDEF:
                    if (!allowEffectivelyFinalInInnerClasses) {
                        reportInnerClsNeedsFinalError(tree, sym);
                        break;
                    }
                case LAMBDA:
                    reportEffectivelyFinalError(tree, sym);
            }
        }
    }
}
 
Example #12
Source File: JavacTrees.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public JCTree getTree(Element element) {
    Symbol symbol = (Symbol) element;
    TypeSymbol enclosing = symbol.enclClass();
    Env<AttrContext> env = enter.getEnv(enclosing);
    if (env == null)
        return null;
    JCClassDecl classNode = env.enclClass;
    if (classNode != null) {
        if (TreeInfo.symbolFor(classNode) == element)
            return classNode;
        for (JCTree node : classNode.getMembers())
            if (TreeInfo.symbolFor(node) == element)
                return node;
    }
    return null;
}
 
Example #13
Source File: JavacTrees.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Symbol getElement(TreePath path) {
    JCTree tree = (JCTree) path.getLeaf();
    Symbol sym = TreeInfo.symbolFor(tree);
    if (sym == null) {
        if (TreeInfo.isDeclaration(tree)) {
            for (TreePath p = path; p != null; p = p.getParentPath()) {
                JCTree t = (JCTree) p.getLeaf();
                if (t.hasTag(JCTree.Tag.CLASSDEF)) {
                    JCClassDecl ct = (JCClassDecl) t;
                    if (ct.sym != null) {
                        if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
                            attr.attribClass(ct.pos(), ct.sym);
                            sym = TreeInfo.symbolFor(tree);
                        }
                        break;
                    }
                }
            }
        }
    }
    return sym;
}
 
Example #14
Source File: JavacTrees.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Symbol getElement(TreePath path) {
    JCTree tree = (JCTree) path.getLeaf();
    Symbol sym = TreeInfo.symbolFor(tree);
    if (sym == null) {
        if (TreeInfo.isDeclaration(tree)) {
            for (TreePath p = path; p != null; p = p.getParentPath()) {
                JCTree t = (JCTree) p.getLeaf();
                if (t.hasTag(JCTree.Tag.CLASSDEF)) {
                    JCClassDecl ct = (JCClassDecl) t;
                    if (ct.sym != null) {
                        if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
                            attr.attribClass(ct.pos(), ct.sym);
                            sym = TreeInfo.symbolFor(tree);
                        }
                        break;
                    }
                }
            }
        }
    }
    return sym;
}
 
Example #15
Source File: JavacTrees.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public JCTree getTree(Element element) {
    Symbol symbol = (Symbol) element;
    TypeSymbol enclosing = symbol.enclClass();
    Env<AttrContext> env = enter.getEnv(enclosing);
    if (env == null)
        return null;
    JCClassDecl classNode = env.enclClass;
    if (classNode != null) {
        if (TreeInfo.symbolFor(classNode) == element)
            return classNode;
        for (JCTree node : classNode.getMembers())
            if (TreeInfo.symbolFor(node) == element)
                return node;
    }
    return null;
}
 
Example #16
Source File: JavacTrees.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public JCTree getTree(Element element) {
    Symbol symbol = (Symbol) element;
    TypeSymbol enclosing = symbol.enclClass();
    Env<AttrContext> env = enter.getEnv(enclosing);
    if (env == null)
        return null;
    JCClassDecl classNode = env.enclClass;
    if (classNode != null) {
        if (TreeInfo.symbolFor(classNode) == element)
            return classNode;
        for (JCTree node : classNode.getMembers())
            if (TreeInfo.symbolFor(node) == element)
                return node;
    }
    return null;
}
 
Example #17
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * If a list of annotations contains a reference to java.lang.Deprecated,
 * set the DEPRECATED flag.
 * If the annotation is marked forRemoval=true, also set DEPRECATED_REMOVAL.
 **/
private void handleDeprecatedAnnotations(List<JCAnnotation> annotations, Symbol sym) {
    for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
        JCAnnotation a = al.head;
        if (a.annotationType.type == syms.deprecatedType) {
            sym.flags_field |= (Flags.DEPRECATED | Flags.DEPRECATED_ANNOTATION);
           StreamSupport.stream(a.args)
                    .filter(e -> e.hasTag(ASSIGN))
                    .map(e -> (JCAssign) e)
                    .filter(assign -> TreeInfo.name(assign.lhs) == names.forRemoval)
                    .findFirst()
                    .ifPresent(assign -> {
                        JCExpression rhs = TreeInfo.skipParens(assign.rhs);
                        if (rhs.hasTag(LITERAL)
                                && Boolean.TRUE.equals(((JCLiteral) rhs).getValue())) {
                            sym.flags_field |= DEPRECATED_REMOVAL;
                        }
                    });
        }
    }
}
 
Example #18
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitSelect(JCFieldAccess tree) {
    // need to special case-access of the form C.super.x
    // these will always need an access method, unless C
    // is a default interface subclassed by the current class.
    boolean qualifiedSuperAccess =
        tree.selected.hasTag(SELECT) &&
        TreeInfo.name(tree.selected) == names._super &&
        !types.isDirectSuperInterface(((JCFieldAccess)tree.selected).selected.type.tsym, currentClass);
    tree.selected = translate(tree.selected);
    if (tree.name == names._class) {
        result = classOf(tree.selected);
    }
    else if (tree.name == names._super &&
            types.isDirectSuperInterface(tree.selected.type.tsym, currentClass)) {
        //default super call!! Not a classic qualified super call
        TypeSymbol supSym = tree.selected.type.tsym;
        Assert.checkNonNull(types.asSuper(currentClass.type, supSym));
        result = tree;
    }
    else if (tree.name == names._this || tree.name == names._super) {
        result = makeThis(tree.pos(), tree.selected.type.tsym);
    }
    else
        result = access(tree.sym, tree, enclOp, qualifiedSuperAccess);
}
 
Example #19
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitUses(JCUses tree) {
    Type st = attr.attribType(tree.qualid, env, syms.objectType);
    Symbol sym = TreeInfo.symbol(tree.qualid);
    if ((sym.flags() & ENUM) != 0) {
        log.error(tree.qualid.pos(), Errors.ServiceDefinitionIsEnum(st.tsym));
    } else if (st.hasTag(CLASS)) {
        ClassSymbol service = (ClassSymbol) st.tsym;
        if (allUses.add(service)) {
            Directive.UsesDirective d = new Directive.UsesDirective(service);
            msym.uses = msym.uses.prepend(d);
            msym.directives = msym.directives.prepend(d);
        } else {
            log.error(tree.pos(), Errors.DuplicateUses(service));
        }
    }
}
 
Example #20
Source File: WidthEstimator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void visitAssignop(JCAssignOp tree) {
open(prec, TreeInfo.assignopPrec);
width+=3;
width(operators.operatorName(tree.getTag()));
width(tree.lhs, TreeInfo.assignopPrec + 1);
width(tree.rhs, TreeInfo.assignopPrec);
   }
 
Example #21
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** If tree refers to a superclass constructor call,
 *  add all free variables of the superclass.
 */
public void visitApply(JCMethodInvocation tree) {
    if (TreeInfo.name(tree.meth) == names._super) {
        Symbol constructor = TreeInfo.symbol(tree.meth);
        ClassSymbol c = (ClassSymbol)constructor.owner;
        if (c.hasOuterInstance() &&
            !tree.meth.hasTag(SELECT) &&
            outerThisStack.head != null)
            visitSymbol(outerThisStack.head);
    }
    super.visitApply(tree);
}
 
Example #22
Source File: TreePosTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example #23
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** return access code for identifier,
 *  @param tree     The tree representing the identifier use.
 *  @param enclOp   The closest enclosing operation node of tree,
 *                  null if tree is not a subtree of an operation.
 */
private static int accessCode(JCTree tree, JCTree enclOp) {
    if (enclOp == null)
        return AccessCode.DEREF.code;
    else if (enclOp.hasTag(ASSIGN) &&
             tree == TreeInfo.skipParens(((JCAssign) enclOp).lhs))
        return AccessCode.ASSIGN.code;
    else if ((enclOp.getTag().isIncOrDecUnaryOp() || enclOp.getTag().isAssignop()) &&
            tree == TreeInfo.skipParens(((JCOperatorExpression) enclOp).getOperand(LEFT)))
        return (((JCOperatorExpression) enclOp).operator).getAccessCode(enclOp.getTag());
    else
        return AccessCode.DEREF.code;
}
 
Example #24
Source File: NBEnter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void visitTopLevel(JCTree.JCCompilationUnit tree) {
    if (TreeInfo.isModuleInfo(tree) && tree.modle == syms.noModule) {
        //workaround: when source level == 8, then visitTopLevel crashes for module-info.java
        return ;
    }
    super.visitTopLevel(tree);
}
 
Example #25
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
   public void visitApply(JCMethodInvocation tree) {
       int prevPrec = this.prec;
       this.prec = TreeInfo.postfixPrec;
       printMethodSelect(tree);
       this.prec = prevPrec;
print(cs.spaceBeforeMethodCallParen() ? " (" : "(");
       if (cs.spaceWithinMethodCallParens() && tree.args.nonEmpty())
           print(' ');
wrapTrees(tree.args, cs.wrapMethodCallArgs(), cs.alignMultilineCallArgs()
               ? out.col : out.leftMargin + cs.getContinuationIndentSize());
print(cs.spaceWithinMethodCallParens() && tree.args.nonEmpty() ? " )" : ")");
   }
 
Example #26
Source File: DPrinter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void printTree(String label, JCTree tree) {
    if (tree == null) {
        printNull(label);
    } else {
        indent();
        String ext;
        try {
            ext = tree.getKind().name();
        } catch (Throwable t) {
            ext = "n/a";
        }
        out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext));
        if (showPositions) {
            // We can always get start position, but to get end position
            // and/or line+offset, we would need a JCCompilationUnit
            out.print(" pos:" + tree.pos);
        }
        if (showTreeTypes && tree.type != null)
            out.print(" type:" + toString(tree.type));
        Symbol sym;
        if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null)
            out.print(" sym:" + toString(sym));
        out.println();

        indent(+1);
        if (showSrc) {
            indent();
            out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength));
        }
        tree.accept(treeVisitor);
        indent(-1);
    }
}
 
Example #27
Source File: ArgumentAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void visitNewClass(JCNewClass that) {
    if (TreeInfo.isDiamond(that)) {
        processArg(that, speculativeTree -> new ResolvedConstructorType(that, env, speculativeTree));
    } else {
        //not a poly expression, just call Attr
        setResult(that, attr.attribTree(that, env, attr.unknownExprInfo));
    }
}
 
Example #28
Source File: TestTrees.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void testElement(Trees trees, Element e) {
    trees.getClass();
    e.getClass();

    System.err.println("testElement: " + e);
    Tree tree = trees.getTree(e);
    //System.err.println(tree);

    if (TreeInfo.symbolFor((JCTree)tree) != e)
        error("bad result from getTree");

    TreePath path = trees.getPath(e);
    if (path == null) {
        error("getPath returned null");
        return;
    }
    if (path.getLeaf() != tree)
        error("bad result from getPath");

    Element e2 = trees.getElement(path);
    if (e2 == null) {
        error("getElement returned null");
        return;
    }
    if (e2 != e)
        error("bad result from getElement");

    // The TypeMirror is not available yet when annotation processing;
    // it is set up later during ANALYSE.
    TypeMirror t = trees.getTypeMirror(path);
    if (t != null && t.getKind() == TypeKind.DECLARED &&
            ((DeclaredType)t).asElement() != e2)
        error("bad result from getTypeMirror");

    for (AnnotationMirror m: e.getAnnotationMirrors()) {
        testAnnotation(trees, e, m);
    }
}
 
Example #29
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void checkAccessFromSerializableElement(final JCTree tree, boolean isLambda) {
    if (warnOnAnyAccessToMembers ||
        (lint.isEnabled(LintCategory.SERIAL) &&
        !lint.isSuppressed(LintCategory.SERIAL) &&
        isLambda)) {
        Symbol sym = TreeInfo.symbol(tree);
        if (!sym.kind.matches(KindSelector.VAL_MTH)) {
            return;
        }

        if (sym.kind == VAR) {
            if ((sym.flags() & PARAMETER) != 0 ||
                sym.isLocal() ||
                sym.name == names._this ||
                sym.name == names._super) {
                return;
            }
        }

        if (!types.isSubtype(sym.owner.type, syms.serializableType) &&
            isEffectivelyNonPublic(sym)) {
            if (isLambda) {
                if (belongsToRestrictedPackage(sym)) {
                    log.warning(LintCategory.SERIAL, tree.pos(),
                                Warnings.AccessToMemberFromSerializableLambda(sym));
                }
            } else {
                log.warning(tree.pos(),
                            Warnings.AccessToMemberFromSerializableElement(sym));
            }
        }
    }
}
 
Example #30
Source File: DPrinter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void printTree(String label, JCTree tree) {
    if (tree == null) {
        printNull(label);
    } else {
        indent();
        String ext;
        try {
            ext = tree.getKind().name();
        } catch (Throwable t) {
            ext = "n/a";
        }
        out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext));
        if (showPositions) {
            // We can always get start position, but to get end position
            // and/or line+offset, we would need a JCCompilationUnit
            out.print(" pos:" + tree.pos);
        }
        if (showTreeTypes && tree.type != null)
            out.print(" type:" + toString(tree.type));
        Symbol sym;
        if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null)
            out.print(" sym:" + toString(sym));
        out.println();

        indent(+1);
        if (showSrc) {
            indent();
            out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength));
        }
        tree.accept(treeVisitor);
        indent(-1);
    }
}