< prev index next > src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java
Print this page
/** 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;
+ return name == name.table.names.init || name == name.table.names.vnew;
+ } else {
+ return false;
+ }
+ }
+
+ /** Is tree a value factory declaration?
+ */
+ public static boolean isValueFactory(JCTree tree) {
+ if (tree.hasTag(METHODDEF)) {
+ Name name = ((JCMethodDecl) tree).name;
+ return name == name.table.names.vnew;
} else {
return false;
}
}
/** Is there a constructor declaration in the given list of trees?
*/
public static boolean hasConstructors(List<JCTree> trees) {
for (List<JCTree> l = trees; l.nonEmpty(); l = l.tail)
- if (isConstructor(l.head)) return true;
+ if (isConstructor(l.head) || isValueFactory(l.head)) return true;
return false;
}
/** Is there a constructor invocation in the given list of trees?
+ * Optionally, check only for no-arg ctor invocation
*/
- public static Name getConstructorInvocationName(List<? extends JCTree> trees, Names names) {
+ public static Name getConstructorInvocationName(List<? extends JCTree> trees, Names names, boolean argsAllowed) {
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;
+ if (argsAllowed || apply.args.size() == 0) {
+ Name methName = TreeInfo.name(apply.meth);
+ if (methName == names._this ||
+ methName == names._super) {
+ return methName;
+ }
}
}
}
}
return names.empty;
/** Return the first call in a constructor definition. */
public static JCMethodInvocation firstConstructorCall(JCTree tree) {
if (!tree.hasTag(METHODDEF)) return null;
JCMethodDecl md = (JCMethodDecl) tree;
- Names names = md.name.table.names;
- if (md.name != names.init) return null;
+ if (!md.isInitOrVNew()) return null;
if (md.body == null) return null;
List<JCStatement> stats = md.body.stats;
// Synthetic initializations can appear before the super call.
while (stats.nonEmpty() && isSyntheticInit(stats.head))
stats = stats.tail;
return node.mods.pos;
break;
}
case CONDEXPR:
return getStartPos(((JCConditional) tree).cond);
+ case DEFAULT_VALUE:
+ return getStartPos(((JCDefaultValue) tree).clazz);
case EXEC:
return getStartPos(((JCExpressionStatement) tree).expr);
case INDEXED:
return getStartPos(((JCArrayAccess) tree).indexed);
case METHODDEF: {
return getEndPos(((JCWildcard) tree).inner, endPosTable);
case TYPECAST:
return getEndPos(((JCTypeCast) tree).expr, endPosTable);
case TYPETEST:
return getEndPos(((JCInstanceOf) tree).pattern, endPosTable);
+ case WITHFIELD:
+ return getEndPos(((JCWithField) tree).value, endPosTable);
case WHILELOOP:
return getEndPos(((JCWhileLoop) tree).body, endPosTable);
case ANNOTATED_TYPE:
return getEndPos(((JCAnnotatedType) tree).underlyingType, endPosTable);
case ERRONEOUS: {
< prev index next >