langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
changeset 11055 ec1418effa77
parent 10950 e87b50888909
child 11142 45d0ec1e7463
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Mon Nov 14 08:09:47 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Mon Nov 14 15:11:10 2011 -0800
@@ -28,10 +28,10 @@
 import com.sun.source.tree.Tree;
 import com.sun.tools.javac.comp.AttrContext;
 import com.sun.tools.javac.comp.Env;
-import java.util.Map;
 import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 import com.sun.tools.javac.code.*;
+import com.sun.tools.javac.parser.EndPosTable;
 import com.sun.tools.javac.tree.JCTree.*;
 
 import static com.sun.tools.javac.code.Flags.*;
@@ -346,17 +346,17 @@
 
     /** The end position of given tree, given  a table of end positions generated by the parser
      */
-    public static int getEndPos(JCTree tree, Map<JCTree, Integer> endPositions) {
+    public static int getEndPos(JCTree tree, EndPosTable endPosTable) {
         if (tree == null)
             return Position.NOPOS;
 
-        if (endPositions == null) {
+        if (endPosTable == null) {
             // fall back on limited info in the tree
             return endPos(tree);
         }
 
-        Integer mapPos = endPositions.get(tree);
-        if (mapPos != null)
+        int mapPos = endPosTable.getEndPos(tree);
+        if (mapPos != Position.NOPOS)
             return mapPos;
 
         switch(tree.getTag()) {
@@ -364,7 +364,7 @@
             case SL_ASG: case SR_ASG: case USR_ASG:
             case PLUS_ASG: case MINUS_ASG: case MUL_ASG:
             case DIV_ASG: case MOD_ASG:
-                return getEndPos(((JCAssignOp) tree).rhs, endPositions);
+                return getEndPos(((JCAssignOp) tree).rhs, endPosTable);
             case OR: case AND: case BITOR:
             case BITXOR: case BITAND: case EQ:
             case NE: case LT: case GT:
@@ -372,62 +372,62 @@
             case SR: case USR: case PLUS:
             case MINUS: case MUL: case DIV:
             case MOD:
-                return getEndPos(((JCBinary) tree).rhs, endPositions);
+                return getEndPos(((JCBinary) tree).rhs, endPosTable);
             case CASE:
-                return getEndPos(((JCCase) tree).stats.last(), endPositions);
+                return getEndPos(((JCCase) tree).stats.last(), endPosTable);
             case CATCH:
-                return getEndPos(((JCCatch) tree).body, endPositions);
+                return getEndPos(((JCCatch) tree).body, endPosTable);
             case CONDEXPR:
-                return getEndPos(((JCConditional) tree).falsepart, endPositions);
+                return getEndPos(((JCConditional) tree).falsepart, endPosTable);
             case FORLOOP:
-                return getEndPos(((JCForLoop) tree).body, endPositions);
+                return getEndPos(((JCForLoop) tree).body, endPosTable);
             case FOREACHLOOP:
-                return getEndPos(((JCEnhancedForLoop) tree).body, endPositions);
+                return getEndPos(((JCEnhancedForLoop) tree).body, endPosTable);
             case IF: {
                 JCIf node = (JCIf)tree;
                 if (node.elsepart == null) {
-                    return getEndPos(node.thenpart, endPositions);
+                    return getEndPos(node.thenpart, endPosTable);
                 } else {
-                    return getEndPos(node.elsepart, endPositions);
+                    return getEndPos(node.elsepart, endPosTable);
                 }
             }
             case LABELLED:
-                return getEndPos(((JCLabeledStatement) tree).body, endPositions);
+                return getEndPos(((JCLabeledStatement) tree).body, endPosTable);
             case MODIFIERS:
-                return getEndPos(((JCModifiers) tree).annotations.last(), endPositions);
+                return getEndPos(((JCModifiers) tree).annotations.last(), endPosTable);
             case SYNCHRONIZED:
-                return getEndPos(((JCSynchronized) tree).body, endPositions);
+                return getEndPos(((JCSynchronized) tree).body, endPosTable);
             case TOPLEVEL:
-                return getEndPos(((JCCompilationUnit) tree).defs.last(), endPositions);
+                return getEndPos(((JCCompilationUnit) tree).defs.last(), endPosTable);
             case TRY: {
                 JCTry node = (JCTry)tree;
                 if (node.finalizer != null) {
-                    return getEndPos(node.finalizer, endPositions);
+                    return getEndPos(node.finalizer, endPosTable);
                 } else if (!node.catchers.isEmpty()) {
-                    return getEndPos(node.catchers.last(), endPositions);
+                    return getEndPos(node.catchers.last(), endPosTable);
                 } else {
-                    return getEndPos(node.body, endPositions);
+                    return getEndPos(node.body, endPosTable);
                 }
             }
             case WILDCARD:
-                return getEndPos(((JCWildcard) tree).inner, endPositions);
+                return getEndPos(((JCWildcard) tree).inner, endPosTable);
             case TYPECAST:
-                return getEndPos(((JCTypeCast) tree).expr, endPositions);
+                return getEndPos(((JCTypeCast) tree).expr, endPosTable);
             case TYPETEST:
-                return getEndPos(((JCInstanceOf) tree).clazz, endPositions);
+                return getEndPos(((JCInstanceOf) tree).clazz, endPosTable);
             case POS:
             case NEG:
             case NOT:
             case COMPL:
             case PREINC:
             case PREDEC:
-                return getEndPos(((JCUnary) tree).arg, endPositions);
+                return getEndPos(((JCUnary) tree).arg, endPosTable);
             case WHILELOOP:
-                return getEndPos(((JCWhileLoop) tree).body, endPositions);
+                return getEndPos(((JCWhileLoop) tree).body, endPosTable);
             case ERRONEOUS: {
                 JCErroneous node = (JCErroneous)tree;
                 if (node.errs != null && node.errs.nonEmpty())
-                    return getEndPos(node.errs.last(), endPositions);
+                    return getEndPos(node.errs.last(), endPosTable);
             }
         }
         return Position.NOPOS;
@@ -444,7 +444,7 @@
             public JCTree getTree() { return tree; }
             public int getStartPosition() { return TreeInfo.getStartPos(tree); }
             public int getPreferredPosition() { return endPos; }
-            public int getEndPosition(Map<JCTree, Integer> endPosTable) {
+            public int getEndPosition(EndPosTable endPosTable) {
                 return TreeInfo.getEndPos(tree, endPosTable);
             }
         };