author | alanb |
Fri, 10 Feb 2017 09:06:10 +0000 | |
changeset 43767 | 9cff98a149cb |
parent 42822 | a84956e7ee4d |
child 45912 | 865870b7fe9b |
permissions | -rw-r--r-- |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
1 |
/* |
36526 | 2 |
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
4 |
* |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
32337 | 7 |
* published by the Free Software Foundation. |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
8 |
* |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
13 |
* accompanied this code). |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
14 |
* |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
18 |
* |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
21 |
* questions. |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
22 |
*/ |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
23 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
24 |
/* |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
25 |
* @test |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
26 |
* @bug 8003967 |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
27 |
* @summary detect and remove all mutable implicit static enum fields in langtools |
30846 | 28 |
* @modules jdk.jdeps/com.sun.tools.classfile |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27995
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.util |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
30 |
* @run main DetectMutableStaticFields |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
31 |
*/ |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
32 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
33 |
import java.io.File; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
34 |
import java.io.IOException; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
35 |
import java.net.URI; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
36 |
import java.net.URISyntaxException; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
37 |
import java.util.ArrayList; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
38 |
import java.util.Arrays; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
39 |
import java.util.EnumSet; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
40 |
import java.util.HashMap; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
41 |
import java.util.List; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
42 |
import java.util.Map; |
36526 | 43 |
import java.util.Set; |
44 |
||
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
45 |
import javax.tools.JavaCompiler; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
46 |
import javax.tools.JavaFileManager; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
47 |
import javax.tools.JavaFileObject; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
48 |
import javax.tools.StandardJavaFileManager; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
49 |
import javax.tools.StandardLocation; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
50 |
import javax.tools.ToolProvider; |
36526 | 51 |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
52 |
import com.sun.tools.classfile.ClassFile; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
53 |
import com.sun.tools.classfile.ConstantPoolException; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
54 |
import com.sun.tools.classfile.Descriptor; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
55 |
import com.sun.tools.classfile.Descriptor.InvalidDescriptor; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
56 |
import com.sun.tools.classfile.Field; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
57 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
58 |
import static javax.tools.JavaFileObject.Kind.CLASS; |
36526 | 59 |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
60 |
import static com.sun.tools.classfile.AccessFlags.ACC_ENUM; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
61 |
import static com.sun.tools.classfile.AccessFlags.ACC_FINAL; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
62 |
import static com.sun.tools.classfile.AccessFlags.ACC_STATIC; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
63 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
64 |
public class DetectMutableStaticFields { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
65 |
|
36526 | 66 |
private final String[] modules = { |
67 |
"java.compiler", |
|
68 |
"jdk.compiler", |
|
69 |
"jdk.javadoc", |
|
70 |
"jdk.jdeps" |
|
71 |
}; |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
72 |
|
36526 | 73 |
private final String[] packagesToSeekFor = new String[] { |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
74 |
"javax.tools", |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
75 |
"javax.lang.model", |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
76 |
"com.sun.javadoc", |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
77 |
"com.sun.source", |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
78 |
"com.sun.tools.classfile", |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
79 |
"com.sun.tools.doclets", |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
80 |
"com.sun.tools.javac", |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
81 |
"com.sun.tools.javadoc", |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
82 |
"com.sun.tools.javah", |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
83 |
"com.sun.tools.javap", |
36526 | 84 |
"jdk.javadoc" |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
85 |
}; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
86 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
87 |
private static final Map<String, List<String>> classFieldsToIgnoreMap = new HashMap<>(); |
36526 | 88 |
private static void ignore(String className, String... fields) { |
89 |
classFieldsToIgnoreMap.put(className, Arrays.asList(fields)); |
|
90 |
} |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
91 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
92 |
static { |
36526 | 93 |
ignore("javax/tools/ToolProvider", "instance"); |
94 |
ignore("com/sun/tools/javah/JavahTask", "versionRB"); |
|
95 |
ignore("com/sun/tools/classfile/Dependencies$DefaultFilter", "instance"); |
|
96 |
ignore("com/sun/tools/javap/JavapTask", "versionRB"); |
|
97 |
ignore("com/sun/tools/doclets/formats/html/HtmlDoclet", "docletToStart"); |
|
98 |
ignore("com/sun/tools/javac/util/JCDiagnostic", "fragmentFormatter"); |
|
99 |
ignore("com/sun/tools/javac/util/JavacMessages", "defaultBundle", "defaultMessages"); |
|
100 |
ignore("com/sun/tools/javac/file/JRTIndex", "sharedInstance"); |
|
101 |
ignore("com/sun/tools/javac/main/JavaCompiler", "versionRB"); |
|
102 |
ignore("com/sun/tools/javac/code/Type", "moreInfo"); |
|
103 |
ignore("com/sun/tools/javac/util/SharedNameTable", "freelist"); |
|
104 |
ignore("com/sun/tools/javac/util/Log", "useRawMessages"); |
|
105 |
||
106 |
// The following static fields are used for caches of information obtained |
|
107 |
// by reflective lookup, to avoid explicit references that are not available |
|
108 |
// when running javac on JDK 8. |
|
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
109 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$Configuration", |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42822
diff
changeset
|
110 |
"resolveAndBindMethod", "configurationClass"); |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
111 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$Layer", |
36526 | 112 |
"bootMethod", "defineModulesWithOneLoaderMethod", "configurationMethod", "layerClass"); |
41033
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
113 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$Module", |
49af2ecba616
8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents:
40308
diff
changeset
|
114 |
"addExportsMethod", "addUsesMethod", "getModuleMethod", "getUnnamedModuleMethod"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42261
diff
changeset
|
115 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$ModuleDescriptor$Version", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42261
diff
changeset
|
116 |
"versionClass", "parseMethod"); |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
117 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$ModuleFinder", |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
118 |
"moduleFinderClass", "ofMethod"); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
119 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$ServiceLoaderHelper", |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
120 |
"loadMethod"); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
121 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$VMHelper", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
122 |
"vmClass", "getRuntimeArgumentsMethod"); |
41440 | 123 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$JmodFile", |
124 |
"jmodFileClass", "checkMagicMethod"); |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
125 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
126 |
|
36526 | 127 |
private final List<String> errors = new ArrayList<>(); |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
128 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
129 |
public static void main(String[] args) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
130 |
try { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
131 |
new DetectMutableStaticFields().run(); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
132 |
} catch (Exception ex) { |
36526 | 133 |
throw new AssertionError("Exception during test execution: " + ex, ex); |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
134 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
135 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
136 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
137 |
private void run() |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
138 |
throws |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
139 |
IOException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
140 |
ConstantPoolException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
141 |
InvalidDescriptor, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
142 |
URISyntaxException { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
143 |
|
36526 | 144 |
JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
145 |
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
|
146 |
for (String module: modules) { |
|
147 |
analyzeModule(fm, module); |
|
148 |
} |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
149 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
150 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
151 |
if (errors.size() > 0) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
152 |
for (String error: errors) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
153 |
System.err.println(error); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
154 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
155 |
throw new AssertionError("There are mutable fields, " |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
156 |
+ "please check output"); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
157 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
158 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
159 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
160 |
boolean shouldAnalyzePackage(String packageName) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
161 |
for (String aPackage: packagesToSeekFor) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
162 |
if (packageName.contains(aPackage)) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
163 |
return true; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
164 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
165 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
166 |
return false; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
167 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
168 |
|
36526 | 169 |
void analyzeModule(StandardJavaFileManager fm, String moduleName) |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
170 |
throws |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
171 |
IOException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
172 |
ConstantPoolException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
173 |
InvalidDescriptor { |
36526 | 174 |
JavaFileManager.Location location = |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
41440
diff
changeset
|
175 |
fm.getLocationForModule(StandardLocation.SYSTEM_MODULES, moduleName); |
36526 | 176 |
if (location == null) |
177 |
throw new AssertionError("can't find module " + moduleName); |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
178 |
|
36526 | 179 |
for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { |
180 |
String className = fm.inferBinaryName(location, file); |
|
181 |
int index = className.lastIndexOf('.'); |
|
182 |
String pckName = index == -1 ? "" : className.substring(0, index); |
|
183 |
if (shouldAnalyzePackage(pckName)) { |
|
184 |
analyzeClassFile(ClassFile.read(file.openInputStream())); |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
185 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
186 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
187 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
188 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
189 |
List<String> currentFieldsToIgnore; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
190 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
191 |
boolean ignoreField(String field) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
192 |
if (currentFieldsToIgnore != null) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
193 |
for (String fieldToIgnore : currentFieldsToIgnore) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
194 |
if (field.equals(fieldToIgnore)) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
195 |
return true; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
196 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
197 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
198 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
199 |
return false; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
200 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
201 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
202 |
void analyzeClassFile(ClassFile classFileToCheck) |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
203 |
throws |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
204 |
IOException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
205 |
ConstantPoolException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
206 |
Descriptor.InvalidDescriptor { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
207 |
boolean enumClass = |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
208 |
(classFileToCheck.access_flags.flags & ACC_ENUM) != 0; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
209 |
boolean nonFinalStaticEnumField; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
210 |
boolean nonFinalStaticField; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
211 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
212 |
currentFieldsToIgnore = |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
213 |
classFieldsToIgnoreMap.get(classFileToCheck.getName()); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
214 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
215 |
for (Field field : classFileToCheck.fields) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
216 |
if (ignoreField(field.getName(classFileToCheck.constant_pool))) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
217 |
continue; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
218 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
219 |
nonFinalStaticEnumField = |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
220 |
(field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
221 |
nonFinalStaticField = |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
222 |
(field.access_flags.flags & ACC_STATIC) != 0 && |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
223 |
(field.access_flags.flags & ACC_FINAL) == 0; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
224 |
if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
225 |
errors.add("There is a mutable field named " + |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
226 |
field.getName(classFileToCheck.constant_pool) + |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
227 |
", at class " + |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
228 |
classFileToCheck.getName()); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
229 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
230 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
231 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
232 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
233 |
} |