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
--- 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;
+ }
+ }
}