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
|
|
26 |
* @summary Test the ignoring of comments and certain modifiers
|
|
27 |
* @build KullaTesting TestingInputStream
|
|
28 |
* @run testng IgnoreTest
|
|
29 |
*/
|
|
30 |
|
|
31 |
import org.testng.annotations.Test;
|
|
32 |
|
|
33 |
import jdk.jshell.MethodSnippet;
|
|
34 |
import jdk.jshell.TypeDeclSnippet;
|
|
35 |
import jdk.jshell.VarSnippet;
|
|
36 |
import static jdk.jshell.Snippet.Status.VALID;
|
|
37 |
import static jdk.jshell.Snippet.SubKind.*;
|
|
38 |
|
|
39 |
@Test
|
|
40 |
public class IgnoreTest extends KullaTesting {
|
|
41 |
|
|
42 |
public void testComment() {
|
|
43 |
assertVarKeyMatch("//t1\n int//t2\n x//t3\n =//t4\n 12//t5\n ;//t6\n",
|
|
44 |
true, "x", VAR_DECLARATION_WITH_INITIALIZER_SUBKIND, "int", added(VALID));
|
|
45 |
assertVarKeyMatch("//t1\n int//t2\n y//t3\n =//t4\n 12//t5\n ;//t6",
|
|
46 |
true, "y", VAR_DECLARATION_WITH_INITIALIZER_SUBKIND, "int", added(VALID));
|
|
47 |
assertDeclarationKeyMatch(" //t0\n" +
|
|
48 |
" int//t0\n" +
|
|
49 |
" f//t0\n" +
|
|
50 |
" (//t0\n" +
|
|
51 |
" int x//t1\n" +
|
|
52 |
" ) {//t2\n" +
|
|
53 |
" return x+//t3\n" +
|
|
54 |
" x//t4\n" +
|
|
55 |
" ;//t5\n" +
|
|
56 |
" }//t6",
|
|
57 |
false, "f", METHOD_SUBKIND, added(VALID));
|
|
58 |
}
|
|
59 |
|
|
60 |
public void testVarModifier() {
|
|
61 |
VarSnippet x1 = (VarSnippet) assertDeclareWarn1("public int x1;", "jdk.eval.warn.illegal.modifiers");
|
|
62 |
assertVariableDeclSnippet(x1, "x1", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 1);
|
|
63 |
VarSnippet x2 = (VarSnippet) assertDeclareWarn1("protected int x2;", "jdk.eval.warn.illegal.modifiers");
|
|
64 |
assertVariableDeclSnippet(x2, "x2", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 1);
|
|
65 |
VarSnippet x3 = (VarSnippet) assertDeclareWarn1("private int x3;", "jdk.eval.warn.illegal.modifiers");
|
|
66 |
assertVariableDeclSnippet(x3, "x3", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 1);
|
|
67 |
VarSnippet x4 = (VarSnippet) assertDeclareWarn1("static int x4;", "jdk.eval.warn.illegal.modifiers");
|
|
68 |
assertVariableDeclSnippet(x4, "x4", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 1);
|
|
69 |
VarSnippet x5 = (VarSnippet) assertDeclareWarn1("final int x5;", "jdk.eval.warn.illegal.modifiers");
|
|
70 |
assertVariableDeclSnippet(x5, "x5", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 1);
|
|
71 |
}
|
|
72 |
|
|
73 |
public void testMethodModifier() {
|
|
74 |
MethodSnippet m1 = (MethodSnippet) assertDeclareWarn1("public void m1() {}", "jdk.eval.warn.illegal.modifiers");
|
|
75 |
assertMethodDeclSnippet(m1, "m1", "()void", VALID, 0, 1);
|
|
76 |
MethodSnippet m2 = (MethodSnippet) assertDeclareWarn1("protected void m2() {}", "jdk.eval.warn.illegal.modifiers");
|
|
77 |
assertMethodDeclSnippet(m2, "m2", "()void", VALID, 0, 1);
|
|
78 |
MethodSnippet m3 = (MethodSnippet) assertDeclareWarn1("private void m3() {}", "jdk.eval.warn.illegal.modifiers");
|
|
79 |
assertMethodDeclSnippet(m3, "m3", "()void", VALID, 0, 1);
|
|
80 |
MethodSnippet m4 = (MethodSnippet) assertDeclareWarn1("static void m4() {}", "jdk.eval.warn.illegal.modifiers");
|
|
81 |
assertMethodDeclSnippet(m4, "m4", "()void", VALID, 0, 1);
|
|
82 |
MethodSnippet m5 = (MethodSnippet) assertDeclareWarn1("final void m5() {}", "jdk.eval.warn.illegal.modifiers");
|
|
83 |
assertMethodDeclSnippet(m5, "m5", "()void", VALID, 0, 1);
|
|
84 |
}
|
|
85 |
|
|
86 |
public void testClassModifier() {
|
|
87 |
TypeDeclSnippet c1 = (TypeDeclSnippet) assertDeclareWarn1("public class C1 {}", "jdk.eval.warn.illegal.modifiers");
|
|
88 |
assertTypeDeclSnippet(c1, "C1", VALID, CLASS_SUBKIND, 0, 1);
|
|
89 |
TypeDeclSnippet c2 = (TypeDeclSnippet) assertDeclareWarn1("protected class C2 {}", "jdk.eval.warn.illegal.modifiers");
|
|
90 |
assertTypeDeclSnippet(c2, "C2", VALID, CLASS_SUBKIND, 0, 1);
|
|
91 |
TypeDeclSnippet c3 = (TypeDeclSnippet) assertDeclareWarn1("private class C3 {}", "jdk.eval.warn.illegal.modifiers");
|
|
92 |
assertTypeDeclSnippet(c3, "C3", VALID, CLASS_SUBKIND, 0, 1);
|
|
93 |
TypeDeclSnippet c4 = (TypeDeclSnippet) assertDeclareWarn1("static class C4 {}", "jdk.eval.warn.illegal.modifiers");
|
|
94 |
assertTypeDeclSnippet(c4, "C4", VALID, CLASS_SUBKIND, 0, 1);
|
|
95 |
TypeDeclSnippet c5 = (TypeDeclSnippet) assertDeclareWarn1("final class C5 {}", "jdk.eval.warn.illegal.modifiers");
|
|
96 |
assertTypeDeclSnippet(c5, "C5", VALID, CLASS_SUBKIND, 0, 1);
|
|
97 |
}
|
|
98 |
|
|
99 |
public void testInsideModifier() {
|
|
100 |
assertEval("import static java.lang.reflect.Modifier.*;");
|
|
101 |
assertEval("class C {"
|
|
102 |
+ "public int z;"
|
|
103 |
+ "final int f = 3;"
|
|
104 |
+ "protected int a;"
|
|
105 |
+ "private void m() {}"
|
|
106 |
+ "static void b() {}"
|
|
107 |
+ "}");
|
|
108 |
assertEval("C.class.getDeclaredField(\"z\").getModifiers() == PUBLIC;", "true");
|
|
109 |
assertEval("C.class.getDeclaredField(\"f\").getModifiers() == FINAL;", "true");
|
|
110 |
assertEval("C.class.getDeclaredField(\"a\").getModifiers() == PROTECTED;", "true");
|
|
111 |
assertEval("C.class.getDeclaredMethod(\"m\").getModifiers() == PRIVATE;", "true");
|
|
112 |
assertEval("C.class.getDeclaredMethod(\"b\").getModifiers() == STATIC;", "true");
|
|
113 |
}
|
|
114 |
}
|