8171892: JShell: incorrect printing of multidemensional arrays

8171387: jshell tool: message inconsistencies

Reviewed-by: sundar, dlsmith
This commit is contained in:
Robert Field 2016-12-23 11:17:50 -08:00
parent bc5b401e00
commit 72b502fa4f
3 changed files with 39 additions and 8 deletions

View File

@ -150,8 +150,8 @@ jshell.err.retained.mode.failure = Failure in retained modes (modes cleared) --
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: \

View File

@ -202,12 +202,27 @@ public class DirectExecutionControl implements ExecutionControl {
} 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) {

View File

@ -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 @@ public class SimpleRegressionTest extends KullaTesting {
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 @@ public class SimpleRegressionTest extends KullaTesting {
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 } } }");
}
}