private Tree skipLabel(JCTree tree) { return tree.hasTag(JCTree.Tag.LABELLED) ? ((JCTree.JCLabeledStatement) tree).body : tree; }
/** Return true if a tree represents the null literal. */ public static boolean isNull(JCTree tree) { if (!tree.hasTag(LITERAL)) return false; JCLiteral lit = (JCLiteral) tree; return (lit.typetag == BOT); }
private boolean isTranslatedClassAvailable(ClassSymbol c) { for (JCTree tree: translated) { if (tree.hasTag(CLASSDEF) && ((JCClassDecl) tree).sym == c) { return true; } } return false; }
/** The scope in which a member definition in environment env is to be entered * This is usually the environment's scope, except for class environments, * where the local scope is for type variables, and the this and super symbol * only, and members go into the class member scope. */ Scope enterScope(Env<AttrContext> env) { return (env.tree.hasTag(JCTree.Tag.CLASSDEF)) ? ((JCClassDecl) env.tree).sym.members_field : env.info.scope; }
/** Is tree a constructor declaration? */ public static boolean isConstructor(JCTree tree) { if (tree.hasTag(METHODDEF)) { Name name = ((JCMethodDecl) tree).name; return name == name.table.names.init; } else { return false; } }
/** The scope in which a member definition in environment env is to be entered * This is usually the environment's scope, except for class environments, * where the local scope is for type variables, and the this and super symbol * only, and members go into the class member scope. */ Scope enterScope(Env<AttrContext> env) { return (env.tree.hasTag(JCTree.Tag.CLASSDEF)) ? ((JCClassDecl) env.tree).sym.members_field : env.info.scope; }
private JCLiteral stringLiteral(JCTree tree) { if (tree.hasTag(LITERAL)) { JCLiteral lit = (JCLiteral)tree; if (lit.typetag == TypeTag.CLASS) { return lit; } } return null; }
public List<JCTree> getTypeDecls() { List<JCTree> typeDefs; for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail) if (!typeDefs.head.hasTag(IMPORT)) break; return typeDefs; } @Override
private boolean isCanonical(JCTree tree) { while (tree.hasTag(SELECT)) { JCFieldAccess s = (JCFieldAccess) tree; if (s.sym.owner != TreeInfo.symbol(s.selected)) return false; tree = s.selected; } return true; }
/** Skip parens and return the enclosed expression */ public static JCTree skipParens(JCTree tree) { if (tree.hasTag(PARENS)) return skipParens((JCParens)tree); else return tree; }
public static String getCommentText(Env<?> env, JCTree tree) { DocCommentTable docComments = (tree.hasTag(JCTree.Tag.TOPLEVEL)) ? ((JCCompilationUnit) tree).docComments : env.toplevel.docComments; return (docComments == null) ? null : docComments.getCommentText(tree); }
/** The position of the first statement in a block, or the position of * the block itself if it is empty. */ public static int firstStatPos(JCTree tree) { if (tree.hasTag(BLOCK) && ((JCBlock) tree).stats.nonEmpty()) return ((JCBlock) tree).stats.head.pos; else return tree.pos; }
/** Add any variables defined in stats to the switch scope. */ private static void addVars(List<JCStatement> stats, Scope switchScope) { for (;stats.nonEmpty(); stats = stats.tail) { JCTree stat = stats.head; if (stat.hasTag(VARDEF)) switchScope.enter(((JCVariableDecl) stat).sym); } } // where
/** Return true if this is a nonstatic selection. */ public static boolean nonstaticSelect(JCTree tree) { tree = skipParens(tree); if (!tree.hasTag(SELECT)) return false; JCFieldAccess s = (JCFieldAccess) tree; Symbol e = symbol(s.selected); return e == null || (e.kind != Kinds.PCK && e.kind != Kinds.TYP); }
void reportEffectivelyFinalError(DiagnosticPosition pos, Symbol sym) { String subKey = currentTree.hasTag(LAMBDA) ? "lambda" : "inner.cls"; log.error(pos, "cant.ref.non.effectively.final.var", sym, diags.fragment(subKey)); }
/** Analyze a statement. Check that statement is reachable. */ void scanStat(JCTree tree) { if (!alive && tree != null) { log.error(tree.pos(), "unreachable.stmt"); if (!tree.hasTag(SKIP)) alive = true; } scan(tree); }
/** * Attribute an env for either a top level tree or class declaration. */ public void attrib(Env<AttrContext> env) { if (env.tree.hasTag(TOPLEVEL)) attribTopLevel(env); else attribClass(env.tree.pos(), env.enclClass.sym); }
/** Derived visitor method: generate code for a statement. */ public void genStat(JCTree tree, Env<GenContext> env) { if (code.isAlive()) { code.statBegin(tree.pos); genDef(tree, env); } else if (env.info.isSwitch && tree.hasTag(VARDEF)) { // variables whose declarations are in a switch // can be used even if the decl is unreachable. code.newLocal(((JCVariableDecl) tree).sym); } }
public void visitBlock(JCBlock tree) { int limit = code.nextreg; Env<GenContext> localEnv = env.dup(tree, new GenContext()); genStats(tree.stats, localEnv); // End the scope of all block-local variables in variable info. if (!env.tree.hasTag(METHODDEF)) { code.statBegin(tree.endpos); code.endScopes(limit); code.pendingStatPos = Position.NOPOS; } }