34 import com.sun.tools.javac.comp.Env; |
34 import com.sun.tools.javac.comp.Env; |
35 import com.sun.tools.javac.tree.JCTree.*; |
35 import com.sun.tools.javac.tree.JCTree.*; |
36 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; |
36 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; |
37 import com.sun.tools.javac.util.*; |
37 import com.sun.tools.javac.util.*; |
38 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
38 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
39 |
39 import static com.sun.tools.javac.code.Flags.*; |
40 import static com.sun.tools.javac.code.Flags.*; |
40 import static com.sun.tools.javac.code.Kinds.Kind.*; |
41 import static com.sun.tools.javac.code.Kinds.Kind.*; |
41 import static com.sun.tools.javac.code.TypeTag.BOT; |
42 import static com.sun.tools.javac.code.TypeTag.BOT; |
42 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
43 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
43 import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK; |
44 import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK; |
44 import static com.sun.tools.javac.tree.JCTree.Tag.SYNCHRONIZED; |
45 import static com.sun.tools.javac.tree.JCTree.Tag.SYNCHRONIZED; |
|
46 |
45 import javax.tools.JavaFileObject; |
47 import javax.tools.JavaFileObject; |
|
48 |
|
49 import static com.sun.tools.javac.tree.JCTree.JCOperatorExpression.OperandPos.LEFT; |
|
50 import static com.sun.tools.javac.tree.JCTree.JCOperatorExpression.OperandPos.RIGHT; |
46 |
51 |
47 /** Utility class containing inspector methods for trees. |
52 /** Utility class containing inspector methods for trees. |
48 * |
53 * |
49 * <p><b>This is NOT part of any supported API. |
54 * <p><b>This is NOT part of any supported API. |
50 * If you write code that depends on this, you do so at your own risk. |
55 * If you write code that depends on this, you do so at your own risk. |
384 return getStartPos(((JCAssign) tree).lhs); |
389 return getStartPos(((JCAssign) tree).lhs); |
385 case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG: |
390 case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG: |
386 case SL_ASG: case SR_ASG: case USR_ASG: |
391 case SL_ASG: case SR_ASG: case USR_ASG: |
387 case PLUS_ASG: case MINUS_ASG: case MUL_ASG: |
392 case PLUS_ASG: case MINUS_ASG: case MUL_ASG: |
388 case DIV_ASG: case MOD_ASG: |
393 case DIV_ASG: case MOD_ASG: |
389 return getStartPos(((JCAssignOp) tree).lhs); |
|
390 case OR: case AND: case BITOR: |
394 case OR: case AND: case BITOR: |
391 case BITXOR: case BITAND: case EQ: |
395 case BITXOR: case BITAND: case EQ: |
392 case NE: case LT: case GT: |
396 case NE: case LT: case GT: |
393 case LE: case GE: case SL: |
397 case LE: case GE: case SL: |
394 case SR: case USR: case PLUS: |
398 case SR: case USR: case PLUS: |
395 case MINUS: case MUL: case DIV: |
399 case MINUS: case MUL: case DIV: |
396 case MOD: |
400 case MOD: |
397 return getStartPos(((JCBinary) tree).lhs); |
401 case POSTINC: |
|
402 case POSTDEC: |
|
403 return getStartPos(((JCOperatorExpression) tree).getOperand(LEFT)); |
398 case CLASSDEF: { |
404 case CLASSDEF: { |
399 JCClassDecl node = (JCClassDecl)tree; |
405 JCClassDecl node = (JCClassDecl)tree; |
400 if (node.mods.pos != Position.NOPOS) |
406 if (node.mods.pos != Position.NOPOS) |
401 return node.mods.pos; |
407 return node.mods.pos; |
402 break; |
408 break; |
421 return getStartPos(((JCTypeApply) tree).clazz); |
427 return getStartPos(((JCTypeApply) tree).clazz); |
422 case TYPEARRAY: |
428 case TYPEARRAY: |
423 return getStartPos(((JCArrayTypeTree) tree).elemtype); |
429 return getStartPos(((JCArrayTypeTree) tree).elemtype); |
424 case TYPETEST: |
430 case TYPETEST: |
425 return getStartPos(((JCInstanceOf) tree).expr); |
431 return getStartPos(((JCInstanceOf) tree).expr); |
426 case POSTINC: |
|
427 case POSTDEC: |
|
428 return getStartPos(((JCUnary) tree).arg); |
|
429 case ANNOTATED_TYPE: { |
432 case ANNOTATED_TYPE: { |
430 JCAnnotatedType node = (JCAnnotatedType) tree; |
433 JCAnnotatedType node = (JCAnnotatedType) tree; |
431 if (node.annotations.nonEmpty()) { |
434 if (node.annotations.nonEmpty()) { |
432 if (node.underlyingType.hasTag(TYPEARRAY) || |
435 if (node.underlyingType.hasTag(TYPEARRAY) || |
433 node.underlyingType.hasTag(SELECT)) { |
436 node.underlyingType.hasTag(SELECT)) { |
484 switch(tree.getTag()) { |
487 switch(tree.getTag()) { |
485 case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG: |
488 case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG: |
486 case SL_ASG: case SR_ASG: case USR_ASG: |
489 case SL_ASG: case SR_ASG: case USR_ASG: |
487 case PLUS_ASG: case MINUS_ASG: case MUL_ASG: |
490 case PLUS_ASG: case MINUS_ASG: case MUL_ASG: |
488 case DIV_ASG: case MOD_ASG: |
491 case DIV_ASG: case MOD_ASG: |
489 return getEndPos(((JCAssignOp) tree).rhs, endPosTable); |
|
490 case OR: case AND: case BITOR: |
492 case OR: case AND: case BITOR: |
491 case BITXOR: case BITAND: case EQ: |
493 case BITXOR: case BITAND: case EQ: |
492 case NE: case LT: case GT: |
494 case NE: case LT: case GT: |
493 case LE: case GE: case SL: |
495 case LE: case GE: case SL: |
494 case SR: case USR: case PLUS: |
496 case SR: case USR: case PLUS: |
495 case MINUS: case MUL: case DIV: |
497 case MINUS: case MUL: case DIV: |
496 case MOD: |
498 case MOD: |
497 return getEndPos(((JCBinary) tree).rhs, endPosTable); |
499 case POS: |
|
500 case NEG: |
|
501 case NOT: |
|
502 case COMPL: |
|
503 case PREINC: |
|
504 case PREDEC: |
|
505 return getEndPos(((JCOperatorExpression) tree).getOperand(RIGHT), endPosTable); |
498 case CASE: |
506 case CASE: |
499 return getEndPos(((JCCase) tree).stats.last(), endPosTable); |
507 return getEndPos(((JCCase) tree).stats.last(), endPosTable); |
500 case CATCH: |
508 case CATCH: |
501 return getEndPos(((JCCatch) tree).body, endPosTable); |
509 return getEndPos(((JCCatch) tree).body, endPosTable); |
502 case CONDEXPR: |
510 case CONDEXPR: |
535 return getEndPos(((JCWildcard) tree).inner, endPosTable); |
543 return getEndPos(((JCWildcard) tree).inner, endPosTable); |
536 case TYPECAST: |
544 case TYPECAST: |
537 return getEndPos(((JCTypeCast) tree).expr, endPosTable); |
545 return getEndPos(((JCTypeCast) tree).expr, endPosTable); |
538 case TYPETEST: |
546 case TYPETEST: |
539 return getEndPos(((JCInstanceOf) tree).clazz, endPosTable); |
547 return getEndPos(((JCInstanceOf) tree).clazz, endPosTable); |
540 case POS: |
|
541 case NEG: |
|
542 case NOT: |
|
543 case COMPL: |
|
544 case PREINC: |
|
545 case PREDEC: |
|
546 return getEndPos(((JCUnary) tree).arg, endPosTable); |
|
547 case WHILELOOP: |
548 case WHILELOOP: |
548 return getEndPos(((JCWhileLoop) tree).body, endPosTable); |
549 return getEndPos(((JCWhileLoop) tree).body, endPosTable); |
549 case ANNOTATED_TYPE: |
550 case ANNOTATED_TYPE: |
550 return getEndPos(((JCAnnotatedType) tree).underlyingType, endPosTable); |
551 return getEndPos(((JCAnnotatedType) tree).underlyingType, endPosTable); |
551 case ERRONEOUS: { |
552 case ERRONEOUS: { |