6917122: provide utility method to find the inner most type of a type tree
authorjjg
Thu, 14 Jan 2010 17:18:30 -0800
changeset 4705 7fac532dc6fa
parent 4704 5206047418c2
child 4706 9dc1a9745cf3
6917122: provide utility method to find the inner most type of a type tree Reviewed-by: darcy, jjg Contributed-by: mali@csail.mit.edu, mernst@cs.washington.edu
langtools/src/share/classes/com/sun/tools/javac/tree/Pretty.java
langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Wed Jan 13 17:39:44 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Thu Jan 14 17:18:30 2010 -0800
@@ -1152,20 +1152,7 @@
 
     // Prints the inner element type of a nested array
     private void printBaseElementType(JCTree tree) throws IOException {
-        switch (tree.getTag()) {
-        case JCTree.TYPEARRAY:
-            printBaseElementType(((JCArrayTypeTree)tree).elemtype);
-            return;
-        case JCTree.WILDCARD:
-            printBaseElementType(((JCWildcard)tree).inner);
-            return;
-        case JCTree.ANNOTATED_TYPE:
-            printBaseElementType(((JCAnnotatedType)tree).underlyingType);
-            return;
-        default:
-            printExpr(tree);
-            return;
-        }
+        printExpr(TreeInfo.innermostType(tree));
     }
 
     // prints the brackets of a nested array in reverse order
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Wed Jan 13 17:39:44 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Thu Jan 14 17:18:30 2010 -0800
@@ -891,4 +891,17 @@
             throw new AssertionError("Unexpected type tree: " + tree);
         }
     }
+
+    public static JCTree innermostType(JCTree type) {
+        switch (type.getTag()) {
+        case JCTree.TYPEARRAY:
+            return innermostType(((JCArrayTypeTree)type).elemtype);
+        case JCTree.WILDCARD:
+            return innermostType(((JCWildcard)type).inner);
+        case JCTree.ANNOTATED_TYPE:
+            return innermostType(((JCAnnotatedType)type).underlyingType);
+        default:
+            return type;
+        }
+    }
 }