author | sadayapalam |
Mon, 19 Sep 2016 05:31:53 +0530 | |
changeset 41033 | 49af2ecba616 |
parent 40308 | 274367a99f98 |
child 41440 | abd777fa486c |
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", |
36526 | 110 |
"resolveRequiresAndUsesMethod", "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"); |
38533
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
115 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$ModuleFinder", |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
116 |
"moduleFinderClass", "ofMethod"); |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
117 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$ServiceLoaderHelper", |
2bd347dde526
8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents:
36526
diff
changeset
|
118 |
"loadMethod"); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
119 |
ignore("com/sun/tools/javac/util/JDK9Wrappers$VMHelper", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38533
diff
changeset
|
120 |
"vmClass", "getRuntimeArgumentsMethod"); |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
121 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
122 |
|
36526 | 123 |
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
|
124 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
125 |
public static void main(String[] args) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
126 |
try { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
127 |
new DetectMutableStaticFields().run(); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
128 |
} catch (Exception ex) { |
36526 | 129 |
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
|
130 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
131 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
132 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
133 |
private void run() |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
134 |
throws |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
135 |
IOException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
136 |
ConstantPoolException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
137 |
InvalidDescriptor, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
138 |
URISyntaxException { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
139 |
|
36526 | 140 |
JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
141 |
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
|
142 |
for (String module: modules) { |
|
143 |
analyzeModule(fm, module); |
|
144 |
} |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
145 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
146 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
147 |
if (errors.size() > 0) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
148 |
for (String error: errors) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
149 |
System.err.println(error); |
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 |
throw new AssertionError("There are mutable fields, " |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
152 |
+ "please check output"); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
153 |
} |
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 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
156 |
boolean shouldAnalyzePackage(String packageName) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
157 |
for (String aPackage: packagesToSeekFor) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
158 |
if (packageName.contains(aPackage)) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
159 |
return true; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
160 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
161 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
162 |
return false; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
163 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
164 |
|
36526 | 165 |
void analyzeModule(StandardJavaFileManager fm, String moduleName) |
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
166 |
throws |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
167 |
IOException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
168 |
ConstantPoolException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
169 |
InvalidDescriptor { |
36526 | 170 |
JavaFileManager.Location location = |
171 |
fm.getModuleLocation(StandardLocation.SYSTEM_MODULES, moduleName); |
|
172 |
if (location == null) |
|
173 |
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
|
174 |
|
36526 | 175 |
for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { |
176 |
String className = fm.inferBinaryName(location, file); |
|
177 |
int index = className.lastIndexOf('.'); |
|
178 |
String pckName = index == -1 ? "" : className.substring(0, index); |
|
179 |
if (shouldAnalyzePackage(pckName)) { |
|
180 |
analyzeClassFile(ClassFile.read(file.openInputStream())); |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
181 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
182 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
183 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
184 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
185 |
List<String> currentFieldsToIgnore; |
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 |
boolean ignoreField(String field) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
188 |
if (currentFieldsToIgnore != null) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
189 |
for (String fieldToIgnore : currentFieldsToIgnore) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
190 |
if (field.equals(fieldToIgnore)) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
191 |
return true; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
192 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
193 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
194 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
195 |
return false; |
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 |
void analyzeClassFile(ClassFile classFileToCheck) |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
199 |
throws |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
200 |
IOException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
201 |
ConstantPoolException, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
202 |
Descriptor.InvalidDescriptor { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
203 |
boolean enumClass = |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
204 |
(classFileToCheck.access_flags.flags & ACC_ENUM) != 0; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
205 |
boolean nonFinalStaticEnumField; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
206 |
boolean nonFinalStaticField; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
207 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
208 |
currentFieldsToIgnore = |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
209 |
classFieldsToIgnoreMap.get(classFileToCheck.getName()); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
210 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
211 |
for (Field field : classFileToCheck.fields) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
212 |
if (ignoreField(field.getName(classFileToCheck.constant_pool))) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
213 |
continue; |
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 |
nonFinalStaticEnumField = |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
216 |
(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
|
217 |
nonFinalStaticField = |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
218 |
(field.access_flags.flags & ACC_STATIC) != 0 && |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
219 |
(field.access_flags.flags & ACC_FINAL) == 0; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
220 |
if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
221 |
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
|
222 |
field.getName(classFileToCheck.constant_pool) + |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
223 |
", at class " + |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
224 |
classFileToCheck.getName()); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
225 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
226 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
227 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
228 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
diff
changeset
|
229 |
} |