Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/jshell/JShellQueryTest.java
40931 views
1
/*
2
* Copyright (c) 2016, 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
26
* @bug 8143964
27
* @summary test queries to the JShell that return Streams
28
* @build KullaTesting
29
* @run testng JShellQueryTest
30
*/
31
import jdk.jshell.Snippet;
32
import org.testng.annotations.Test;
33
34
import jdk.jshell.ImportSnippet;
35
import jdk.jshell.MethodSnippet;
36
import jdk.jshell.TypeDeclSnippet;
37
import jdk.jshell.VarSnippet;
38
import static java.util.stream.Collectors.joining;
39
import static org.testng.Assert.assertEquals;
40
41
@Test
42
public class JShellQueryTest extends KullaTesting {
43
44
public void testSnippets() {
45
assertStreamMatch(getState().snippets());
46
VarSnippet sx = varKey(assertEval("int x = 5;"));
47
VarSnippet sfoo = varKey(assertEval("String foo;"));
48
MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
49
MethodSnippet svv = methodKey(assertEval("void vv() { }"));
50
assertStreamMatch(getState().snippets(), sx, sfoo, smm, svv);
51
TypeDeclSnippet sc = classKey(assertEval("class C { }"));
52
TypeDeclSnippet si = classKey(assertEval("interface I { }"));
53
ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
54
assertStreamMatch(getState().snippets(), sx, sfoo, smm, svv, sc, si, simp);
55
}
56
57
public void testVars() {
58
assertStreamMatch(getState().variables());
59
VarSnippet sx = varKey(assertEval("int x = 5;"));
60
VarSnippet sfoo = varKey(assertEval("String foo;"));
61
MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
62
MethodSnippet svv = methodKey(assertEval("void vv() { }"));
63
assertStreamMatch(getState().variables(), sx, sfoo);
64
TypeDeclSnippet sc = classKey(assertEval("class C { }"));
65
TypeDeclSnippet si = classKey(assertEval("interface I { }"));
66
ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
67
assertStreamMatch(getState().variables(), sx, sfoo);
68
}
69
70
public void testMethods() {
71
assertStreamMatch(getState().methods());
72
VarSnippet sx = varKey(assertEval("int x = 5;"));
73
VarSnippet sfoo = varKey(assertEval("String foo;"));
74
MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
75
MethodSnippet svv = methodKey(assertEval("void vv() { }"));
76
TypeDeclSnippet sc = classKey(assertEval("class C { }"));
77
TypeDeclSnippet si = classKey(assertEval("interface I { }"));
78
ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
79
assertStreamMatch(getState().methods(), smm, svv);
80
}
81
82
public void testTypes() {
83
assertStreamMatch(getState().types());
84
VarSnippet sx = varKey(assertEval("int x = 5;"));
85
VarSnippet sfoo = varKey(assertEval("String foo;"));
86
MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
87
MethodSnippet svv = methodKey(assertEval("void vv() { }"));
88
TypeDeclSnippet sc = classKey(assertEval("class C { }"));
89
TypeDeclSnippet si = classKey(assertEval("interface I { }"));
90
ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
91
assertStreamMatch(getState().types(), sc, si);
92
}
93
94
public void testImports() {
95
assertStreamMatch(getState().imports());
96
VarSnippet sx = varKey(assertEval("int x = 5;"));
97
VarSnippet sfoo = varKey(assertEval("String foo;"));
98
MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
99
MethodSnippet svv = methodKey(assertEval("void vv() { }"));
100
TypeDeclSnippet sc = classKey(assertEval("class C { }"));
101
TypeDeclSnippet si = classKey(assertEval("interface I { }"));
102
ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
103
assertStreamMatch(getState().imports(), simp);
104
}
105
106
public void testDiagnostics() {
107
Snippet sx = varKey(assertEval("int x = 5;"));
108
assertStreamMatch(getState().diagnostics(sx));
109
Snippet broken = methodKey(assertEvalFail("int m() { blah(); return \"hello\"; }"));
110
String res = getState().diagnostics(broken)
111
.map(d -> d.getCode())
112
.collect(joining("+"));
113
assertEquals(res, "compiler.err.cant.resolve.location.args+compiler.err.prob.found.req");
114
}
115
116
public void testUnresolvedDependencies() {
117
VarSnippet sx = varKey(assertEval("int x = 5;"));
118
assertStreamMatch(getState().unresolvedDependencies(sx));
119
MethodSnippet unr = methodKey(getState().eval("void uu() { baz(); zips(); }"));
120
assertStreamMatch(getState().unresolvedDependencies(unr), "method zips()", "method baz()");
121
}
122
}
123
124