当前位置: 首页>>代码示例>>Java>>正文


Java TreeInfo.symbolFor方法代码示例

本文整理汇总了Java中com.sun.tools.javac.tree.TreeInfo.symbolFor方法的典型用法代码示例。如果您正苦于以下问题:Java TreeInfo.symbolFor方法的具体用法?Java TreeInfo.symbolFor怎么用?Java TreeInfo.symbolFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.tree.TreeInfo的用法示例。


在下文中一共展示了TreeInfo.symbolFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTree

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:JavacTrees.java

示例2: getElement

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
public Element getElement(TreePath path) {
    JCTree tree = (JCTree) path.getLeaf();
    Symbol sym = TreeInfo.symbolFor(tree);
    if (sym == null && TreeInfo.isDeclaration(tree)) {
        for (TreePath p = path; p != null; p = p.getParentPath()) {
            JCTree t = (JCTree) p.getLeaf();
            if (t.getTag() == JCTree.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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:21,代码来源:JavacTrees.java

示例3: getElement

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:JavacTrees.java

示例4: getElement

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public Symbol getElement(TreePath path) {
    JCTree tree = (JCTree) path.getLeaf();
    Symbol sym = TreeInfo.symbolFor(tree);
    if (sym == null) {
        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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:JavacTrees.java

示例5: getElement

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
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;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:24,代码来源:JavacTrees.java

示例6: isAnnotationProcessorExempt

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/**
 * Returns true if the compilation unit contains a single top-level class generated by an exempt
 * annotation processor (according to its {@link @Generated} annotation).
 *
 * <p>Annotation processors are expected to never generate more than one top level class, as
 * required by the style guide.
 */
public ProcessorDependencyMode isAnnotationProcessorExempt(JCTree.JCCompilationUnit unit) {
  if (unit.getTypeDecls().size() != 1) {
    return ProcessorDependencyMode.DEFAULT;
  }
  Symbol sym = TreeInfo.symbolFor(getOnlyElement(unit.getTypeDecls()));
  if (sym == null) {
    return ProcessorDependencyMode.DEFAULT;
  }
  for (String value : getGeneratedBy(sym)) {
    // Relax strict deps for dagger-generated code (b/17979436).
    if (value.startsWith(DAGGER_PROCESSOR_PREFIX)) {
      return ProcessorDependencyMode.EXEMPT_NORECORD;
    }
    if (dependencyModule.getExemptGenerators().contains(value)) {
      return ProcessorDependencyMode.EXEMPT_RECORD;
    }
  }
  return ProcessorDependencyMode.DEFAULT;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:27,代码来源:StrictJavaDepsPlugin.java

示例7: visitApply

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@Override
public void visitApply(JCMethodInvocation tree) {
    Symbol m = TreeInfo.symbolFor(tree);
    AssertOverloadKind ak = assertOverloadKind(m);
    if (ak != AssertOverloadKind.NONE &&
        !m.name.contentEquals("error")) {
        JCExpression lastParam = tree.args.last();
        if (isSimpleStringArg(lastParam) != ak.simpleArgExpected()) {
            messages.error(lastParam, ak.errKey);
        }
    }

    super.visitApply(tree);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:AssertCheckAnalyzer.java

示例8: isSimpleStringArg

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
boolean isSimpleStringArg(JCExpression e) {
    switch (e.getTag()) {
        case LAMBDA:
            JCLambda lambda = (JCLambda)e;
            return (lambda.getBodyKind() == BodyKind.EXPRESSION) &&
                    isSimpleStringArg((JCExpression)lambda.body);
        default:
            Symbol argSym = TreeInfo.symbolFor(e);
            return (e.type.constValue() != null ||
                    (argSym != null && argSym.kind == Kinds.Kind.VAR));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:AssertCheckAnalyzer.java

示例9: checkLegacyLogMethod

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
void checkLegacyLogMethod(JCMethodInvocation tree) {
    Symbol method = TreeInfo.symbolFor(tree);
    if (method == null ||
        method.kind != Kinds.Kind.MTH ||
        !typeToCheck(method.owner.type) ||
        !LEGACY_METHOD_NAMES.contains(method.name.toString()) ||
        !((MethodSymbol) method).isVarArgs() ||
        method.type.getParameterTypes().size() < 2) {
        return ;
    }
    JCExpression key = tree.args.get(method.type.getParameterTypes().size() - 2);
    if (key.hasTag(Tag.LITERAL)) {
        messages.error(tree, "crules.use.of.legacy.log.method", tree);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:LegacyLogMethodAnalyzer.java

示例10: testElement

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:TestTrees.java

示例11: printTree

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:DPrinter.java

示例12: getElement

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
public Element getElement(TreePath path) {
    Tree t = path.getLeaf();
    return TreeInfo.symbolFor((JCTree) t);
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:5,代码来源:JavacTrees.java

示例13: visitTry

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
public void visitTry(JCTry tree) {
    // Create a new local environment with a local
    Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup()));
    boolean isTryWithResource = tree.resources.nonEmpty();
    // Create a nested environment for attributing the try block if needed
    Env<AttrContext> tryEnv = isTryWithResource ?
        env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) :
        localEnv;
    // Attribute resource declarations
    for (JCTree resource : tree.resources) {
        if (resource.getTag() == JCTree.VARDEF) {
            attribStat(resource, tryEnv);
            chk.checkType(resource, resource.type, syms.autoCloseableType, "try.not.applicable.to.type");

            //check that resource type cannot throw InterruptedException
            checkAutoCloseable(resource.pos(), localEnv, resource.type);

            VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource);
            var.setData(ElementKind.RESOURCE_VARIABLE);
        } else {
            attribExpr(resource, tryEnv, syms.autoCloseableType, "try.not.applicable.to.type");
        }
    }
    // Attribute body
    attribStat(tree.body, tryEnv);
    if (isTryWithResource)
        tryEnv.info.scope.leave();

    // Attribute catch clauses
    for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
        JCCatch c = l.head;
        Env<AttrContext> catchEnv =
            localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup()));
        Type ctype = attribStat(c.param, catchEnv);
        if (TreeInfo.isMultiCatch(c)) {
            //multi-catch parameter is implicitly marked as final
            c.param.sym.flags_field |= FINAL | UNION;
        }
        if (c.param.sym.kind == Kinds.VAR) {
            c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
        }
        chk.checkType(c.param.vartype.pos(),
                      chk.checkClassType(c.param.vartype.pos(), ctype),
                      syms.throwableType);
        attribStat(c.body, catchEnv);
        catchEnv.info.scope.leave();
    }

    // Attribute finalizer
    if (tree.finalizer != null) attribStat(tree.finalizer, localEnv);

    localEnv.info.scope.leave();
    result = null;
}
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:55,代码来源:Attr.java

示例14: symbol

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/**
 * Gets the {@link Element} ("symbol") for the given Tree API node.
 *
 * @param tree the {@link Tree} node to get the symbol for
 * @throws IllegalArgumentException
 *         if {@code tree} is null or is not a valid javac-internal tree
 *         (JCTree)
 * @return the {@code {@link Symbol}} for the given tree, or null if one
 *         could not be found
 */
public static /*@Nullable*/ Element symbol(Tree tree) {
    if (tree == null) {
        ErrorReporter.errorAbort("InternalUtils.symbol: tree is null");
        return null; // dead code
    }

    if (!(tree instanceof JCTree)) {
        ErrorReporter.errorAbort("InternalUtils.symbol: tree is not a valid Javac tree");
        return null; // dead code
    }

    if (TreeUtils.isExpressionTree(tree)) {
        tree = TreeUtils.skipParens((ExpressionTree) tree);
    }

    switch (tree.getKind()) {
        case VARIABLE:
        case METHOD:
        case CLASS:
        case ENUM:
        case INTERFACE:
        case ANNOTATION_TYPE:
        case TYPE_PARAMETER:
            return TreeInfo.symbolFor((JCTree) tree);

        // symbol() only works on MethodSelects, so we need to get it manually
        // for method invocations.
        case METHOD_INVOCATION:
            return TreeInfo.symbol(((JCMethodInvocation) tree).getMethodSelect());

        case ASSIGNMENT:
            return TreeInfo.symbol((JCTree)((AssignmentTree)tree).getVariable());

        case ARRAY_ACCESS:
            return symbol(((ArrayAccessTree)tree).getExpression());

        case NEW_CLASS:
            return ((JCNewClass)tree).constructor;

        default:
            return TreeInfo.symbol((JCTree) tree);
    }
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:54,代码来源:InternalUtils.java

示例15: symbol

import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/**
 * Gets the {@link Element} ("symbol") for the given Tree API node.
 *
 * @param tree the {@link Tree} node to get the symbol for
 * @throws IllegalArgumentException if {@code tree} is null or is not a valid javac-internal
 *     tree (JCTree)
 * @return the {@link Symbol} for the given tree, or null if one could not be found
 */
public static /*@Nullable*/ Element symbol(Tree tree) {
    if (tree == null) {
        ErrorReporter.errorAbort("InternalUtils.symbol: tree is null");
        return null; // dead code
    }

    if (!(tree instanceof JCTree)) {
        ErrorReporter.errorAbort("InternalUtils.symbol: tree is not a valid Javac tree");
        return null; // dead code
    }

    if (TreeUtils.isExpressionTree(tree)) {
        tree = TreeUtils.skipParens((ExpressionTree) tree);
    }

    switch (tree.getKind()) {
        case VARIABLE:
        case METHOD:
        case CLASS:
        case ENUM:
        case INTERFACE:
        case ANNOTATION_TYPE:
        case TYPE_PARAMETER:
            return TreeInfo.symbolFor((JCTree) tree);

            // symbol() only works on MethodSelects, so we need to get it manually
            // for method invocations.
        case METHOD_INVOCATION:
            return TreeInfo.symbol(((JCMethodInvocation) tree).getMethodSelect());

        case ASSIGNMENT:
            return TreeInfo.symbol((JCTree) ((AssignmentTree) tree).getVariable());

        case ARRAY_ACCESS:
            return symbol(((ArrayAccessTree) tree).getExpression());

        case NEW_CLASS:
            return ((JCNewClass) tree).constructor;

        case MEMBER_REFERENCE:
            // TreeInfo.symbol, which is used in the default case, didn't handle
            // member references until JDK8u20. So handle it here.
            return ((JCMemberReference) tree).sym;

        default:
            return TreeInfo.symbol((JCTree) tree);
    }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:57,代码来源:InternalUtils.java


注:本文中的com.sun.tools.javac.tree.TreeInfo.symbolFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。