changeset 498:b96ad32c004a

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
author jjg
date Thu, 14 Jan 2010 17:18:30 -0800
parents ccd51af119b4
children 2d0f4e7b44b2
files src/share/classes/com/sun/tools/javac/tree/Pretty.java src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
diffstat 2 files changed, 14 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Wed Jan 13 17:39:44 2010 -0800
+++ b/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/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Wed Jan 13 17:39:44 2010 -0800
+++ b/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;
+        }
+    }
 }