本文整理汇总了Java中com.sun.tools.javac.tree.TreeInfo类的典型用法代码示例。如果您正苦于以下问题:Java TreeInfo类的具体用法?Java TreeInfo怎么用?Java TreeInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TreeInfo类属于com.sun.tools.javac.tree包,在下文中一共展示了TreeInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: VeryPretty
import com.sun.tools.javac.tree.TreeInfo; //导入依赖的package包/类
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);
}
示例2: 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;
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: copyEnvIfNeeded
import com.sun.tools.javac.tree.TreeInfo; //导入依赖的package包/类
/**
* Create a copy of Env if needed.
*/
Env<AttrContext> copyEnvIfNeeded(JCTree tree, Env<AttrContext> env) {
if (!analyzerModes.isEmpty() &&
!env.info.isSpeculative &&
TreeInfo.isStatement(tree) &&
!tree.hasTag(LABELLED)) {
Env<AttrContext> analyzeEnv =
env.dup(env.tree, env.info.dup(env.info.scope.dupUnshared(env.info.scope.owner)));
analyzeEnv.info.returnResult = analyzeEnv.info.returnResult != null ?
attr.new ResultInfo(analyzeEnv.info.returnResult.pkind,
analyzeEnv.info.returnResult.pt) : null;
return analyzeEnv;
} else {
return null;
}
}
示例8: 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));
}
}
}
示例9: getAnnotationClassValue
import com.sun.tools.javac.tree.TreeInfo; //导入依赖的package包/类
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(), Errors.AnnotationValueMustBeClassLiteral);
return new Attribute.Error(syms.errType);
}
return new Attribute.Class(types,
(((JCFieldAccess) tree).selected).type);
}
示例10: getModuleName
import com.sun.tools.javac.tree.TreeInfo; //导入依赖的package包/类
private String getModuleName(Location location) throws ToolException {
try {
JavaFileObject jfo = fm.getJavaFileForInput(location,
"module-info", JavaFileObject.Kind.SOURCE);
if (jfo != null) {
JCCompilationUnit jcu = compiler.parse(jfo);
JCModuleDecl module = TreeInfo.getModule(jcu);
if (module != null) {
return module.getName().toString();
}
}
} catch (IOException ioe) {
String text = messager.getText("main.file.manager.list", location);
throw new ToolException(SYSERR, text, ioe);
}
return null;
}
示例11: translateTopLevelClass
import com.sun.tools.javac.tree.TreeInfo; //导入依赖的package包/类
@Override
public List<JCTree> translateTopLevelClass(Env<AttrContext> env, JCTree cdef, TreeMaker make) {
List<JCTree> result = super.translateTopLevelClass(env, cdef, make);
new TreeScanner() {
@Override
public void visitBinary(JCBinary tree) {
hasNullCheck |= tree.operator.getSimpleName().contentEquals("!=") &&
"resource".equals(String.valueOf(TreeInfo.name(tree.lhs))) &&
TreeInfo.isNull(tree.rhs);
super.visitBinary(tree);
}
}.scan(result);
return result;
}
示例12: 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;
}
示例13: 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);
}
}
示例14: getAnnotationClassValue
import com.sun.tools.javac.tree.TreeInfo; //导入依赖的package包/类
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);
}
示例15: suggestFixForSameReference
import com.sun.tools.javac.tree.TreeInfo; //导入依赖的package包/类
/** Handles the case "expr1 == expr2" */
private static void suggestFixForSameReference(
SuggestedFix.Builder fix, AssertTree foundAssert, VisitorState state, boolean isEqual) {
BinaryTree equalityTree = (BinaryTree) TreeInfo.skipParens((JCTree) foundAssert.getCondition());
ExpressionTree expr1 = equalityTree.getLeftOperand();
ExpressionTree expr2 = equalityTree.getRightOperand();
if (expr1.getKind() == NULL_LITERAL) {
// case: "assert null [op] expr"
addFix(fix, (JCExpression) expr2, foundAssert, state, isEqual ? IS_NULL : IS_NOT_NULL);
} else if (expr2.getKind() == NULL_LITERAL) {
// case: "assert expr [op] null"
addFix(fix, (JCExpression) expr1, foundAssert, state, isEqual ? IS_NULL : IS_NOT_NULL);
} else {
// case: "assert expr1 [op] expr2"
addFix(
fix,
(JCExpression) expr1,
foundAssert,
state,
String.format(isEqual ? IS_SAME_AS : IS_NOT_SAME_AS, expr2));
}
}