author | jlahoda |
Wed, 18 May 2016 21:00:43 +0200 | |
changeset 38521 | f2fe39ab9256 |
parent 36778 | e04318f39f92 |
child 39182 | d4487b864f64 |
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 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
32 |
* @build KullaTesting TestingInputStream Compiler |
36160 | 33 |
* @run testng ComputeFQNsTest |
34 |
*/ |
|
35 |
||
36 |
import java.io.Writer; |
|
37 |
import java.nio.file.Files; |
|
38 |
import java.nio.file.Path; |
|
39 |
import java.nio.file.Paths; |
|
40 |
import java.util.Arrays; |
|
41 |
||
42 |
import jdk.jshell.SourceCodeAnalysis.QualifiedNames; |
|
43 |
import static org.testng.Assert.*; |
|
44 |
import org.testng.annotations.Test; |
|
45 |
||
46 |
@Test |
|
47 |
public class ComputeFQNsTest extends KullaTesting { |
|
48 |
||
49 |
private final Compiler compiler = new Compiler(); |
|
50 |
private final Path outDir = Paths.get("ComputeFQNsTest"); |
|
51 |
||
52 |
public void testAddImport() throws Exception { |
|
53 |
compiler.compile(outDir, "package test1; public class TestClass { }", "package test2; public class TestClass { }"); |
|
54 |
String jarName = "test.jar"; |
|
55 |
compiler.jar(outDir, jarName, "test1/TestClass.class", "test2/TestClass.class"); |
|
56 |
addToClasspath(compiler.getPath(outDir).resolve(jarName)); |
|
57 |
||
58 |
assertInferredFQNs("LinkedList", "java.util.LinkedList"); |
|
59 |
assertInferredFQNs("ArrayList", "java.util.ArrayList"); |
|
60 |
assertInferredFQNs("TestClass", "test1.TestClass", "test2.TestClass"); |
|
61 |
assertInferredFQNs("CharSequence", "CharSequence".length(), true, "java.lang.CharSequence"); |
|
62 |
assertInferredFQNs("unresolvable"); |
|
63 |
assertInferredFQNs("void test(ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
64 |
assertInferredFQNs("void test(ArrayList l) throws InvocationTargetException", "InvocationTargetException".length(), false, "java.lang.reflect.InvocationTargetException"); |
|
65 |
assertInferredFQNs("void test(ArrayList l) { ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
66 |
assertInferredFQNs("<T extends ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
67 |
assertInferredFQNs("Object l = Arrays", "Arrays".length(), false, "java.util.Arrays"); |
|
68 |
assertInferredFQNs("class X<T extends ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
69 |
assertInferredFQNs("class X extends ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
70 |
assertInferredFQNs("class X extends java.util.ArrayList<TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
71 |
assertInferredFQNs("class X extends java.util.ArrayList<TypeMirror, TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
72 |
assertInferredFQNs("class X implements TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
73 |
assertInferredFQNs("class X implements TypeMirror, TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
74 |
assertInferredFQNs("class X implements java.util.List<TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
75 |
assertInferredFQNs("class X implements java.util.List<TypeMirror, TypeElement", "TypeElement".length(), false, "javax.lang.model.element.TypeElement"); |
|
76 |
assertInferredFQNs("class X { ArrayList", "ArrayList".length(), false, "java.util.ArrayList"); |
|
77 |
} |
|
78 |
||
36164
8ced04acb5e0
8150874: Disable the ComputeFQNsTest.testSuspendIndexing test
jlahoda
parents:
36160
diff
changeset
|
79 |
@Test(enabled = false) //JDK-8150860 |
36160 | 80 |
public void testSuspendIndexing() throws Exception { |
81 |
compiler.compile(outDir, "package test; public class FQNTest { }"); |
|
82 |
String jarName = "test.jar"; |
|
83 |
compiler.jar(outDir, jarName, "test/FQNTest.class"); |
|
84 |
Path continueMarkFile = outDir.resolve("continuemark").toAbsolutePath(); |
|
85 |
Files.createDirectories(continueMarkFile.getParent()); |
|
86 |
try (Writer w = Files.newBufferedWriter(continueMarkFile)) {} |
|
87 |
||
88 |
Path runMarkFile = outDir.resolve("runmark").toAbsolutePath(); |
|
89 |
Files.deleteIfExists(runMarkFile); |
|
90 |
||
91 |
getState().sourceCodeAnalysis(); |
|
92 |
||
93 |
new Thread() { |
|
94 |
@Override public void run() { |
|
95 |
assertEval("{new java.io.FileOutputStream(\"" + runMarkFile.toAbsolutePath().toString() + "\").close();" + |
|
96 |
" while (java.nio.file.Files.exists(java.nio.file.Paths.get(\"" + continueMarkFile.toString() + "\"))) Thread.sleep(100); }"); |
|
97 |
} |
|
98 |
}.start(); |
|
99 |
||
100 |
while (!Files.exists(runMarkFile)) |
|
101 |
Thread.sleep(100); |
|
102 |
||
103 |
addToClasspath(compiler.getPath(outDir).resolve(jarName)); |
|
104 |
||
105 |
String code = "FQNTest"; |
|
106 |
||
107 |
QualifiedNames candidates = getAnalysis().listQualifiedNames(code, code.length()); |
|
108 |
||
109 |
assertEquals(candidates.getNames(), Arrays.asList(), "Input: " + code + ", candidates=" + candidates.getNames()); |
|
110 |
assertEquals(candidates.isUpToDate(), false, "Input: " + code + ", up-to-date=" + candidates.isUpToDate()); |
|
111 |
||
112 |
Files.delete(continueMarkFile); |
|
113 |
||
114 |
waitIndexingFinished(); |
|
115 |
||
116 |
candidates = getAnalysis().listQualifiedNames(code, code.length()); |
|
117 |
||
118 |
assertEquals(candidates.getNames(), Arrays.asList("test.FQNTest"), "Input: " + code + ", candidates=" + candidates.getNames()); |
|
119 |
assertEquals(true, candidates.isUpToDate(), "Input: " + code + ", up-to-date=" + candidates.isUpToDate()); |
|
120 |
} |
|
121 |
||
122 |
} |