本文整理汇总了Java中com.sun.tools.javac.tree.TreeInfo.symbol方法的典型用法代码示例。如果您正苦于以下问题:Java TreeInfo.symbol方法的具体用法?Java TreeInfo.symbol怎么用?Java TreeInfo.symbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.tree.TreeInfo
的用法示例。
在下文中一共展示了TreeInfo.symbol方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitApply
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@Override
public void visitApply(JCMethodInvocation tree) {
boolean prevCheckThis = checkThis;
try {
Symbol meth = TreeInfo.symbol(tree.meth);
Name methName = TreeInfo.name(tree.meth);
if (meth != null && meth.name == names.init) {
Symbol c = meth.owner;
if (c.hasOuterInstance()) {
checkThis = false;
if (tree.meth.getTag() != JCTree.Tag.SELECT && (c.isLocal() || methName == names._this)) {
checkThis(tree.meth.pos(), c.type.getEnclosingType().tsym);
}
}
}
super.visitApply(tree);
} finally {
checkThis = prevCheckThis;
}
}
示例2: visitUses
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@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));
}
}
}
示例3: visitUses
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@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;
Directive.UsesDirective d = new Directive.UsesDirective(service);
if (!allUses.add(d)) {
log.error(tree.pos(), Errors.DuplicateUses(service));
}
msym.uses = msym.uses.prepend(d);
msym.directives = msym.directives.prepend(d);
}
}
示例4: getAnnotationEnumValue
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
private Attribute getAnnotationEnumValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
Type result = attr.attribExpr(tree, env, expectedElementType);
Symbol sym = TreeInfo.symbol(tree);
if (sym == null ||
TreeInfo.nonstaticSelect(tree) ||
sym.kind != VAR ||
(sym.flags() & Flags.ENUM) == 0) {
log.error(tree.pos(), Errors.EnumAnnotationMustBeEnumConstant);
return new Attribute.Error(result.getOriginalType());
}
VarSymbol enumerator = (VarSymbol) sym;
return new Attribute.Enum(expectedElementType, enumerator);
}
示例5: visitReference
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@Override
public void visitReference(JCMemberReference tree) {
//perform arity-based check
Env<AttrContext> localEnv = env.dup(tree);
JCExpression exprTree = (JCExpression)deferredAttr.attribSpeculative(tree.getQualifierExpression(), localEnv,
attr.memberReferenceQualifierResult(tree));
JCMemberReference mref2 = new TreeCopier<Void>(attr.make).copy(tree);
mref2.expr = exprTree;
Symbol lhsSym = TreeInfo.symbol(exprTree);
localEnv.info.selectSuper = lhsSym != null && lhsSym.name == lhsSym.name.table.names._super;
Symbol res =
attr.rs.getMemberReference(tree, localEnv, mref2,
exprTree.type, tree.name);
if (!res.kind.isResolutionError()) {
tree.sym = res;
}
if (res.kind.isResolutionTargetError() ||
res.type != null && res.type.hasTag(FORALL) ||
(res.flags() & Flags.VARARGS) != 0 ||
(TreeInfo.isStaticSelector(exprTree, tree.name.table.names) &&
exprTree.type.isRaw() && !exprTree.type.hasTag(ARRAY))) {
tree.overloadKind = JCMemberReference.OverloadKind.OVERLOADED;
} else {
tree.overloadKind = JCMemberReference.OverloadKind.UNOVERLOADED;
}
//return a plain old deferred type for this
setResult(tree, deferredAttr.new DeferredType(tree, env));
}
示例6: getAnnotationEnumValue
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
private Attribute getAnnotationEnumValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
Type result = attr.attribExpr(tree, env, expectedElementType);
Symbol sym = TreeInfo.symbol(tree);
if (sym == null ||
TreeInfo.nonstaticSelect(tree) ||
sym.kind != VAR ||
(sym.flags() & Flags.ENUM) == 0) {
log.error(tree.pos(), "enum.annotation.must.be.enum.constant");
return new Attribute.Error(result.getOriginalType());
}
VarSymbol enumerator = (VarSymbol) sym;
return new Attribute.Enum(expectedElementType, enumerator);
}
示例7: isStaticReference
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/** Does tree represent a static reference to an identifier?
* It is assumed that tree is either a SELECT or an IDENT.
* We have to weed out selects from non-type names here.
* @param tree The candidate tree.
*/
boolean isStaticReference(JCTree tree) {
if (tree.getTag() == JCTree.SELECT) {
Symbol lsym = TreeInfo.symbol(((JCFieldAccess) tree).selected);
if (lsym == null || lsym.kind != TYP) {
return false;
}
}
return true;
}
示例8: visitParens
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
public void visitParens(JCParens tree) {
Type owntype = attribTree(tree.expr, env, pkind, pt);
result = check(tree, owntype, pkind, pkind, pt);
Symbol sym = TreeInfo.symbol(tree);
if (sym != null && (sym.kind&(TYP|PCK)) != 0)
log.error(tree.pos(), "illegal.start.of.type");
}
示例9: connectSubType
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
private void connectSubType(TreePath path, Tree superTree, Node baseClassNode, RelationTypes r) {
JCTree jcTree = (JCTree) superTree;
if (jcTree != null) {
Symbol s = TreeInfo.symbol(jcTree);
Tree superClassTree = trees.getTree(s);
if (superClassTree == null) {
String typeStr = s.toString();
Node classType = null;
if (classTypeCache.containsKey(typeStr)) {
classType = classTypeCache.get(typeStr);
} else {
classType = graphDb.createNode();
classType.setProperty("nodeType", "ClassType");
classType.setProperty("fullyQualifiedName", typeStr);
classTypeCache.put(typeStr, classType);
}
baseClassNode.createRelationshipTo(classType, r);
} else if (superClassTree.getKind() == Kind.CLASS || superClassTree.getKind() == Kind.INTERFACE) {
if (treeToNodeCache.containsKey(superClassTree)) {
Node superTypeNode = treeToNodeCache.get(superClassTree);
baseClassNode.createRelationshipTo(superTypeNode, r);
} else {
Pair<Node, RelationTypes> todoTuple = Pair.create(baseClassNode, r);
todo.put(superClassTree, todoTuple);
}
}
}
}
示例10: 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);
}
}
示例11: 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);
}
}