< prev index next >

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

Print this page

  94         return isCanonicalConstructor(tree) && (((JCMethodDecl)tree).sym.flags_field & COMPACT_RECORD_CONSTRUCTOR) != 0;
  95     }
  96 
  97     public static boolean isReceiverParam(JCTree tree) {
  98         if (tree.hasTag(VARDEF)) {
  99             return ((JCVariableDecl)tree).nameexpr != null;
 100         } else {
 101             return false;
 102         }
 103     }
 104 
 105     /** Is there a constructor declaration in the given list of trees?
 106      */
 107     public static boolean hasConstructors(List<JCTree> trees) {
 108         for (List<JCTree> l = trees; l.nonEmpty(); l = l.tail)
 109             if (isConstructor(l.head)) return true;
 110         return false;
 111     }
 112 
 113     /** Is there a constructor invocation in the given list of trees?

 114      */
 115     public static Name getConstructorInvocationName(List<? extends JCTree> trees, Names names) {
 116         for (JCTree tree : trees) {
 117             if (tree.hasTag(EXEC)) {
 118                 JCExpressionStatement stat = (JCExpressionStatement)tree;
 119                 if (stat.expr.hasTag(APPLY)) {
 120                     JCMethodInvocation apply = (JCMethodInvocation)stat.expr;
 121                     Name methName = TreeInfo.name(apply.meth);
 122                     if (methName == names._this ||
 123                         methName == names._super) {
 124                         return methName;


 125                     }
 126                 }
 127             }
 128         }
 129         return names.empty;
 130     }
 131 
 132     public static boolean isMultiCatch(JCCatch catchClause) {
 133         return catchClause.param.vartype.hasTag(TYPEUNION);
 134     }
 135 
 136     /** Is statement an initializer for a synthetic field?
 137      */
 138     public static boolean isSyntheticInit(JCTree stat) {
 139         if (stat.hasTag(EXEC)) {
 140             JCExpressionStatement exec = (JCExpressionStatement)stat;
 141             if (exec.expr.hasTag(ASSIGN)) {
 142                 JCAssign assign = (JCAssign)exec.expr;
 143                 if (assign.lhs.hasTag(SELECT)) {
 144                     JCFieldAccess select = (JCFieldAccess)assign.lhs;

 468             case PLUS_ASG: case MINUS_ASG: case MUL_ASG:
 469             case DIV_ASG: case MOD_ASG:
 470             case OR: case AND: case BITOR:
 471             case BITXOR: case BITAND: case EQ:
 472             case NE: case LT: case GT:
 473             case LE: case GE: case SL:
 474             case SR: case USR: case PLUS:
 475             case MINUS: case MUL: case DIV:
 476             case MOD:
 477             case POSTINC:
 478             case POSTDEC:
 479                 return getStartPos(((JCOperatorExpression) tree).getOperand(LEFT));
 480             case CLASSDEF: {
 481                 JCClassDecl node = (JCClassDecl)tree;
 482                 if (node.mods.pos != Position.NOPOS)
 483                     return node.mods.pos;
 484                 break;
 485             }
 486             case CONDEXPR:
 487                 return getStartPos(((JCConditional) tree).cond);


 488             case EXEC:
 489                 return getStartPos(((JCExpressionStatement) tree).expr);
 490             case INDEXED:
 491                 return getStartPos(((JCArrayAccess) tree).indexed);
 492             case METHODDEF: {
 493                 JCMethodDecl node = (JCMethodDecl)tree;
 494                 if (node.mods.pos != Position.NOPOS)
 495                     return node.mods.pos;
 496                 if (node.typarams.nonEmpty()) // List.nil() used for no typarams
 497                     return getStartPos(node.typarams.head);
 498                 return node.restype == null ? node.pos : getStartPos(node.restype);
 499             }
 500             case SELECT:
 501                 return getStartPos(((JCFieldAccess) tree).selected);
 502             case TYPEAPPLY:
 503                 return getStartPos(((JCTypeApply) tree).clazz);
 504             case TYPEARRAY:
 505                 return getStartPos(((JCArrayTypeTree) tree).elemtype);
 506             case TYPETEST:
 507                 return getStartPos(((JCInstanceOf) tree).expr);

 619             case SYNCHRONIZED:
 620                 return getEndPos(((JCSynchronized) tree).body, endPosTable);
 621             case TOPLEVEL:
 622                 return getEndPos(((JCCompilationUnit) tree).defs.last(), endPosTable);
 623             case TRY: {
 624                 JCTry node = (JCTry)tree;
 625                 if (node.finalizer != null) {
 626                     return getEndPos(node.finalizer, endPosTable);
 627                 } else if (!node.catchers.isEmpty()) {
 628                     return getEndPos(node.catchers.last(), endPosTable);
 629                 } else {
 630                     return getEndPos(node.body, endPosTable);
 631                 }
 632             }
 633             case WILDCARD:
 634                 return getEndPos(((JCWildcard) tree).inner, endPosTable);
 635             case TYPECAST:
 636                 return getEndPos(((JCTypeCast) tree).expr, endPosTable);
 637             case TYPETEST:
 638                 return getEndPos(((JCInstanceOf) tree).pattern, endPosTable);


 639             case WHILELOOP:
 640                 return getEndPos(((JCWhileLoop) tree).body, endPosTable);
 641             case ANNOTATED_TYPE:
 642                 return getEndPos(((JCAnnotatedType) tree).underlyingType, endPosTable);
 643             case PARENTHESIZEDPATTERN: {
 644                 JCParenthesizedPattern node = (JCParenthesizedPattern) tree;
 645                 return getEndPos(node.pattern, endPosTable);
 646             }
 647             case GUARDPATTERN: {
 648                 JCGuardPattern node = (JCGuardPattern) tree;
 649                 return getEndPos(node.expr, endPosTable);
 650             }
 651             case ERRONEOUS: {
 652                 JCErroneous node = (JCErroneous)tree;
 653                 if (node.errs != null && node.errs.nonEmpty())
 654                     return getEndPos(node.errs.last(), endPosTable);
 655             }
 656         }
 657         return Position.NOPOS;
 658     }

  94         return isCanonicalConstructor(tree) && (((JCMethodDecl)tree).sym.flags_field & COMPACT_RECORD_CONSTRUCTOR) != 0;
  95     }
  96 
  97     public static boolean isReceiverParam(JCTree tree) {
  98         if (tree.hasTag(VARDEF)) {
  99             return ((JCVariableDecl)tree).nameexpr != null;
 100         } else {
 101             return false;
 102         }
 103     }
 104 
 105     /** Is there a constructor declaration in the given list of trees?
 106      */
 107     public static boolean hasConstructors(List<JCTree> trees) {
 108         for (List<JCTree> l = trees; l.nonEmpty(); l = l.tail)
 109             if (isConstructor(l.head)) return true;
 110         return false;
 111     }
 112 
 113     /** Is there a constructor invocation in the given list of trees?
 114      *  Optionally, check only for no-arg ctor invocation
 115      */
 116     public static Name getConstructorInvocationName(List<? extends JCTree> trees, Names names, boolean argsAllowed) {
 117         for (JCTree tree : trees) {
 118             if (tree.hasTag(EXEC)) {
 119                 JCExpressionStatement stat = (JCExpressionStatement)tree;
 120                 if (stat.expr.hasTag(APPLY)) {
 121                     JCMethodInvocation apply = (JCMethodInvocation)stat.expr;
 122                     if (argsAllowed || apply.args.size() == 0) {
 123                         Name methName = TreeInfo.name(apply.meth);
 124                         if (methName == names._this ||
 125                                 methName == names._super) {
 126                             return methName;
 127                         }
 128                     }
 129                 }
 130             }
 131         }
 132         return names.empty;
 133     }
 134 
 135     public static boolean isMultiCatch(JCCatch catchClause) {
 136         return catchClause.param.vartype.hasTag(TYPEUNION);
 137     }
 138 
 139     /** Is statement an initializer for a synthetic field?
 140      */
 141     public static boolean isSyntheticInit(JCTree stat) {
 142         if (stat.hasTag(EXEC)) {
 143             JCExpressionStatement exec = (JCExpressionStatement)stat;
 144             if (exec.expr.hasTag(ASSIGN)) {
 145                 JCAssign assign = (JCAssign)exec.expr;
 146                 if (assign.lhs.hasTag(SELECT)) {
 147                     JCFieldAccess select = (JCFieldAccess)assign.lhs;

 471             case PLUS_ASG: case MINUS_ASG: case MUL_ASG:
 472             case DIV_ASG: case MOD_ASG:
 473             case OR: case AND: case BITOR:
 474             case BITXOR: case BITAND: case EQ:
 475             case NE: case LT: case GT:
 476             case LE: case GE: case SL:
 477             case SR: case USR: case PLUS:
 478             case MINUS: case MUL: case DIV:
 479             case MOD:
 480             case POSTINC:
 481             case POSTDEC:
 482                 return getStartPos(((JCOperatorExpression) tree).getOperand(LEFT));
 483             case CLASSDEF: {
 484                 JCClassDecl node = (JCClassDecl)tree;
 485                 if (node.mods.pos != Position.NOPOS)
 486                     return node.mods.pos;
 487                 break;
 488             }
 489             case CONDEXPR:
 490                 return getStartPos(((JCConditional) tree).cond);
 491             case DEFAULT_VALUE:
 492                 return getStartPos(((JCDefaultValue) tree).clazz);
 493             case EXEC:
 494                 return getStartPos(((JCExpressionStatement) tree).expr);
 495             case INDEXED:
 496                 return getStartPos(((JCArrayAccess) tree).indexed);
 497             case METHODDEF: {
 498                 JCMethodDecl node = (JCMethodDecl)tree;
 499                 if (node.mods.pos != Position.NOPOS)
 500                     return node.mods.pos;
 501                 if (node.typarams.nonEmpty()) // List.nil() used for no typarams
 502                     return getStartPos(node.typarams.head);
 503                 return node.restype == null ? node.pos : getStartPos(node.restype);
 504             }
 505             case SELECT:
 506                 return getStartPos(((JCFieldAccess) tree).selected);
 507             case TYPEAPPLY:
 508                 return getStartPos(((JCTypeApply) tree).clazz);
 509             case TYPEARRAY:
 510                 return getStartPos(((JCArrayTypeTree) tree).elemtype);
 511             case TYPETEST:
 512                 return getStartPos(((JCInstanceOf) tree).expr);

 624             case SYNCHRONIZED:
 625                 return getEndPos(((JCSynchronized) tree).body, endPosTable);
 626             case TOPLEVEL:
 627                 return getEndPos(((JCCompilationUnit) tree).defs.last(), endPosTable);
 628             case TRY: {
 629                 JCTry node = (JCTry)tree;
 630                 if (node.finalizer != null) {
 631                     return getEndPos(node.finalizer, endPosTable);
 632                 } else if (!node.catchers.isEmpty()) {
 633                     return getEndPos(node.catchers.last(), endPosTable);
 634                 } else {
 635                     return getEndPos(node.body, endPosTable);
 636                 }
 637             }
 638             case WILDCARD:
 639                 return getEndPos(((JCWildcard) tree).inner, endPosTable);
 640             case TYPECAST:
 641                 return getEndPos(((JCTypeCast) tree).expr, endPosTable);
 642             case TYPETEST:
 643                 return getEndPos(((JCInstanceOf) tree).pattern, endPosTable);
 644             case WITHFIELD:
 645                 return getEndPos(((JCWithField) tree).value, endPosTable);
 646             case WHILELOOP:
 647                 return getEndPos(((JCWhileLoop) tree).body, endPosTable);
 648             case ANNOTATED_TYPE:
 649                 return getEndPos(((JCAnnotatedType) tree).underlyingType, endPosTable);
 650             case PARENTHESIZEDPATTERN: {
 651                 JCParenthesizedPattern node = (JCParenthesizedPattern) tree;
 652                 return getEndPos(node.pattern, endPosTable);
 653             }
 654             case GUARDPATTERN: {
 655                 JCGuardPattern node = (JCGuardPattern) tree;
 656                 return getEndPos(node.expr, endPosTable);
 657             }
 658             case ERRONEOUS: {
 659                 JCErroneous node = (JCErroneous)tree;
 660                 if (node.errs != null && node.errs.nonEmpty())
 661                     return getEndPos(node.errs.last(), endPosTable);
 662             }
 663         }
 664         return Position.NOPOS;
 665     }
< prev index next >