Java Code Examples for com.sun.tools.javac.tree.TreeInfo#isInitialConstructor()
The following examples show how to use
com.sun.tools.javac.tree.TreeInfo#isInitialConstructor() .
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: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/************************************************************************* * Visitor methods for statements and definitions *************************************************************************/ /* ------------ Visitor methods for various sorts of trees -------------*/ public void visitClassDef(JCClassDecl tree) { if (tree.sym == null) return; JCClassDecl classDefPrev = classDef; List<Type> thrownPrev = thrown; List<Type> caughtPrev = caught; ListBuffer<FlowPendingExit> pendingExitsPrev = pendingExits; Lint lintPrev = lint; boolean anonymousClass = tree.name == names.empty; pendingExits = new ListBuffer<>(); if (!anonymousClass) { caught = List.nil(); } classDef = tree; thrown = List.nil(); lint = lint.augment(tree.sym); try { // process all the static initializers for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { if (!l.head.hasTag(METHODDEF) && (TreeInfo.flags(l.head) & STATIC) != 0) { scan(l.head); errorUncaught(); } } // add intersection of all thrown clauses of initial constructors // to set of caught exceptions, unless class is anonymous. if (!anonymousClass) { boolean firstConstructor = true; for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { if (TreeInfo.isInitialConstructor(l.head)) { List<Type> mthrown = ((JCMethodDecl) l.head).sym.type.getThrownTypes(); if (firstConstructor) { caught = mthrown; firstConstructor = false; } else { caught = chk.intersect(mthrown, caught); } } } } // process all the instance initializers for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { if (!l.head.hasTag(METHODDEF) && (TreeInfo.flags(l.head) & STATIC) == 0) { scan(l.head); errorUncaught(); } } // in an anonymous class, add the set of thrown exceptions to // the throws clause of the synthetic constructor and propagate // outwards. // Changing the throws clause on the fly is okay here because // the anonymous constructor can't be invoked anywhere else, // and its type hasn't been cached. if (anonymousClass) { for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { if (TreeInfo.isConstructor(l.head)) { JCMethodDecl mdef = (JCMethodDecl)l.head; scan(mdef); mdef.thrown = make.Types(thrown); mdef.sym.type = types.createMethodTypeWithThrown(mdef.sym.type, thrown); } } thrownPrev = chk.union(thrown, thrownPrev); } // process all the methods for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { if (anonymousClass && TreeInfo.isConstructor(l.head)) continue; // there can never be an uncaught exception. if (l.head.hasTag(METHODDEF)) { scan(l.head); errorUncaught(); } } thrown = thrownPrev; } finally { pendingExits = pendingExitsPrev; caught = caughtPrev; classDef = classDefPrev; lint = lintPrev; } }
Example 2
Source File: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void visitMethodDef(JCMethodDecl tree) { if (tree.body == null) return; List<Type> caughtPrev = caught; List<Type> mthrown = tree.sym.type.getThrownTypes(); Lint lintPrev = lint; lint = lint.augment(tree.sym); Assert.check(pendingExits.isEmpty()); try { for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { JCVariableDecl def = l.head; scan(def); } if (TreeInfo.isInitialConstructor(tree)) caught = chk.union(caught, mthrown); else if ((tree.sym.flags() & (BLOCK | STATIC)) != BLOCK) caught = mthrown; // else we are in an instance initializer block; // leave caught unchanged. scan(tree.body); List<FlowPendingExit> exits = pendingExits.toList(); pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { FlowPendingExit exit = exits.head; exits = exits.tail; if (exit.thrown == null) { Assert.check(exit.tree.hasTag(RETURN)); } else { // uncaught throws will be reported later pendingExits.append(exit); } } } finally { caught = caughtPrev; lint = lintPrev; } }
Example 3
Source File: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void visitMethodDef(JCMethodDecl tree) { if (tree.body == null) { return; } /* MemberEnter can generate synthetic methods ignore them */ if ((tree.sym.flags() & SYNTHETIC) != 0) { return; } Lint lintPrev = lint; lint = lint.augment(tree.sym); try { if (tree.body == null) { return; } /* Ignore synthetic methods, except for translated lambda methods. */ if ((tree.sym.flags() & (SYNTHETIC | LAMBDA_METHOD)) == SYNTHETIC) { return; } final Bits initsPrev = new Bits(inits); final Bits uninitsPrev = new Bits(uninits); int nextadrPrev = nextadr; int firstadrPrev = firstadr; int returnadrPrev = returnadr; Assert.check(pendingExits.isEmpty()); boolean lastInitialConstructor = isInitialConstructor; try { isInitialConstructor = TreeInfo.isInitialConstructor(tree); if (!isInitialConstructor) { firstadr = nextadr; } for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { JCVariableDecl def = l.head; scan(def); Assert.check((def.sym.flags() & PARAMETER) != 0, "Method parameter without PARAMETER flag"); /* If we are executing the code from Gen, then there can be * synthetic or mandated variables, ignore them. */ initParam(def); } // else we are in an instance initializer block; // leave caught unchanged. scan(tree.body); if (isInitialConstructor) { boolean isSynthesized = (tree.sym.flags() & GENERATEDCONSTR) != 0; for (int i = firstadr; i < nextadr; i++) { JCVariableDecl vardecl = vardecls[i]; VarSymbol var = vardecl.sym; if (var.owner == classDef.sym) { // choose the diagnostic position based on whether // the ctor is default(synthesized) or not if (isSynthesized) { checkInit(TreeInfo.diagnosticPositionFor(var, vardecl), var, "var.not.initialized.in.default.constructor"); } else { checkInit(TreeInfo.diagEndPos(tree.body), var); } } } } List<AssignPendingExit> exits = pendingExits.toList(); pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { AssignPendingExit exit = exits.head; exits = exits.tail; Assert.check(exit.tree.hasTag(RETURN), exit.tree); if (isInitialConstructor) { inits.assign(exit.exit_inits); for (int i = firstadr; i < nextadr; i++) { checkInit(exit.tree.pos(), vardecls[i].sym); } } } } finally { inits.assign(initsPrev); uninits.assign(uninitsPrev); nextadr = nextadrPrev; firstadr = firstadrPrev; returnadr = returnadrPrev; isInitialConstructor = lastInitialConstructor; } } finally { lint = lintPrev; } }