author | rfield |
Fri, 11 Dec 2015 11:20:10 -0800 | |
changeset 34750 | 36d62753f5da |
parent 33362 | 65ec6de1d6b4 |
child 43134 | 006808ae5f6e |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
34750
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
26 |
* @bug 8144903 |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
27 |
* @summary Tests for determining the type from the expression |
33362 | 28 |
* @build KullaTesting TestingInputStream |
29 |
* @run testng TypeNameTest |
|
30 |
*/ |
|
31 |
||
32 |
import jdk.jshell.Snippet; |
|
33 |
import jdk.jshell.VarSnippet; |
|
34 |
import org.testng.annotations.Test; |
|
35 |
||
36 |
import static jdk.jshell.Snippet.Status.VALID; |
|
37 |
import static org.testng.Assert.assertEquals; |
|
38 |
||
39 |
@Test |
|
40 |
public class TypeNameTest extends KullaTesting { |
|
41 |
||
42 |
public void testReplClassName() { |
|
43 |
assertEval("class C {}"); |
|
44 |
VarSnippet sn = (VarSnippet) varKey(assertEval("new C();")); |
|
45 |
assertEquals(sn.typeName(), "C"); |
|
46 |
} |
|
47 |
||
48 |
public void testReplNestedClassName() { |
|
49 |
assertEval("class D { static class E {} }"); |
|
50 |
VarSnippet sn = (VarSnippet) varKey(assertEval("new D.E();")); |
|
51 |
assertEquals(sn.typeName(), "D.E"); |
|
52 |
} |
|
53 |
||
54 |
public void testAnonymousClassName() { |
|
55 |
assertEval("class C {}"); |
|
56 |
VarSnippet sn = (VarSnippet) varKey(assertEval("new C() { int x; };")); |
|
57 |
assertEquals(sn.typeName(), "C"); |
|
58 |
} |
|
59 |
||
60 |
public void testCapturedTypeName() { |
|
61 |
VarSnippet sn = (VarSnippet) varKey(assertEval("\"\".getClass();")); |
|
62 |
assertEquals(sn.typeName(), "Class<? extends String>"); |
|
63 |
} |
|
64 |
||
34750
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
65 |
public void testArrayTypeOfCapturedTypeName() { |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
66 |
VarSnippet sn = (VarSnippet) varKey(assertEval("\"\".getClass().getEnumConstants();")); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
67 |
assertEquals(sn.typeName(), "String[]"); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
68 |
} |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
69 |
|
33362 | 70 |
public void testJavaLang() { |
71 |
VarSnippet sn = (VarSnippet) varKey(assertEval("\"\";")); |
|
72 |
assertEquals(sn.typeName(), "String"); |
|
73 |
} |
|
74 |
||
75 |
public void testNotOverEagerPackageEating() { |
|
76 |
VarSnippet sn = (VarSnippet) varKey(assertEval("\"\".getClass().getDeclaredMethod(\"hashCode\");")); |
|
77 |
assertEquals(sn.typeName(), "java.lang.reflect.Method"); |
|
78 |
} |
|
79 |
||
80 |
public void testBounds() { |
|
81 |
assertEval("java.util.List<? extends String> list1 = java.util.Arrays.asList(\"\");"); |
|
82 |
VarSnippet sn1 = (VarSnippet) varKey(assertEval("list1.iterator().next()")); |
|
83 |
assertEquals(sn1.typeName(), "String"); |
|
84 |
assertEval("java.util.List<? super String> list2 = java.util.Arrays.asList(\"\");"); |
|
85 |
VarSnippet sn2 = (VarSnippet) varKey(assertEval("list2.iterator().next()")); |
|
86 |
assertEquals(sn2.typeName(), "Object"); |
|
87 |
assertEval("java.util.List<?> list3 = java.util.Arrays.asList(\"\");"); |
|
88 |
VarSnippet sn3 = (VarSnippet) varKey(assertEval("list3.iterator().next()")); |
|
89 |
assertEquals(sn3.typeName(), "Object"); |
|
90 |
assertEval("class Test1<X extends CharSequence> { public X get() { return null; } }"); |
|
34750
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
91 |
Snippet x = varKey(assertEval("Test1<?> test1 = new Test1<>();")); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
92 |
VarSnippet sn4 = (VarSnippet) varKey(assertEval("test1.get()")); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
93 |
assertEquals(sn4.typeName(), "Object"); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
94 |
assertEval("class Test2<X extends Number & CharSequence> { public X get() { return null; } }"); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
95 |
assertEval("Test2<?> test2 = new Test2<>();"); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
96 |
VarSnippet sn5 = (VarSnippet) varKey(assertEval("test2.get()")); |
33362 | 97 |
assertEquals(sn5.typeName(), "Object"); |
34750
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
98 |
assertEval("class Test3<T> { T[][] get() { return null; } }", added(VALID)); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
99 |
assertEval("Test3<? extends String> test3 = new Test3<>();"); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
100 |
VarSnippet sn6 = (VarSnippet) varKey(assertEval("test3.get()")); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
101 |
assertEquals(sn6.typeName(), "String[][]"); |
33362 | 102 |
} |
103 |
} |