author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46924 | langtools/test/jdk/jshell/ComputeFQNsTest.java@58445145ef13 |
permissions | -rw-r--r-- |
36160 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 8131027 |
|
27 |
* @summary Test Get FQNs |
|
28 |
* @library /tools/lib |
|
36526 | 29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39807
diff
changeset
|
31 |
* jdk.jshell/jdk.jshell:open |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
32 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
33 |
* @build KullaTesting TestingInputStream Compiler |
36160 | 34 |
* @run testng ComputeFQNsTest |
35 |
*/ |
|
36 |
||
37 |
import java.io.Writer; |
|
38 |
import java.nio.file.Files; |
|
39 |
import java.nio.file.Path; |
|
40 |
import java.nio.file.Paths; |
|
41 |
import java.util.Arrays; |
|
42 |
||
43 |
import jdk.jshell.SourceCodeAnalysis.QualifiedNames; |
|
44 |
import static org.testng.Assert.*; |
|
45 |
import org.testng.annotations.Test; |
|
46 |
||
47 |
@Test |
|
48 |
public class ComputeFQNsTest extends KullaTesting { |
|
49 |
||
50 |
private final Compiler compiler = new Compiler(); |
|
51 |
private final Path outDir = Paths.get("ComputeFQNsTest"); |
|
52 |
||
53 |
public void testAddImport() throws Exception { |
|
46924
58445145ef13
8186636: JShell tests: jtreg_4.2-b08 breaks ComputeFQNsTest.testAddImport()
rfield
parents:
42407
diff
changeset
|
54 |
compiler.compile(outDir, "package test1; public class FQNTestClass { }", "package test2; public class FQNTestClass { }"); |
36160 | 55 |
String jarName = "test.jar"; |
46924
58445145ef13
8186636: JShell tests: jtreg_4.2-b08 breaks ComputeFQNsTest.testAddImport()
rfield
parents:
42407
diff
changeset
|
56 |
compiler.jar(outDir, jarName, "test1/FQNTestClass.class", "test2/FQNTestClass.class"); |
36160 | 57 |
addToClasspath(compiler.getPath(outDir).resolve(jarName)); |
58 |
||
59 |
assertInferredFQNs("LinkedList", "java.util.LinkedList"); |
|
60 |
assertInferredFQNs("ArrayList", "java.util.ArrayList"); |
|
46924
58445145ef13
8186636: JShell tests: jtreg_4.2-b08 breaks ComputeFQNsTest.testAddImport()
rfield
parents:
42407
diff
changeset
|
61 |
assertInferredFQNs("FQNTestClass", "test1.FQNTestClass", "test2.FQNTestClass"); |
36160 | 62 |
assertInferredFQNs("CharSequence", "CharSequence".length(), true, "java.lang.CharSequence"); |
63 |
assertInferredFQNs("unresolvable"); |
|
64 |
assertInferredFQNs("void test(ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
65 |
assertInferredFQNs("void test(ArrayList l) throws InvocationTargetException", "InvocationTargetException".length(), false, "java.lang.reflect.InvocationTargetException"); |
|
66 |
assertInferredFQNs("void test(ArrayList l) { ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
67 |
assertInferredFQNs("<T extends ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
68 |
assertInferredFQNs("Object l = Arrays", "Arrays".length(), false, "java.util.Arrays"); |
|
69 |
assertInferredFQNs("class X<T extends ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
70 |
assertInferredFQNs("class X extends ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
71 |
assertInferredFQNs("class X extends java.util.ArrayList<TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
72 |
assertInferredFQNs("class X extends java.util.ArrayList<TypeMirror, TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
73 |
assertInferredFQNs("class X implements TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
74 |
assertInferredFQNs("class X implements TypeMirror, TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
75 |
assertInferredFQNs("class X implements java.util.List<TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
76 |
assertInferredFQNs("class X implements java.util.List<TypeMirror, TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
77 |
assertInferredFQNs("class X { ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
78 |
} |
|
79 |
||
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
39182
diff
changeset
|
80 |
@Test(enabled = false) //TODO 8161165 |
39182
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
81 |
public void testSuspendIndexing() throws Throwable { |
36160 | 82 |
compiler.compile(outDir, "package test; public class FQNTest { }"); |
83 |
String jarName = "test.jar"; |
|
84 |
compiler.jar(outDir, jarName, "test/FQNTest.class"); |
|
85 |
Path continueMarkFile = outDir.resolve("continuemark").toAbsolutePath(); |
|
86 |
Files.createDirectories(continueMarkFile.getParent()); |
|
87 |
try (Writer w = Files.newBufferedWriter(continueMarkFile)) {} |
|
88 |
||
89 |
Path runMarkFile = outDir.resolve("runmark").toAbsolutePath(); |
|
90 |
Files.deleteIfExists(runMarkFile); |
|
91 |
||
92 |
getState().sourceCodeAnalysis(); |
|
93 |
||
39182
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
94 |
Throwable[] evalException = new Throwable[1]; |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
95 |
|
36160 | 96 |
new Thread() { |
97 |
@Override public void run() { |
|
39182
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
98 |
try { |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
99 |
assertEval("{new java.io.FileOutputStream(\"" + runMarkFile.toAbsolutePath().toString().replace("\\", "\\\\") + "\").close();" + |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
100 |
" while (java.nio.file.Files.exists(java.nio.file.Paths.get(\"" + continueMarkFile.toAbsolutePath().toString().replace("\\", "\\\\") + "\"))) Thread.sleep(100); }"); |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
101 |
} catch (Throwable t) { |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
102 |
evalException[0] = t; |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
103 |
} |
36160 | 104 |
} |
105 |
}.start(); |
|
106 |
||
39182
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
107 |
while (true) { |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
108 |
if (Files.exists(runMarkFile)) |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
109 |
break; |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
110 |
try { |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
111 |
Thread.sleep(100); |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
112 |
} catch (Throwable t) { |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
113 |
if (evalException[0] != null) { |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
114 |
evalException[0].addSuppressed(t); |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
115 |
} else { |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
116 |
throw t; |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
117 |
} |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
118 |
} |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
119 |
if (evalException[0] != null) { |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
120 |
throw evalException[0]; |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
121 |
} |
d4487b864f64
8150860: Mach 5 tier1 test started failing - jdk/jshell/ComputeFQNsTest.java (after 8131027/8150814)
jlahoda
parents:
36778
diff
changeset
|
122 |
} |
36160 | 123 |
|
124 |
addToClasspath(compiler.getPath(outDir).resolve(jarName)); |
|
125 |
||
126 |
String code = "FQNTest"; |
|
127 |
||
128 |
QualifiedNames candidates = getAnalysis().listQualifiedNames(code, code.length()); |
|
129 |
||
130 |
assertEquals(candidates.getNames(), Arrays.asList(), "Input: " + code + ", candidates=" + candidates.getNames()); |
|
131 |
assertEquals(candidates.isUpToDate(), false, "Input: " + code + ", up-to-date=" + candidates.isUpToDate()); |
|
132 |
||
133 |
Files.delete(continueMarkFile); |
|
134 |
||
135 |
waitIndexingFinished(); |
|
136 |
||
137 |
candidates = getAnalysis().listQualifiedNames(code, code.length()); |
|
138 |
||
139 |
assertEquals(candidates.getNames(), Arrays.asList("test.FQNTest"), "Input: " + code + ", candidates=" + candidates.getNames()); |
|
140 |
assertEquals(true, candidates.isUpToDate(), "Input: " + code + ", up-to-date=" + candidates.isUpToDate()); |
|
141 |
} |
|
142 |
||
143 |
} |