8171892: JShell: incorrect printing of multidemensional arrays
authorrfield
Fri, 23 Dec 2016 11:17:50 -0800
changeset 42971 22c8c025a651
parent 42970 bcdba0c26793
child 42972 47ca49eee534
8171892: JShell: incorrect printing of multidemensional arrays 8171387: jshell tool: message inconsistencies Reviewed-by: sundar, dlsmith
langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties
langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DirectExecutionControl.java
langtools/test/jdk/jshell/SimpleRegressionTest.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Thu Dec 22 18:48:42 2016 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Fri Dec 23 11:17:50 2016 -0800
@@ -150,8 +150,8 @@
 jshell.console.see.more = <press tab to see more>
 jshell.console.see.javadoc = <press shift-tab again to see javadoc>
 jshell.console.see.help = <press shift-tab again to see detailed help>
-jshell.console.see.next.page = -- Press space for next page, Q to quit. --
-jshell.console.see.next.javadoc = -- Press space for next javadoc, Q to quit. --
+jshell.console.see.next.page = <press space for next page, Q to quit>
+jshell.console.see.next.javadoc = <press space for next javadoc, Q to quit>
 jshell.console.no.javadoc = <no javadoc found>
 jshell.console.do.nothing = Do nothing
 jshell.console.choice = Choice: \
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DirectExecutionControl.java	Thu Dec 22 18:48:42 2016 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DirectExecutionControl.java	Fri Dec 23 11:17:50 2016 -0800
@@ -202,12 +202,27 @@
         } else if (value instanceof Character) {
             return "'" + value + "'";
         } else if (value.getClass().isArray()) {
-            String tn = value.getClass().getTypeName();
+            int dims = 0;
+            Class<?> t = value.getClass();
+            while (true) {
+                Class<?> ct = t.getComponentType();
+                if (ct == null) {
+                    break;
+                }
+                ++dims;
+                t = ct;
+            }
+            String tn = t.getTypeName();
             int len = Array.getLength(value);
             StringBuilder sb = new StringBuilder();
-            sb.append(tn.substring(tn.lastIndexOf('.') + 1, tn.length() - 1));
+            sb.append(tn.substring(tn.lastIndexOf('.') + 1, tn.length()));
+            sb.append("[");
             sb.append(len);
-            sb.append("] { ");
+            sb.append("]");
+            for (int i = 1; i < dims; ++i) {
+                sb.append("[]");
+            }
+            sb.append(" { ");
             for (int i = 0; i < len; ++i) {
                 sb.append(valueString(Array.get(value, i)));
                 if (i < len - 1) {
--- a/langtools/test/jdk/jshell/SimpleRegressionTest.java	Thu Dec 22 18:48:42 2016 +0000
+++ b/langtools/test/jdk/jshell/SimpleRegressionTest.java	Fri Dec 23 11:17:50 2016 -0800
@@ -22,7 +22,7 @@
  */
 
 /*
- * @test 8130450 8158906 8154374 8166400
+ * @test 8130450 8158906 8154374 8166400 8171892
  * @summary simple regression test
  * @build KullaTesting TestingInputStream
  * @run testng SimpleRegressionTest
@@ -150,7 +150,7 @@
         assertEval("C.class.getClassLoader() == Thread.currentThread().getContextClassLoader()", "true");
     }
 
-    public void testArayRepresentation() {
+    public void testArrayRepresentation() {
         assertEval("new int[4]", "int[4] { 0, 0, 0, 0 }");
         assertEval("new int[0]", "int[0] {  }");
         assertEval("new byte[2]", "byte[2] { 0, 0 }");
@@ -162,8 +162,24 @@
         assertEval("new char[] { 'a', 34, 77 }", "char[3] { 'a', '\"', 'M' }");
         assertEval("new boolean[] { false, true }", "boolean[2] { false, true }");
         assertEval("new int[][] { new int[] {44, 55}, new int[] {88,99}}",
-                "int[][2] { int[2] { 44, 55 }, int[2] { 88, 99 } }");
+                "int[2][] { int[2] { 44, 55 }, int[2] { 88, 99 } }");
         assertEval("new Object[] { \"howdy\", new int[] { 33, 44, 55 }, new String[] { \"up\", \"down\" }}",
                 "Object[3] { \"howdy\", int[3] { 33, 44, 55 }, String[2] { \"up\", \"down\" } }");
     }
+
+    public void testMultiDimArrayRepresentation() {
+        assertEval("new int[3][1]",
+                "int[3][] { int[1] { 0 }, int[1] { 0 }, int[1] { 0 } }");
+        assertEval("new int[3][]",
+                "int[3][] { null, null, null }");
+        assertEval("new int[][] { new int[] {44}, new int[] {77, 88,99}}",
+                "int[2][] { int[1] { 44 }, int[3] { 77, 88, 99 } }");
+        assertEval("new String[3][1]",
+                "String[3][] { String[1] { null }, String[1] { null }, String[1] { null } }");
+        assertEval("class C { }");
+        assertEval("new C[3][2]",
+                "C[3][] { C[2] { null, null }, C[2] { null, null }, C[2] { null, null } }");
+        assertEval("new boolean[2][1][3]",
+                "boolean[2][][] { boolean[1][] { boolean[3] { false, false, false } }, boolean[1][] { boolean[3] { false, false, false } } }");
+    }
 }