8000 Simplify newly introduced ElementKind management · sakerbuild/saker.java.compiler@ebc873f · GitHub
[go: up one dir, main page]

Skip to content

Commit ebc873f

Browse files
committed
Simplify newly introduced ElementKind management
[skip ci]
1 parent 0c0c020 commit ebc873f

File tree

14 files changed

+106
-150
lines changed

14 files changed

+106
-150
lines changed

impl-jdk12/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,6 @@ public static String getModuleNameOf(Element elem) {
8080
return Java9LanguageUtils.getModuleNameOf(elem);
8181
}
8282

83-
public static boolean isModuleElementKind(ElementKind kind) {
84-
return Java9LanguageUtils.isModuleElementKind(kind);
85-
}
86-
87-
public static boolean isRecordElementKind(ElementKind kind) {
88-
return false;
89-
}
90-
91-
public static boolean isRecordComponentElementKind(ElementKind kind) {
92-
return false;
93-
}
94-
95-
public static ElementKind getModuleElementKind() {
96-
return ElementKind.MODULE;
97-
}
98-
99-
public static ElementKind getRecordElementKind() {
100-
return null;
101-
}
102-
103-
public static ElementKind getRecordComponentElementKind() {
104-
return null;
105-
}
106-
10783
public static void addTreeKindToElementKindMapping(Map<Tree.Kind, ElementKind> map) {
10884
}
10985
}

impl-jdk13/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,6 @@ public static String getModuleNameOf(Element elem) {
7979
return Java9LanguageUtils.getModuleNameOf(elem);
8080
}
8181

82-
public static boolean isModuleElementKind(ElementKind kind) {
83-
return Java9LanguageUtils.isModuleElementKind(kind);
84-
}
85-
86-
public static boolean isRecordElementKind(ElementKind kind) {
87-
return false;
88-
}
89-
90-
public static boolean isRecordComponentElementKind(ElementKind kind) {
91-
return false;
92-
}
93-
94-
public static ElementKind getModuleElementKind() {
95-
return ElementKind.MODULE;
96-
}
97-
98-
public static ElementKind getRecordElementKind() {
99-
return null;
100-
}
101-
102-
public static ElementKind getRecordComponentElementKind() {
103-
return null;
104-
}
105-
10682
public static void addTreeKindToElementKindMapping(Map<Tree.Kind, ElementKind> map) {
10783
}
10884
}

impl-jdk14/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,6 @@ public static String getModuleNameOf(Element elem) {
8282
return Java9LanguageUtils.getModuleNameOf(elem);
8383
}
8484

85-
//TODO remove element kind related functions
86-
public static boolean isModuleElementKind(ElementKind kind) {
87-
return Java9LanguageUtils.isModuleElementKind(kind);
88-
}
89-
90-
public static boolean isRecordElementKind(ElementKind kind) {
91-
return kind == ElementKind.RECORD;
92-
}
93-
94-
public static boolean isRecordComponentElementKind(ElementKind kind) {
95-
return kind == ElementKind.RECORD_COMPONENT;
96-
}
97-
98-
public static ElementKind getModuleElementKind() {
99-
return ElementKind.MODULE;
100-
}
101-
102-
public static ElementKind getRecordElementKind() {
103-
return ElementKind.RECORD;
104-
}
105-
106-
public static ElementKind getRecordComponentElementKind() {
107-
return ElementKind.RECORD_COMPONENT;
108-
}
109-
11085
public static void addTreeKindToElementKindMapping(Map<Tree.Kind, ElementKind> map) {
11186
Java14LanguageUtils.addTreeKindToElementKindMapping(map);
11287
}

impl-jdk8/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,6 @@ public static String getModuleNameOf(Element elem) {
8484
return null;
8585
}
8686

87-
public static boolean isModuleElementKind(ElementKind kind) {
88-
return false;
89-
}
90-
91-
public static boolean isRecordElementKind(ElementKind kind) {
92-
return false;
93-
}
94-
95-
public static boolean isRecordComponentElementKind(ElementKind kind) {
96-
return false;
97-
}
98-
99-
public static ElementKind getModuleElementKind() {
100-
return null;
101-
}
102-
103-
public static ElementKind getRecordElementKind() {
104-
return null;
105-
}
106-
107-
public static ElementKind getRecordComponentElementKind() {
108-
return null;
109-
}
110-
11187
public static void addTreeKindToElementKindMapping(Map<Tree.Kind, ElementKind> map) {
11288
}
11389
}

