author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 42822 | a84956e7ee4d |
permissions | -rw-r--r-- |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
1 |
/* |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
4 |
* |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
8 |
* |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
14 |
* |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
18 |
* |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
22 |
*/ |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
23 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
24 |
/* |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
25 |
* @test |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
26 |
* @summary tests for module declarations |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
27 |
* @library /tools/lib |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.main |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
30 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
31 |
* @run main ExportsUnexported |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
32 |
*/ |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
33 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
34 |
import java.nio.file.Path; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
36 |
import java.util.Arrays; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
37 |
import java.util.Collections; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
38 |
import java.util.List; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
39 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
40 |
import toolbox.JavacTask; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
41 |
import toolbox.Task; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
42 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
43 |
public class ExportsUnexported extends ModuleTestBase { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
44 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
45 |
public static void main(String... args) throws Exception { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
46 |
ExportsUnexported t = new ExportsUnexported(); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
47 |
t.runTests(); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
48 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
49 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
50 |
@Test |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
51 |
public void testLocations(Path base) throws Exception { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
52 |
String warningsTest = "package api;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
53 |
"import impl.impl.*;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
54 |
"@impl.impl^.DocAnn\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
55 |
"public abstract class Api<T extends impl.impl^.Cls&impl.impl^.Intf> extends impl.impl^.Cls implements impl.impl^.Intf, impl.impl^.NonDocAnn, impl.impl^.DocAnn {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
56 |
" public static <E extends impl.impl^.Cls&impl.impl^.Intf> impl.impl^.Cls m(impl.impl^.Intf i, impl.impl^.Cls c) throws impl.impl^.Exc { return null; }\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
57 |
" public static impl.impl^.Cls f;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
58 |
"}"; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
59 |
String noWarningsTest = "package api;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
60 |
"import impl.impl.*;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
61 |
"@impl.impl.NonDocAnn\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
62 |
"public abstract class Api {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
63 |
" private static abstract class I <T extends impl.impl.Cls&impl.impl.Intf> extends impl.impl.Cls implements impl.impl.Intf, impl.impl.NonDocAnn, impl.impl.DocAnn {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
64 |
" public static abstract class II <T extends impl.impl.Cls&impl.impl.Intf> extends impl.impl.Cls implements impl.impl.Intf, impl.impl.NonDocAnn, impl.impl.DocAnn { }\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
65 |
" public static <E extends impl.impl.Cls&impl.impl.Intf> impl.impl.Cls m(impl.impl.Intf i, impl.impl.Cls c) throws impl.impl.Exc { return null; }\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
66 |
" public static impl.impl.Cls f;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
67 |
" }\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
68 |
" private static <E extends impl.impl.Cls&impl.impl.Intf> impl.impl.Cls m(impl.impl.Intf i, impl.impl.Cls c) throws impl.impl.Exc { return null; }\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
69 |
" private static impl.impl.Cls f1;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
70 |
" public static void m() { new impl.impl.Cls(); }\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
71 |
" public static Object f2 = new impl.impl.Cls();\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
72 |
"}"; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
73 |
for (String genericTest : new String[] {warningsTest, noWarningsTest}) { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
74 |
for (String test : new String[] {genericTest, genericTest.replaceAll("impl\\.impl\\^.([A-Za-z])", "^$1").replaceAll("impl\\.impl\\.([A-Za-z])", "$1")}) { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
75 |
System.err.println("testing: " + test); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
76 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
77 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
78 |
Path src_m1 = src.resolve("m1x"); |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
79 |
StringBuilder testCode = new StringBuilder(); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
80 |
List<String> expectedLog = new ArrayList<>(); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
81 |
int line = 1; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
82 |
int col = 1; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
83 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
84 |
for (int i = 0; i < test.length(); i++) { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
85 |
char c = test.charAt(i); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
86 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
87 |
if (c == '^') { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
88 |
StringBuilder typeName = new StringBuilder(); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
89 |
for (int j = i + 1 + (test.charAt(i + 1) == '.' ? 1 : 0); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
90 |
j < test.length() && Character.isJavaIdentifierPart(test.charAt(j)); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
91 |
j++) { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
92 |
typeName.append(test.charAt(j)); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
93 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
94 |
String kindName; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
95 |
switch (typeName.toString()) { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
96 |
case "Exc": case "DocAnn": case "NonDocAnn": |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
97 |
case "Cls": kindName = "kindname.class"; break; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
98 |
case "Intf": kindName = "kindname.interface"; break; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
99 |
default: |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
100 |
throw new AssertionError(typeName.toString()); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
101 |
} |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
102 |
expectedLog.add("Api.java:" + line + ":" + col |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
103 |
+ ": compiler.warn.leaks.not.accessible.unexported: " |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
104 |
+ kindName + ", impl.impl." + typeName + ", m1x"); |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
105 |
continue; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
106 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
107 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
108 |
if (c == '\n') { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
109 |
line++; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
110 |
col = 0; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
111 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
112 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
113 |
testCode.append(c); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
114 |
col++; |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
115 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
116 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
117 |
if (!expectedLog.isEmpty()) { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
118 |
expectedLog.add("" + expectedLog.size() + " warning" + (expectedLog.size() == 1 ? "" : "s")); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
119 |
expectedLog.add("- compiler.err.warnings.and.werror"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
120 |
expectedLog.add("1 error"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
121 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
122 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
123 |
Collections.sort(expectedLog); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
124 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
125 |
tb.writeJavaFiles(src_m1, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
126 |
"module m1x { exports api; }", |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
127 |
testCode.toString(), |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
128 |
"package impl.impl; public class Cls { }", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
129 |
"package impl.impl; public class Exc extends Exception { }", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
130 |
"package impl.impl; public interface Intf { }", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
131 |
"package impl.impl; @java.lang.annotation.Documented public @interface DocAnn { }", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
132 |
"package impl.impl; public @interface NonDocAnn { }"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
133 |
Path classes = base.resolve("classes"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
134 |
tb.createDirectories(classes); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
135 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
136 |
List<String> log = new JavacTask(tb) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
137 |
.options("-XDrawDiagnostics", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
138 |
"-Werror", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
139 |
"--module-source-path", src.toString(), |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
140 |
"-Xlint:exports") |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
141 |
.outdir(classes) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
142 |
.files(findJavaFiles(src)) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
143 |
.run(expectedLog.isEmpty() ? Task.Expect.SUCCESS : Task.Expect.FAIL) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
144 |
.writeAll() |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
145 |
.getOutputLines(Task.OutputKind.DIRECT); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
146 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
147 |
log = new ArrayList<>(log); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
148 |
Collections.sort(log); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
149 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
150 |
if (expectedLog.isEmpty() ? !log.equals(Arrays.asList("")) : !log.equals(expectedLog)) { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
151 |
throw new Exception("expected output not found in: " + log + "; " + expectedLog); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
152 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
153 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
154 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
155 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
156 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
157 |
@Test |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
158 |
public void testAccessibleToSpecificOrAll(Path base) throws Exception { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
159 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
160 |
Path src_lib1 = src.resolve("lib1x"); |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
161 |
tb.writeJavaFiles(src_lib1, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
162 |
"module lib1x { exports lib1; }", |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
163 |
"package lib1; public class Lib1 {}"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
164 |
Path src_lib2 = src.resolve("lib2x"); |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
165 |
tb.writeJavaFiles(src_lib2, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
166 |
"module lib2x { exports lib2; }", |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
167 |
"package lib2; public class Lib2 {}"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
168 |
Path src_api = src.resolve("api"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
169 |
tb.writeJavaFiles(src_api, |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
170 |
"module api {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
171 |
" exports api;\n" + |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
172 |
" exports qapi1 to qual1x;\n" + |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
173 |
" exports qapi2 to qual1x, qual2x;\n" + |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
174 |
" requires transitive lib1x;\n" + |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
175 |
" requires lib2x;\n" + |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
176 |
"}\n", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
177 |
"package api;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
178 |
"public class Api {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
179 |
" public lib1.Lib1 lib1;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
180 |
" public lib2.Lib2 lib2;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
181 |
" public qapi1.QApi1 qapi1;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
182 |
" public impl.Impl impl;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
183 |
"}", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
184 |
"package qapi1;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
185 |
"public class QApi1 {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
186 |
" public qapi2.QApi2 qapi2;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
187 |
"}", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
188 |
"package qapi2;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
189 |
"public class QApi2 {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
190 |
" public qapi1.QApi1 qapi1;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
191 |
"}", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
192 |
"package impl;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
193 |
"public class Impl {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
194 |
"}"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
195 |
Path src_qual1 = src.resolve("qual1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
196 |
tb.writeJavaFiles(src_qual1, "module qual1x { }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
197 |
Path src_qual2 = src.resolve("qual2x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
198 |
tb.writeJavaFiles(src_qual2, "module qual2x { }"); |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
199 |
Path classes = base.resolve("classes"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
200 |
tb.createDirectories(classes); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
201 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
202 |
List<String> log = new JavacTask(tb) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
203 |
.options("-XDrawDiagnostics", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
204 |
"-Werror", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
205 |
"--module-source-path", src.toString(), |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
206 |
"-Xlint:exports") |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
207 |
.outdir(classes) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
208 |
.files(findJavaFiles(src)) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
209 |
.run(Task.Expect.FAIL) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
210 |
.writeAll() |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
211 |
.getOutputLines(Task.OutputKind.DIRECT); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
212 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
213 |
List<String> expected = Arrays.asList( |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
214 |
"Api.java:4:16: compiler.warn.leaks.not.accessible.not.required.transitive: kindname.class, lib2.Lib2, lib2x", |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
215 |
"Api.java:5:17: compiler.warn.leaks.not.accessible.unexported.qualified: kindname.class, qapi1.QApi1, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
216 |
"Api.java:6:16: compiler.warn.leaks.not.accessible.unexported: kindname.class, impl.Impl, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
217 |
"- compiler.err.warnings.and.werror", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
218 |
"1 error", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
219 |
"3 warnings" |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
220 |
); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
221 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
222 |
if (!log.equals(expected)) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
223 |
throw new Exception("expected output not found"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
224 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
225 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
226 |
@Test |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
227 |
public void testNestedClasses(Path base) throws Exception { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
228 |
Path src = base.resolve("src"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
229 |
Path src_api = src.resolve("api"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
230 |
tb.writeJavaFiles(src_api, |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
231 |
"module api {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
232 |
" exports api;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
233 |
"}\n", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
234 |
"package api;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
235 |
"import impl.Impl.Nested;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
236 |
"public class Api {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
237 |
" public impl.Impl impl1;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
238 |
" public impl.Impl.Nested impl2;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
239 |
" public Nested impl3;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
240 |
"}", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
241 |
"package impl;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
242 |
"public class Impl {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
243 |
" public static class Nested {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
244 |
" }\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
245 |
"}"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
246 |
Path classes = base.resolve("classes"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
247 |
tb.createDirectories(classes); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
248 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
249 |
List<String> log = new JavacTask(tb) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
250 |
.options("-XDrawDiagnostics", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
251 |
"-Werror", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
252 |
"--module-source-path", src.toString(), |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
253 |
"-Xlint:exports") |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
254 |
.outdir(classes) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
255 |
.files(findJavaFiles(src)) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
256 |
.run(Task.Expect.FAIL) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
257 |
.writeAll() |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
258 |
.getOutputLines(Task.OutputKind.DIRECT); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
259 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
260 |
List<String> expected = Arrays.asList( |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
261 |
"Api.java:4:16: compiler.warn.leaks.not.accessible.unexported: kindname.class, impl.Impl, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
262 |
"Api.java:5:16: compiler.warn.leaks.not.accessible.unexported: kindname.class, impl.Impl, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
263 |
"Api.java:6:12: compiler.warn.leaks.not.accessible.unexported: kindname.class, impl.Impl.Nested, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
264 |
"- compiler.err.warnings.and.werror", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
265 |
"1 error", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
266 |
"3 warnings" |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
267 |
); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
268 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
269 |
if (!log.equals(expected)) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
270 |
throw new Exception("expected output not found"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
271 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
272 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
273 |
@Test |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
274 |
public void testProtectedAndInaccessible(Path base) throws Exception { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
275 |
Path src = base.resolve("src"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
276 |
Path src_api = src.resolve("api"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
277 |
tb.writeJavaFiles(src_api, |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
278 |
"module api {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
279 |
" exports api;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
280 |
"}\n", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
281 |
"package api;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
282 |
"public class Api extends PackagePrivateClass<PackagePrivateInterface> implements PackagePrivateInterface<PackagePrivateClass> {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
283 |
" protected PackagePrivateClass<?> f1;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
284 |
" protected PackagePrivateInterface<?> f2;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
285 |
" protected Inner f3;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
286 |
" protected PrivateInner f4;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
287 |
" protected impl.Impl f5;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
288 |
" public static class InnerClass extends PrivateInner {}\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
289 |
" protected static class Inner {}\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
290 |
" private static class PrivateInner {}\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
291 |
"}\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
292 |
"class PackagePrivateClass<T> {}\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
293 |
"interface PackagePrivateInterface<T> {}", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
294 |
"package impl;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
295 |
"public class Impl {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
296 |
"}"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
297 |
Path classes = base.resolve("classes"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
298 |
tb.createDirectories(classes); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
299 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
300 |
List<String> log = new JavacTask(tb) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
301 |
.options("-XDrawDiagnostics", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
302 |
"-Werror", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
303 |
"--module-source-path", src.toString(), |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
304 |
"-Xlint:exports") |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
305 |
.outdir(classes) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
306 |
.files(findJavaFiles(src)) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
307 |
.run(Task.Expect.FAIL) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
308 |
.writeAll() |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
309 |
.getOutputLines(Task.OutputKind.DIRECT); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
310 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
311 |
List<String> expected = Arrays.asList( |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
312 |
"Api.java:2:46: compiler.warn.leaks.not.accessible: kindname.interface, api.PackagePrivateInterface, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
313 |
"Api.java:2:106: compiler.warn.leaks.not.accessible: kindname.class, api.PackagePrivateClass, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
314 |
"Api.java:3:15: compiler.warn.leaks.not.accessible: kindname.class, api.PackagePrivateClass, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
315 |
"Api.java:4:15: compiler.warn.leaks.not.accessible: kindname.interface, api.PackagePrivateInterface, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
316 |
"Api.java:6:15: compiler.warn.leaks.not.accessible: kindname.class, api.Api.PrivateInner, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
317 |
"Api.java:7:19: compiler.warn.leaks.not.accessible.unexported: kindname.class, impl.Impl, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
318 |
"- compiler.err.warnings.and.werror", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
319 |
"1 error", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
320 |
"6 warnings" |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
321 |
); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
322 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
323 |
if (!log.equals(expected)) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
324 |
throw new Exception("expected output not found"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
325 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
326 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
327 |
@Test |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
328 |
public void testSuppressResetProperly(Path base) throws Exception { |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
329 |
Path src = base.resolve("src"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
330 |
Path src_api = src.resolve("api"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
331 |
tb.writeJavaFiles(src_api, |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
332 |
"module api {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
333 |
" exports api;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
334 |
"}\n", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
335 |
"package api;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
336 |
"public class Api {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
337 |
" @SuppressWarnings(\"exports\")\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
338 |
" public PackagePrivateClass f1;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
339 |
" public PackagePrivateClass f2;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
340 |
" @SuppressWarnings(\"exports\")\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
341 |
" public void t() {}\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
342 |
" public PackagePrivateClass f3;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
343 |
" @SuppressWarnings(\"exports\")\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
344 |
" public static class C {\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
345 |
" public PackagePrivateClass f4;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
346 |
" }\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
347 |
" public PackagePrivateClass f5;\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
348 |
"}\n" + |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
349 |
"class PackagePrivateClass<T> {}\n"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
350 |
Path classes = base.resolve("classes"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
351 |
tb.createDirectories(classes); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
352 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
353 |
List<String> log = new JavacTask(tb) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
354 |
.options("-XDrawDiagnostics", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
355 |
"-Werror", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
356 |
"--module-source-path", src.toString(), |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
357 |
"-Xlint:exports") |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
358 |
.outdir(classes) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
359 |
.files(findJavaFiles(src)) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
360 |
.run(Task.Expect.FAIL) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
361 |
.writeAll() |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
362 |
.getOutputLines(Task.OutputKind.DIRECT); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
363 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
364 |
List<String> expected = Arrays.asList( |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
365 |
"Api.java:5:12: compiler.warn.leaks.not.accessible: kindname.class, api.PackagePrivateClass, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
366 |
"Api.java:8:12: compiler.warn.leaks.not.accessible: kindname.class, api.PackagePrivateClass, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
367 |
"Api.java:13:12: compiler.warn.leaks.not.accessible: kindname.class, api.PackagePrivateClass, api", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
368 |
"- compiler.err.warnings.and.werror", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
369 |
"1 error", |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
370 |
"3 warnings" |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
371 |
); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
372 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
373 |
if (!log.equals(expected)) |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
374 |
throw new Exception("expected output not found"); |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
375 |
} |
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
376 |
|
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
diff
changeset
|
377 |
} |