Java Code Examples for com.sun.tools.javac.tree.JCTree#hasTag()

The following examples show how to use com.sun.tools.javac.tree.JCTree#hasTag() . 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: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Check for cycles in the graph of annotation elements.
 */
void checkNonCyclicElements(JCClassDecl tree) {
    if ((tree.sym.flags_field & ANNOTATION) == 0) return;
    Assert.check((tree.sym.flags_field & LOCKED) == 0);
    try {
        tree.sym.flags_field |= LOCKED;
        for (JCTree def : tree.defs) {
            if (!def.hasTag(METHODDEF)) continue;
            JCMethodDecl meth = (JCMethodDecl)def;
            checkAnnotationResType(meth.pos(), meth.restype.type);
        }
    } finally {
        tree.sym.flags_field &= ~LOCKED;
        tree.sym.flags_field |= ACYCLIC_ANN;
    }
}
 
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-8-source 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 4
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void scan(JCTree tree) {
    if (tree != null) {
        for (StatementAnalyzer<JCTree, JCTree> analyzer : analyzers) {
            if (analyzer.isEnabled() &&
                    tree.hasTag(analyzer.tag) &&
                    analyzer.match(tree)) {
                for (JCTree t : analyzer.rewrite(tree)) {
                    rewritings.add(new RewritingContext(originalTree, tree, t, analyzer, env));
                }
                break; //TODO: cover cases where multiple matching analyzers are found
            }
        }
    }
    super.scan(tree);
}
 
Example 5
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Do we need an access method to reference symbol in other package?
 */
boolean needsProtectedAccess(Symbol sym, JCTree tree) {
    if ((sym.flags() & PROTECTED) == 0 ||
        sym.owner.owner == currentClass.owner || // fast special case
        sym.packge() == currentClass.packge())
        return false;
    if (!currentClass.isSubClass(sym.owner, types))
        return true;
    if ((sym.flags() & STATIC) != 0 ||
        !tree.hasTag(SELECT) ||
        TreeInfo.name(((JCFieldAccess) tree).selected) == names._super)
        return false;
    return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types);
}
 
Example 6
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitSelect(JCFieldAccess tree) {
    super.visitSelect(tree);
    JCTree sel = TreeInfo.skipParens(tree.selected);
    if (enforceThisDotInit &&
            sel.hasTag(IDENT) &&
            ((JCIdent)sel).name == names._this &&
            tree.sym.kind == VAR) {
        checkInit(tree.pos(), (VarSymbol)tree.sym);
    }
}
 
Example 7
Source File: JavadocTool.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * From a list of top level trees, return the list of contained class definitions
 */
List<JCClassDecl> listClasses(List<JCCompilationUnit> trees) {
    ListBuffer<JCClassDecl> result = new ListBuffer<JCClassDecl>();
    for (JCCompilationUnit t : trees) {
        for (JCTree def : t.defs) {
            if (def.hasTag(JCTree.Tag.CLASSDEF))
                result.append((JCClassDecl)def);
        }
    }
    return result.toList();
}
 
Example 8
Source File: StringConcat.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private List<JCTree> collect(JCTree tree, List<JCTree> res) {
    tree = TreeInfo.skipParens(tree);
    if (tree.hasTag(PLUS) && tree.type.constValue() == null) {
        JCTree.JCBinary op = (JCTree.JCBinary) tree;
        if (op.operator.kind == MTH && op.operator.opcode == string_add) {
            return res
                    .appendList(collect(op.lhs, res))
                    .appendList(collect(op.rhs, res));
        }
    }
    return res.append(tree);
}
 
Example 9
Source File: JavadocTool.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * From a list of top level trees, return the list of contained class definitions
 */
List<JCClassDecl> listClasses(List<JCCompilationUnit> trees) {
    ListBuffer<JCClassDecl> result = new ListBuffer<JCClassDecl>();
    for (JCCompilationUnit t : trees) {
        for (JCTree def : t.defs) {
            if (def.hasTag(JCTree.Tag.CLASSDEF))
                result.append((JCClassDecl)def);
        }
    }
    return result.toList();
}
 