impl-jdk9/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,6 @@ public static String getModuleNameOf(Element elem) {
101101
return IncrementalElementsTypes9.getModuleOfImpl(elem).getQualifiedName().toString();
102102
}
103103

104-
public static boolean isModuleElementKind(ElementKind kind) {
105-
return kind == ElementKind.MODULE;
106-
}
107-
108-
public static boolean isRecordElementKind(ElementKind kind) {
109-
return false;
110-
}
111-
112-
public static boolean isRecordComponentElementKind(ElementKind kind) {
113-
return false;
114-
}
115-
116-
public static ElementKind getModuleElementKind() {
117-
return ElementKind.MODULE;
118-
}
119-
120-
public static ElementKind getRecordElementKind() {
121-
return null;
122-
}
123-
124-
public static ElementKind getRecordComponentElementKind() {
125-
return null;
126-
}
127-
128104
public static void addTreeKindToElementKindMapping(Map<Tree.Kind, ElementKind> map) {
129105
}
130106

impl-util-jdk8/src/main/saker/java/compiler/util8/impl/model/IncrementalElementsTypes8.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public class IncrementalElementsTypes8 implements IncrementalElementsTypesBase {
288288

289289
static {
290290
ELEMENT_KIND_PACKAGE_MODULE = EnumSet.of(ElementKind.PACKAGE);
291-
ElementKind moduleelemkind = JavaCompilationUtils.getModuleElementKind();
291+
ElementKind moduleelemkind = KindCompatUtils.ELEMENTKIND_MODULE;
292292
if (moduleelemkind != null) {
293293
ELEMENT_KIND_PACKAGE_MODULE.add(moduleelemkind);
294294
}
@@ -714,7 +714,7 @@ public static TypeElement findOuterMostEnclosingType(TypeElement elem) {
714714
}
715715

716716
public static Element getOuterMostEnclosingElement(Element elem) {
717-
if (elem.getKind() == ElementKind.PACKAGE || JavaCompilationUtils.isModuleElementKind(elem.getKind())) {
717+
if (elem.getKind() == ElementKind.PACKAGE || KindCompatUtils.isModuleElementKind(elem.getKind())) {
718718
return elem;
719719
}
720720
while (!(elem.getKind().isClass() || elem.getKind().isInterface())) {
@@ -3959,15 +3959,15 @@ public ResolutionScope createResolutionScope(Element resolutionelement) {
39593959
ClassHoldingFileData file = elementsToFilesMap.get(resolutionelement);
39603960
if (file != null) {
39613961
//either a module, package, or top level type
3962-
if (kind == ElementKind.PACKAGE || JavaCompilationUtils.isModuleElementKind(kind)) {
3962+
if (kind == ElementKind.PACKAGE || KindCompatUtils.isModuleElementKind(kind)) {
39633963
return createUnitResolutionScope(file);
39643964
}
39653965
if (ELEMENT_KIND_TYPES.contains(kind)) {
39663966
//top level type
39673967
return createTypeHeaderResolutionScopeWithFile((TypeElement) resolutionelement, file);
39683968
}
39693969
}
3970-
if (kind == ElementKind.PACKAGE || JavaCompilationUtils.isModuleElementKind(kind)) {
3970+
if (kind == ElementKind.PACKAGE || KindCompatUtils.isModuleElementKind(kind)) {
39713971
//no file found for top level kind.
39723972
return null;
39733973
}
@@ -4024,10 +4024,10 @@ public ResolutionScope createResolutionScope(Element resolutionelement) {
40244024
}
40254025

40264026
default: {
4027-
if (JavaCompilationUtils.isRecordComponentElementKind(kind)) {
4027+
if (KindCompatUtils.isRecordComponentElementKind(kind)) {
40284028
return createTypeHeaderResolutionScope((TypeElement) resolutionelement.getEnclosingElement());
40294029
}
4030-
if (JavaCompilationUtils.isRecordElementKind(kind)) {
4030+
if (KindCompatUtils.isRecordElementKind(kind)) {
40314031
return createTypeHeaderResolutionScope((TypeElement) resolutionelement);
40324032
}
40334033
//unrecognized element type for resolution

impl-util-jdk8/src/main/saker/java/compiler/util8/impl/parser/signature/CompilationUnitSignatureParser8.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,26 +514,22 @@ public Signature visitVariable(VariableTree tree, ParseContext context) {
514514
ExpressionTree initer = tree.getInitializer();
515515
byte declaringkindindex = context.getDeclaringKindIndex();
516516

517+
FieldSignature sig;
517518
//detect if the variable is an enum constant
518-
ElementKind elemkind;
519-
ConstantValueResolver constantvalue;
520519
if (isEnumConstant(tree, varmodifierflagss, declaringkindindex, context.unit)) {
521-
elemkind = ElementKind.ENUM_CONSTANT;
522-
constantvalue = null;
520+
sig = FieldSignatureImpl.createEnumSignature(vartypesig, varname, doccomment);
523521
} else if (isRecordComponent(varmodifierflagss, declaringkindindex)) {
524-
elemkind = JavaCompilationUtils.getRecordComponentElementKind();
525-
constantvalue = null;
522+
sig = FieldSignatureImpl.createRecordComponent(varmodifierflagss, vartypesig, varname, doccomment);
526523
} else {
527-
elemkind = ElementKind.FIELD;
524+
ConstantValueResolver constantvalue;
528525
if (shouldIncludeConstantValue(tree, declaringkindindex, context)) {
529526
constantvalue = getConstantValueForType(initer, context, type);
530527
} else {
531528
constantvalue = null;
532529
}
530+
sig = FieldSignatureImpl.createField(varmodifierflagss, vartypesig, varname, constantvalue, doccomment);
533531
}
534532

535-
FieldSignature sig = FieldSignatureImpl.create(elemkind, varmodifierflagss, vartypesig, varname, constantvalue,
536-
doccomment);
537533
context.treeSignatures.put(tree, sig);
538534

539535
sigpath.setSignature(sig);
@@ -1178,7 +1174,7 @@ private Set<Modifier> getCorrectedClassModifiers(ClassTree tree, ModifiersTree c
11781174
return classmodifierflags;
11791175
}
11801176
default: {
1181-
if (JavaCompilationUtils.isRecordElementKind(kind)) {
1177+
if (KindCompatUtils.isRecordElementKind(kind)) {
11821178
ImmutableModifierSet res = ImmutableModifierSet.get(classmodifiers.getFlags())
11831179
.added(Modifier.FINAL);
11841180
if (enclosingclasssignature != null) {

impl/src/main/saker/java/compiler/impl/RemoteJavaRMIProcess.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import saker.build.thirdparty.saker.util.io.ProcessUtils;
3535
import saker.build.thirdparty.saker.util.io.StreamUtils;
3636
import saker.build.thirdparty.saker.util.io.UnsyncByteArrayOutputStream;
37+
import saker.java.compiler.impl.compile.handler.incremental.RemoteJavaCompilerCacheKey;
3738

3839
public class RemoteJavaRMIProcess implements Closeable {
3940
private Process proc;
@@ -71,8 +72,20 @@ public RemoteJavaRMIProcess(List<String> commands, String workingdirectory, Clas
7172
port = Integer.parseInt(portnumbuf.toString());
7273
}
7374
address = new InetSocketAddress(InetAddress.getLoopbackAddress(), port);
74-
connection = new RMIOptions().classLoader(cloader).transferProperties(rmiproperties)
75-
.workerThreadGroup(connectionThreadGroup).connect(address);
75+
RMIOptions options = new RMIOptions().classLoader(cloader).transferProperties(rmiproperties)
76+
.workerThreadGroup(connectionThreadGroup);
77+
if (RemoteJavaCompilerCacheKey.COLLECT_RMI_STATS) {
78+
options.collectStatistics 10000 (true);
79+
}
80+
connection = options.connect(address);
81+
if (RemoteJavaCompilerCacheKey.COLLECT_RMI_STATS) {
82+
connection.addCloseListener(new RMIConnection.CloseListener() {
83+
@Override
84+
public void onConnectionClosed() {
85+
connection.getStatistics().dumpSummary(System.err, null);
86+
}
87+
});
88+
}
7689
shutdownHook = new Thread(connectionThreadGroup, "RMI process shutdown hook") {
7790
@Override
7891
public void run() {
@@ -115,6 +128,9 @@ public void close() {
115128
} finally {
116129
waitDestroyForcibly();
117130
}
131+
if (RemoteJavaCompilerCacheKey.COLLECT_RMI_STATS) {
132+
printProcessStreams();
133+
}
118134
} catch (IOException e) {
119135
e.printStackTrace();
120136
printProcessStreams();

impl/src/main/saker/java/compiler/impl/compat/KindCompatUtils.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,29 @@ private KindCompatUtils() {
1414
// ONLY ADDITIONAL MODIFICATIONS TO THESE ARRAYS
1515
// for backward compatibility
1616

17-
private static final String[] ELEMENTKIND_NAMES = { "PACKAGE", "ENUM", "CLASS", "ANNOTATION_TYPE", "INTERFACE",
18-
"ENUM_CONSTANT", "FIELD", "PARAMETER", "LOCAL_VARIABLE", "EXCEPTION_PARAMETER", "METHOD", "CONSTRUCTOR",
19-
"STATIC_INIT", "INSTANCE_INIT", "TYPE_PARAMETER", "OTHER", "RESOURCE_VARIABLE", "MODULE", "RECORD",
20-
"RECORD_COMPONENT" };
17+
private static final String[] ELEMENTKIND_NAMES = { //
18+
"PACKAGE", // 0
19+
"ENUM", // 1
20+
"CLASS", // 2
21+
"ANNOTATION_TYPE", // 3
22+
"INTERFACE", // 4
23+
"ENUM_CONSTANT", // 5
24+
"FIELD", // 6
25+
"PARAMETER", // 7
26+
"LOCAL_VARIABLE", // 8
27+
"EXCEPTION_PARAMETER", // 9
28+
"METHOD", // 10
29+
"CONSTRUCTOR", // 11
30+
"STATIC_INIT", // 12
31+
"INSTANCE_INIT", // 13
32+
"TYPE_PARAMETER", // 14
33+
"OTHER", // 15
34+
"RESOURCE_VARIABLE", // 16
35+
"MODULE", // 17
36+
"RECORD", // 18
37+
"RECORD_COMPONENT", // 19
38+
"BINDING_VARIABLE", // 20
39+
};
2140

2241
private static final ElementKind[] ELEMENTKINDS = new ElementKind[ELEMENTKIND_NAMES.length];
2342

@@ -43,6 +62,11 @@ private KindCompatUtils() {
4362
public static final byte ELEMENTKIND_INDEX_MODULE = 17;
4463
public static final byte ELEMENTKIND_INDEX_RECORD = 18;
4564
public static final byte ELEMENTKIND_INDEX_RECORD_COMPONENT = 19;
65+
public static final byte ELEMENTKIND_INDEX_BINDING_VARIABLE = 20;
66+
67+
public static final ElementKind ELEMENTKIND_MODULE;
68+
public static final ElementKind ELEMENTKIND_RECORD;
69+
public static final ElementKind ELEMENTKIND_RECORD_COMPONENT;
4670

4771
private static final byte[] ELEMENTKIND_ORDINAL_INDEX_LOOKUP;
4872
static {
@@ 10000 -64,6 +88,21 @@ private KindCompatUtils() {
6488
ELEMENTKIND_ORDINAL_INDEX_LOOKUP[ek.ordinal()] = (byte) i;
6589
}
6690
}
91+
ELEMENTKIND_MODULE = ELEMENTKINDS[ELEMENTKIND_INDEX_MODULE];
92+
ELEMENTKIND_RECORD = ELEMENTKINDS[ELEMENTKIND_INDEX_RECORD];
93+
ELEMENTKIND_RECORD_COMPONENT = ELEMENTKINDS[ELEMENTKIND_INDEX_RECORD_COMPONENT];
94+
}
95+
96+
public static boolean isModuleElementKind(ElementKind kind) {
97+
return kind != null && kind == ELEMENTKIND_MODULE;
98+
}
99+
100+
public static boolean isRecordElementKind(ElementKind kind) {
101+
return kind != null && kind == ELEMENTKIND_RECORD;
102+
}
103+
104+
public static boolean isRecordComponentElementKind(ElementKind kind) {
105+
return kind != null && kind == ELEMENTKIND_RECORD_COMPONENT;
67106
}
68107

69108
public static byte getElementKindIndex(ElementKind kind) {

impl/src/main/saker/java/compiler/impl/compile/handler/full/FullCompilationInvokerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import saker.build.thirdparty.saker.util.ObjectUtils;
4848
import saker.build.thirdparty.saker.util.io.ByteArrayRegion;
4949
import saker.java.compiler.api.compile.exc.JavaCompilationFailedException;
50+
import saker.java.compiler.impl.compat.KindCompatUtils;
5051
import saker.java.compiler.impl.compile.VersionKeyUtils;
5152
import saker.java.compiler.impl.compile.file.IncrementalDirectoryPaths;
5253
import saker.java.compiler.impl.compile.file.JavaCompilerOutputJavaFileObject;
@@ -126,7 +127,7 @@ public void compile(SakerPathBytes[] sources) throws IOException, JavaCompilatio
126127

127128
//find the module name if any that was compiled
128129
for (Element elem : analyzedelements) {
129-
if (!JavaCompilationUtils.isModuleElementKind(elem.getKind())) {
130+
if (!KindCompatUtils.isModuleElementKind(elem.getKind())) {
130131
continue;
131132
}
132133
outModuleName = ((QualifiedNameable) elem).getQualifiedName().toString();

impl/src/main/saker/java/compiler/impl/compile/handler/incremental/RemoteJavaCompilerCacheKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class RemoteJavaCompilerCacheKey implements CacheKey<RemoteCompiler, Remo
3737
private static final Class<JavaCompilerDaemon> JAVA_COMPILER_DAEMON_MAIN_CLASS = saker.java.compiler.impl.launching.JavaCompilerDaemon.class;
3838
private static final String JAVA_COMPILER_DAEMON_MAIN_CLASS_NAME = JAVA_COMPILER_DAEMON_MAIN_CLASS.getName();
3939

40-
public static final boolean COLLECT_RMI_STATS = System
41-
.getProperty(PropertyNames.PROPERTY_COLLECT_RMI_STATISTICS) != null || TestFlag.ENABLED;
40+
public static final boolean COLLECT_RMI_STATS = saker.build.meta.Versions.VERSION_FULL_COMPOUND >= 8_015
41+
&& (System.getProperty(PropertyNames.PROPERTY_COLLECT_RMI_STATISTICS) != null || TestFlag.ENABLED);
4242

4343
private SakerEnvironment environment;
4444
private String javaExe;

impl/src/main/saker/java/compiler/impl/compile/handler/invoker/IncrementalCompilationDirector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import saker.java.compiler.api.processor.ProcessorCreator;
9898
import saker.java.compiler.impl.JavaTaskUtils;
9999
import saker.java.compiler.impl.JavaUtil;
100+
import saker.java.compiler.impl.compat.KindCompatUtils;
100101
import saker.java.compiler.impl.compile.file.IncrementalDirectoryPaths;
101102
import saker.java.compiler.impl.compile.file.JavaCompilerDirectories;
102103
import saker.java.compiler.impl.compile.file.SakerFileWrapperFileObject;
@@ -1178,7 +1179,7 @@ private static DocReference createDocReference(DocumentedElement<?> elem) {
11781179
return new PackageDocReference(sig.getName());
11791180
}
11801181
default: {
1181-
if (JavaCompilationUtils.isModuleElementKind(elem.getKind())) {
1182+
if (KindCompatUtils.isModuleElementKind(elem.getKind())) {
11821183
ModuleSignature ms = (ModuleSignature) elem.getSignature();
11831184
return new ModuleDocReference(ms.getName());
11841185
}

0 commit comments

Comments
 (0)
0