Java Code Examples for com.sun.tools.javac.tree.TreeInfo#name()
The following examples show how to use
com.sun.tools.javac.tree.TreeInfo#name() .
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 |
/** Check for cycles in the graph of constructors calling other * constructors. */ void checkCyclicConstructors(JCClassDecl tree) { Map<Symbol,Symbol> callMap = new HashMap<>(); // enter each constructor this-call into the map for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { JCMethodInvocation app = TreeInfo.firstConstructorCall(l.head); if (app == null) continue; JCMethodDecl meth = (JCMethodDecl) l.head; if (TreeInfo.name(app.meth) == names._this) { callMap.put(meth.sym, TreeInfo.symbol(app.meth)); } else { meth.sym.flags_field |= ACYCLIC; } } // Check for cycles in the map Symbol[] ctors = new Symbol[0]; ctors = callMap.keySet().toArray(ctors); for (Symbol caller : ctors) { checkCyclicConstructor(tree, caller, callMap); } }
Example 2
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 3
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 4
Source File: Annotate.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private Attribute getAnnotationClassValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) { Type result = attr.attribTree(tree, env, annotationValueInfo(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); }
Example 5
Source File: PostFlowAnalysis.java From netbeans with Apache License 2.0 | 6 votes |
@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; } }
Example 6
Source File: Annotate.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 7
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** 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) { addFreeVars((ClassSymbol) TreeInfo.symbol(tree.meth).owner); } super.visitApply(tree); }
Example 8
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** 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 9
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** 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 10
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Construct an expression using the builder, with the given rval * expression as an argument to the builder. However, the rval * expression must be computed only once, even if used multiple * times in the result of the builder. We do that by * constructing a "let" expression that saves the rvalue into a * temporary variable and then uses the temporary variable in * place of the expression built by the builder. The complete * resulting expression is of the form * <pre> * (let <b>TYPE</b> <b>TEMP</b> = <b>RVAL</b>; * in (<b>BUILDER</b>(<b>TEMP</b>))) * </pre> * where <code><b>TEMP</b></code> is a newly declared variable * in the let expression. */ JCExpression abstractRval(JCExpression rval, Type type, TreeBuilder builder) { rval = TreeInfo.skipParens(rval); switch (rval.getTag()) { case LITERAL: return builder.build(rval); case IDENT: JCIdent id = (JCIdent) rval; if ((id.sym.flags() & FINAL) != 0 && id.sym.owner.kind == MTH) return builder.build(rval); } Name name = TreeInfo.name(rval); if (name == names._super || name == names._this) return builder.build(rval); VarSymbol var = new VarSymbol(FINAL|SYNTHETIC, names.fromString( target.syntheticNameChar() + "" + rval.hashCode()), type, currentMethodSym); rval = convert(rval,type); JCVariableDecl def = make.VarDef(var, rval); // XXX cast JCExpression built = builder.build(make.Ident(var)); JCExpression res = make.LetExpr(def, built); res.type = built.type; return res; }
Example 11
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitApply(JCMethodInvocation tree) { List<ClassSymbol> previousNascentTypes = typesUnderConstruction; try { Name methName = TreeInfo.name(tree.meth); if (methName == names._this || methName == names._super) { typesUnderConstruction = typesUnderConstruction.prepend(currentClass()); } super.visitApply(tree); } finally { typesUnderConstruction = previousNascentTypes; } }
Example 12
Source File: TypeEnter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void doImport(JCImport tree) { JCFieldAccess imp = (JCFieldAccess)tree.qualid; Name name = TreeInfo.name(imp); // Create a local environment pointing to this tree to disable // effects of other imports in Resolve.findGlobalType Env<AttrContext> localEnv = env.dup(tree); TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym; if (name == names.asterisk) { // Import on demand. chk.checkCanonical(imp.selected); if (tree.staticImport) importStaticAll(tree, p, env); else importAll(tree, p, env); } else { // Named type import. if (tree.staticImport) { importNamedStatic(tree, p, name, localEnv); chk.checkCanonical(imp.selected); } else { Type importedType = attribImportType(imp, localEnv); Type originalType = importedType.getOriginalType(); TypeSymbol c = originalType.hasTag(CLASS) ? originalType.tsym : importedType.tsym; chk.checkCanonical(imp); importNamed(tree.pos(), c, env, tree); } } }
Example 13
Source File: PrettyCommentsPrinter.java From EasyMPermission with MIT License | 5 votes |
/** Print unit consisting of package clause and import statements in toplevel, * followed by class definition. if class definition == null, * print all definitions in toplevel. * @param tree The toplevel tree * @param cdef The class definition, which is assumed to be part of the * toplevel tree. */ public void printUnit(JCCompilationUnit tree, JCClassDecl cdef) throws IOException { Object dc = getDocComments(tree); loadDocCommentsTable(dc); printDocComment(tree); if (tree.pid != null) { consumeComments(tree.pos, tree); print("package "); printExpr(tree.pid); print(";"); println(); } boolean firstImport = true; for (List<JCTree> l = tree.defs; l.nonEmpty() && (cdef == null || IMPORT.equals(treeTag(l.head))); l = l.tail) { if (IMPORT.equals(treeTag(l.head))) { JCImport imp = (JCImport)l.head; Name name = TreeInfo.name(imp.qualid); if (name == name.table.fromChars(new char[] {'*'}, 0, 1) || cdef == null || isUsed(TreeInfo.symbol(imp.qualid), cdef)) { if (firstImport) { firstImport = false; println(); } printStat(imp); } } else { printStat(l.head); } } if (cdef != null) { printStat(cdef); println(); } }
Example 14
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void visitApply(JCMethodInvocation tree) { Symbol meth = TreeInfo.symbol(tree.meth); List<Type> argtypes = meth.type.getParameterTypes(); if (meth.name == names.init && meth.owner == syms.enumSym) argtypes = argtypes.tail.tail; tree.args = boxArgs(argtypes, tree.args, tree.varargsElement); tree.varargsElement = null; Name methName = TreeInfo.name(tree.meth); if (meth.name==names.init) { // We are seeing a this(...) or super(...) constructor call. // If an access constructor is used, append null as a last argument. Symbol constructor = accessConstructor(tree.pos(), meth); if (constructor != meth) { tree.args = tree.args.append(makeNull()); TreeInfo.setSymbol(tree.meth, constructor); } // If we are calling a constructor of a local class, add // free variables after explicit constructor arguments. ClassSymbol c = (ClassSymbol)constructor.owner; if (c.isLocal()) { tree.args = tree.args.appendList(loadFreevars(tree.pos(), freevars(c))); } // If we are calling a constructor of an enum class, pass // along the name and ordinal arguments if ((c.flags_field&ENUM) != 0 || c.getQualifiedName() == names.java_lang_Enum) { List<JCVariableDecl> params = currentMethodDef.params; if (currentMethodSym.owner.hasOuterInstance()) params = params.tail; // drop this$n tree.args = tree.args .prepend(make_at(tree.pos()).Ident(params.tail.head.sym)) // ordinal .prepend(make.Ident(params.head.sym)); // name } // If we are calling a constructor of a class with an outer // instance, and the call // is qualified, pass qualifier as first argument in front of // the explicit constructor arguments. If the call // is not qualified, pass the correct outer instance as // first argument. if (c.hasOuterInstance()) { JCExpression thisArg; if (tree.meth.hasTag(SELECT)) { thisArg = attr. makeNullCheck(translate(((JCFieldAccess) tree.meth).selected)); tree.meth = make.Ident(constructor); ((JCIdent) tree.meth).name = methName; } else if (c.isLocal() || methName == names._this){ // local class or this() call thisArg = makeThis(tree.meth.pos(), c.type.getEnclosingType().tsym); } else { // super() call of nested class - never pick 'this' thisArg = makeOwnerThisN(tree.meth.pos(), c, false); } tree.args = tree.args.prepend(thisArg); } } else { // We are seeing a normal method invocation; translate this as usual. tree.meth = translate(tree.meth); // If the translated method itself is an Apply tree, we are // seeing an access method invocation. In this case, append // the method arguments to the arguments of the access method. if (tree.meth.hasTag(APPLY)) { JCMethodInvocation app = (JCMethodInvocation)tree.meth; app.args = tree.args.prependList(app.args); result = app; return; } } result = tree; }