Example 10
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean isCanonical(JCTree tree) {
    while (tree.hasTag(SELECT)) {
        JCFieldAccess s = (JCFieldAccess) tree;
        if (s.sym.owner.getQualifiedName() != TreeInfo.symbol(s.selected).getQualifiedName())
            return false;
        tree = s.selected;
    }
    return true;
}
 
Example 11
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean isIdentOrThisDotIdent(JCTree lhs) {
    if (lhs.hasTag(IDENT))
        return true;
    if (!lhs.hasTag(SELECT))
        return false;

    JCFieldAccess fa = (JCFieldAccess)lhs;
    return fa.selected.hasTag(IDENT) &&
           ((JCIdent)fa.selected).name == names._this;
}
 
Example 12
Source File: JavadocTool.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * From a list of top level trees, return the list of contained class definitions
 */
List<JCClassDecl> listClasses(List<JCCompilationUnit> trees) {
    ListBuffer<JCClassDecl> result = new ListBuffer<>();
    for (JCCompilationUnit t : trees) {
        for (JCTree def : t.defs) {
            if (def.hasTag(JCTree.Tag.CLASSDEF))
                result.append((JCClassDecl)def);
        }
    }
    return result.toList();
}
 
Example 13
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** If tree is either a simple name or of the form this.name or
 *  C.this.name, and tree represents a trackable variable,
 *  record an initialization of the variable.
 */
void letInit(JCTree tree) {
    tree = TreeInfo.skipParens(tree);
    if (tree.hasTag(IDENT) || tree.hasTag(SELECT)) {
        Symbol sym = TreeInfo.symbol(tree);
        if (sym.kind == VAR) {
            letInit(tree.pos(), (VarSymbol)sym);
        }
    }
}
 
Example 14
Source File: JavadocTool.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * From a list of top level trees, return the list of contained class definitions
 */
List<JCClassDecl> listClasses(List<JCCompilationUnit> trees) {
    ListBuffer<JCClassDecl> result = new ListBuffer<JCClassDecl>();
    for (JCCompilationUnit t : trees) {
        for (JCTree def : t.defs) {
            if (def.hasTag(JCTree.Tag.CLASSDEF))
                result.append((JCClassDecl)def);
        }
    }
    return result.toList();
}
 
Example 15
Source File: TreePosTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isAnnotatedArray(JCTree tree) {
    return tree.hasTag(ANNOTATED_TYPE) &&
                    ((JCAnnotatedType)tree).underlyingType.hasTag(TYPEARRAY);
}
 
Example 16
Source File: TreePosTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isAnnotatedArray(JCTree tree) {
    return tree.hasTag(ANNOTATED_TYPE) &&
                    ((JCAnnotatedType)tree).underlyingType.hasTag(TYPEARRAY);
}
 
Example 17
Source File: CheckAttributedTree.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private boolean mandatoryType(JCTree that) {
    return that instanceof JCTree.JCExpression ||
            that.hasTag(VARDEF) ||
            that.hasTag(METHODDEF) ||
            that.hasTag(CLASSDEF);
}
 
Example 18
Source File: CheckAttributedTree.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private boolean mandatoryType(JCTree that) {
    return that instanceof JCTree.JCExpression ||
            that.hasTag(VARDEF) ||
            that.hasTag(METHODDEF) ||
            that.hasTag(CLASSDEF);
}
 
Example 19
Source File: CheckAttributedTree.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean mandatoryType(JCTree that) {
    return that instanceof JCTree.JCExpression ||
            that.hasTag(VARDEF) ||
            that.hasTag(METHODDEF) ||
            that.hasTag(CLASSDEF);
}
 
Example 20
Source File: TreePosTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isAnnotatedArray(JCTree tree) {
    return tree.hasTag(ANNOTATED_TYPE) &&
                    ((JCAnnotatedType)tree).underlyingType.hasTag(TYPEARRAY);
}