author | stefank |
Thu, 07 Jun 2018 10:11:36 +0200 | |
changeset 50621 | 4216de02077e |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
46185
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
1 |
/* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
4 |
* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
8 |
* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
14 |
* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
18 |
* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
21 |
* questions. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
22 |
*/ |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
23 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
24 |
/* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
25 |
* @test |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
26 |
* @bug 8182270 |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
27 |
* @summary test non-eval Snippet analysis |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
28 |
* @build KullaTesting TestingInputStream |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
29 |
* @run testng AnalyzeSnippetTest |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
30 |
*/ |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
31 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
32 |
import java.io.ByteArrayOutputStream; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
33 |
import java.io.PrintStream; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
34 |
import java.util.List; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
35 |
import jdk.jshell.Snippet; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
36 |
import jdk.jshell.DeclarationSnippet; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
37 |
import org.testng.annotations.Test; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
38 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
39 |
import jdk.jshell.JShell; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
40 |
import jdk.jshell.MethodSnippet; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
41 |
import static org.testng.Assert.assertFalse; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
42 |
import static org.testng.Assert.assertTrue; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
43 |
import static org.testng.Assert.assertEquals; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
44 |
import org.testng.annotations.AfterMethod; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
45 |
import org.testng.annotations.BeforeMethod; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
46 |
import jdk.jshell.ErroneousSnippet; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
47 |
import jdk.jshell.ExpressionSnippet; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
48 |
import jdk.jshell.ImportSnippet; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
49 |
import jdk.jshell.Snippet.SubKind; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
50 |
import jdk.jshell.SourceCodeAnalysis; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
51 |
import jdk.jshell.StatementSnippet; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
52 |
import jdk.jshell.TypeDeclSnippet; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
53 |
import jdk.jshell.VarSnippet; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
54 |
import static jdk.jshell.Snippet.SubKind.*; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
55 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
56 |
@Test |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
57 |
public class AnalyzeSnippetTest { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
58 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
59 |
JShell state; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
60 |
SourceCodeAnalysis sca; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
61 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
62 |
@BeforeMethod |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
63 |
public void setUp() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
64 |
state = JShell.builder() |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
65 |
.out(new PrintStream(new ByteArrayOutputStream())) |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
66 |
.err(new PrintStream(new ByteArrayOutputStream())) |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
67 |
.build(); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
68 |
sca = state.sourceCodeAnalysis(); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
69 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
70 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
71 |
@AfterMethod |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
72 |
public void tearDown() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
73 |
if (state != null) { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
74 |
state.close(); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
75 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
76 |
state = null; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
77 |
sca = null; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
78 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
79 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
80 |
public void testImport() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
81 |
ImportSnippet sn = (ImportSnippet) assertSnippet("import java.util.List;", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
82 |
SubKind.SINGLE_TYPE_IMPORT_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
83 |
assertEquals(sn.name(), "List"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
84 |
sn = (ImportSnippet) assertSnippet("import static java.nio.file.StandardOpenOption.CREATE;", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
85 |
SubKind.SINGLE_STATIC_IMPORT_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
86 |
assertTrue(sn.isStatic()); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
87 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
88 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
89 |
public void testClass() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
90 |
TypeDeclSnippet sn = (TypeDeclSnippet) assertSnippet("class C {}", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
91 |
SubKind.CLASS_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
92 |
assertEquals(sn.name(), "C"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
93 |
sn = (TypeDeclSnippet) assertSnippet("enum EE {A, B , C}", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
94 |
SubKind.ENUM_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
95 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
96 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
97 |
public void testMethod() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
98 |
MethodSnippet sn = (MethodSnippet) assertSnippet("int m(int x) { return x + x; }", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
99 |
SubKind.METHOD_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
100 |
assertEquals(sn.name(), "m"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
101 |
assertEquals(sn.signature(), "(int)int"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
102 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
103 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
104 |
public void testVar() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
105 |
VarSnippet sn = (VarSnippet) assertSnippet("int i;", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
106 |
SubKind.VAR_DECLARATION_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
107 |
assertEquals(sn.name(), "i"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
108 |
assertEquals(sn.typeName(), "int"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
109 |
sn = (VarSnippet) assertSnippet("int jj = 6;", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
110 |
SubKind.VAR_DECLARATION_WITH_INITIALIZER_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
111 |
sn = (VarSnippet) assertSnippet("2 + 2", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
112 |
SubKind.TEMP_VAR_EXPRESSION_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
113 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
114 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
115 |
public void testExpression() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
116 |
state.eval("int aa = 10;"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
117 |
ExpressionSnippet sn = (ExpressionSnippet) assertSnippet("aa", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
118 |
SubKind.VAR_VALUE_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
119 |
assertEquals(sn.name(), "aa"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
120 |
assertEquals(sn.typeName(), "int"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
121 |
sn = (ExpressionSnippet) assertSnippet("aa;", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
122 |
SubKind.VAR_VALUE_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
123 |
assertEquals(sn.name(), "aa"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
124 |
assertEquals(sn.typeName(), "int"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
125 |
sn = (ExpressionSnippet) assertSnippet("aa = 99", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
126 |
SubKind.ASSIGNMENT_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
127 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
128 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
129 |
public void testStatement() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
130 |
StatementSnippet sn = (StatementSnippet) assertSnippet("System.out.println(33)", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
131 |
SubKind.STATEMENT_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
132 |
sn = (StatementSnippet) assertSnippet("if (true) System.out.println(33);", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
133 |
SubKind.STATEMENT_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
134 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
135 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
136 |
public void testErroneous() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
137 |
ErroneousSnippet sn = (ErroneousSnippet) assertSnippet("+++", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
138 |
SubKind.UNKNOWN_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
139 |
sn = (ErroneousSnippet) assertSnippet("abc", |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
140 |
SubKind.UNKNOWN_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
141 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
142 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
143 |
public void testNoStateChange() { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
144 |
assertSnippet("int a = 5;", SubKind.VAR_DECLARATION_WITH_INITIALIZER_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
145 |
assertSnippet("a", SubKind.UNKNOWN_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
146 |
VarSnippet vsn = (VarSnippet) state.eval("int aa = 10;").get(0).snippet(); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
147 |
assertSnippet("++aa;", SubKind.TEMP_VAR_EXPRESSION_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
148 |
assertEquals(state.varValue(vsn), "10"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
149 |
assertSnippet("class CC {}", SubKind.CLASS_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
150 |
assertSnippet("new CC();", SubKind.UNKNOWN_SUBKIND); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
151 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
152 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
153 |
private Snippet assertSnippet(String input, SubKind sk) { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
154 |
List<Snippet> sns = sca.sourceToSnippets(input); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
155 |
assertEquals(sns.size(), 1, "snippet count"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
156 |
Snippet sn = sns.get(0); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
157 |
assertEquals(sn.id(), "*UNASSOCIATED*"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
158 |
assertEquals(sn.subKind(), sk); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
159 |
return sn; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
160 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
161 |
} |