< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java

Print this page

        

*** 96,105 **** --- 96,124 ---- for (List<JCTree> l = trees; l.nonEmpty(); l = l.tail) if (isConstructor(l.head)) return true; return false; } + /** Is there a constructor invocation in the given list of trees? + */ + public static Name getConstructorInvocationName(List<? extends JCTree> trees, Names names, boolean isRecord) { + for (JCTree tree : trees) { + if (tree.hasTag(EXEC)) { + JCExpressionStatement stat = (JCExpressionStatement)tree; + if (stat.expr.hasTag(APPLY)) { + JCMethodInvocation apply = (JCMethodInvocation)stat.expr; + Name methName = TreeInfo.name(apply.meth); + if (methName == names._this || + methName == names._super) { + return methName; + } + } + } + } + return names.empty; + } + public static boolean isMultiCatch(JCCatch catchClause) { return catchClause.param.vartype.hasTag(TYPEUNION); } /** Is statement an initializer for a synthetic field?
*** 188,197 **** --- 207,233 ---- } else { return false; } } + public static List<JCVariableDecl> recordFields(JCClassDecl tree) { + return tree.defs.stream() + .filter(t -> t.hasTag(VARDEF)) + .map(t -> (JCVariableDecl)t) + .filter(vd -> (vd.getModifiers().flags & (Flags.RECORD)) == RECORD) + .collect(List.collector()); + } + + public static List<Type> recordFieldTypes(JCClassDecl tree) { + return tree.defs.stream() + .filter(t -> t.hasTag(VARDEF)) + .map(t -> (JCVariableDecl)t) + .filter(vd -> (vd.getModifiers().flags & (Flags.RECORD)) == RECORD) + .map(vd -> vd.type) + .collect(List.collector()); + } + /** Is this a constructor whose first (non-synthetic) statement is not * of the form this(...)? */ public static boolean isInitialConstructor(JCTree tree) { JCMethodInvocation app = firstConstructorCall(tree);
*** 488,497 **** --- 524,537 ---- return node.pos; } else { return getStartPos(node.vartype); } } + case BINDINGPATTERN: { + JCBindingPattern node = (JCBindingPattern)tree; + return getStartPos(node.vartype); + } case ERRONEOUS: { JCErroneous node = (JCErroneous)tree; if (node.errs != null && node.errs.nonEmpty()) return getStartPos(node.errs.head); }
*** 572,582 **** case WILDCARD: return getEndPos(((JCWildcard) tree).inner, endPosTable); case TYPECAST: return getEndPos(((JCTypeCast) tree).expr, endPosTable); case TYPETEST: ! return getEndPos(((JCInstanceOf) tree).clazz, endPosTable); case WHILELOOP: return getEndPos(((JCWhileLoop) tree).body, endPosTable); case ANNOTATED_TYPE: return getEndPos(((JCAnnotatedType) tree).underlyingType, endPosTable); case ERRONEOUS: { --- 612,622 ---- case WILDCARD: return getEndPos(((JCWildcard) tree).inner, endPosTable); case TYPECAST: return getEndPos(((JCTypeCast) tree).expr, endPosTable); case TYPETEST: ! return getEndPos(((JCInstanceOf) tree).pattern, endPosTable); case WHILELOOP: return getEndPos(((JCWhileLoop) tree).body, endPosTable); case ANNOTATED_TYPE: return getEndPos(((JCAnnotatedType) tree).underlyingType, endPosTable); case ERRONEOUS: {
*** 845,854 **** --- 885,896 ---- case TYPE_ANNOTATION: case TYPEPARAMETER: if (node.type != null) return node.type.tsym; return null; + case BINDINGPATTERN: + return ((JCBindingPattern) node).symbol; default: return null; } }
*** 884,893 **** --- 926,953 ---- default: return null; } } + /** If this tree has a modifiers field, return it otherwise return null + */ + public static JCModifiers getModifiers(JCTree tree) { + tree = skipParens(tree); + switch (tree.getTag()) { + case VARDEF: + return ((JCVariableDecl) tree).mods; + case METHODDEF: + return ((JCMethodDecl) tree).mods; + case CLASSDEF: + return ((JCClassDecl) tree).mods; + case MODULEDEF: + return ((JCModuleDecl) tree).mods; + default: + return null; + } + } + /** 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;
*** 1223,1228 **** --- 1283,1289 ---- } public static boolean isPackageInfo(JCCompilationUnit tree) { return tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); } + }
< prev index next >