From 238873cbe7b8f8dadc7c7d5dd782c6ca3ec92e49 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 17 Nov 2022 14:36:55 +0100 Subject: [PATCH] Apply Java 11 syntax --- .../analysis/ClassInitializerAnalysis.java | 49 +++++++++---------- .../teavm/junit/TeaVMTestConfiguration.java | 14 +++--- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/org/teavm/model/analysis/ClassInitializerAnalysis.java b/core/src/main/java/org/teavm/model/analysis/ClassInitializerAnalysis.java index b439ae005..e820baf07 100644 --- a/core/src/main/java/org/teavm/model/analysis/ClassInitializerAnalysis.java +++ b/core/src/main/java/org/teavm/model/analysis/ClassInitializerAnalysis.java @@ -26,20 +26,15 @@ import java.util.Map; import java.util.Set; import org.teavm.dependency.DependencyInfo; import org.teavm.dependency.MethodDependencyInfo; -import org.teavm.dependency.ValueDependencyInfo; import org.teavm.interop.NoSideEffects; import org.teavm.interop.StaticInit; -import org.teavm.model.BasicBlockReader; import org.teavm.model.ClassHierarchy; -import org.teavm.model.ClassReader; import org.teavm.model.ElementModifier; -import org.teavm.model.FieldReader; import org.teavm.model.FieldReference; import org.teavm.model.ListableClassReaderSource; import org.teavm.model.MethodDescriptor; import org.teavm.model.MethodReader; import org.teavm.model.MethodReference; -import org.teavm.model.ProgramReader; import org.teavm.model.ValueType; import org.teavm.model.VariableReader; import org.teavm.model.instructions.AbstractInstructionReader; @@ -71,7 +66,7 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { } this.dependencyInfo = dependencyInfo; - for (String className : classes.getClassNames()) { + for (var className : classes.getClassNames()) { analyze(className); } @@ -92,7 +87,7 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { } private void analyze(String className) { - byte classStatus = classStatuses.get(className); + var classStatus = classStatuses.get(className); switch (classStatus) { case BEING_ANALYZED: if (!className.equals(currentAnalyzedClass)) { @@ -104,7 +99,7 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { return; } - ClassReader cls = classes.get(className); + var cls = classes.get(className); if (cls == null || cls.getAnnotations().get(StaticInit.class.getName()) != null) { classStatuses.put(className, STATIC); @@ -112,13 +107,13 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { } classStatuses.put(className, BEING_ANALYZED); - String previousClass = currentAnalyzedClass; + var previousClass = currentAnalyzedClass; currentAnalyzedClass = className; - MethodReader initializer = cls.getMethod(CLINIT); - boolean isStatic = true; + var initializer = cls.getMethod(CLINIT); + var isStatic = true; if (initializer != null) { - MethodInfo initializerInfo = analyzeMethod(initializer); + var initializerInfo = analyzeMethod(initializer); if (isDynamicInitializer(initializerInfo, className)) { isStatic = false; } @@ -138,7 +133,7 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { return true; } if (methodInfo.classesWithModifiedFields != null) { - for (String affectedClass : methodInfo.classesWithModifiedFields) { + for (var affectedClass : methodInfo.classesWithModifiedFields) { if (!affectedClass.equals(className)) { return true; } @@ -148,18 +143,18 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { } private MethodInfo analyzeMethod(MethodReader method) { - MethodInfo methodInfo = methodInfoMap.get(method.getReference()); + var methodInfo = methodInfoMap.get(method.getReference()); if (methodInfo == null) { methodInfo = new MethodInfo(method.getReference()); methodInfoMap.put(method.getReference(), methodInfo); - String currentClass = method.getDescriptor().equals(CLINIT) ? method.getOwnerName() : null; - InstructionAnalyzer reader = new InstructionAnalyzer(currentClass, methodInfo); - ProgramReader program = method.getProgram(); + var currentClass = method.getDescriptor().equals(CLINIT) ? method.getOwnerName() : null; + var reader = new InstructionAnalyzer(currentClass, methodInfo); + var program = method.getProgram(); if (program == null) { methodInfo.anyFieldModified = hasSideEffects(method); } else { - for (BasicBlockReader block : program.getBasicBlocks()) { + for (var block : program.getBasicBlocks()) { block.readAllInstructions(reader); } } @@ -181,7 +176,7 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { if (method.getAnnotations().get(NoSideEffects.class.getName()) != null) { return false; } - ClassReader containingClass = classes.get(method.getOwnerName()); + var containingClass = classes.get(method.getOwnerName()); if (containingClass.getAnnotations().get(NoSideEffects.class.getName()) != null) { return false; } @@ -221,9 +216,9 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { @Override public void putField(VariableReader instance, FieldReference field, VariableReader value, ValueType fieldType) { if (instance == null) { - ClassReader cls = classes.get(field.getClassName()); + var cls = classes.get(field.getClassName()); if (cls != null) { - FieldReader fieldReader = cls.getField(field.getFieldName()); + var fieldReader = cls.getField(field.getFieldName()); if (fieldReader != null && fieldReader.hasModifier(ElementModifier.FINAL)) { return; } @@ -246,10 +241,10 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { public void invoke(VariableReader receiver, VariableReader instance, MethodReference method, List arguments, InvocationType type) { if (type == InvocationType.VIRTUAL) { - ValueDependencyInfo instanceDep = methodDep.getVariable(instance.getIndex()); - Set implementations = Devirtualization.implementations(hierarchy, dependencyInfo, + var instanceDep = methodDep.getVariable(instance.getIndex()); + var implementations = Devirtualization.implementations(hierarchy, dependencyInfo, instanceDep.getTypes(), method); - for (MethodReference implementation : implementations) { + for (var implementation : implementations) { invokeMethod(implementation); } } else { @@ -259,9 +254,9 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { } private void invokeMethod(MethodReference method) { - ClassReader cls = classes.get(method.getClassName()); + var cls = classes.get(method.getClassName()); if (cls != null) { - MethodReader methodReader = cls.getMethod(method.getDescriptor()); + var methodReader = cls.getMethod(method.getDescriptor()); if (methodReader != null) { analyzeCalledMethod(analyzeMethod(methodReader)); } @@ -303,7 +298,7 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo { methodInfo.anyFieldModified = true; methodInfo.classesWithModifiedFields = null; } else if (calledMethod.classesWithModifiedFields != null) { - for (String className : calledMethod.classesWithModifiedFields) { + for (var className : calledMethod.classesWithModifiedFields) { if (!className.equals(currentClass)) { if (methodInfo.classesWithModifiedFields == null) { methodInfo.classesWithModifiedFields = new HashSet<>(); diff --git a/tools/junit/src/main/java/org/teavm/junit/TeaVMTestConfiguration.java b/tools/junit/src/main/java/org/teavm/junit/TeaVMTestConfiguration.java index b08998c8b..912bfcaf5 100644 --- a/tools/junit/src/main/java/org/teavm/junit/TeaVMTestConfiguration.java +++ b/tools/junit/src/main/java/org/teavm/junit/TeaVMTestConfiguration.java @@ -29,7 +29,7 @@ interface TeaVMTestConfiguration { void apply(T target); - TeaVMTestConfiguration JS_DEFAULT = new TeaVMTestConfiguration() { + TeaVMTestConfiguration JS_DEFAULT = new TeaVMTestConfiguration<>() { @Override public String getSuffix() { return ""; @@ -46,7 +46,7 @@ interface TeaVMTestConfiguration { } }; - TeaVMTestConfiguration JS_OPTIMIZED = new TeaVMTestConfiguration() { + TeaVMTestConfiguration JS_OPTIMIZED = new TeaVMTestConfiguration<>() { @Override public String getSuffix() { return "optimized"; @@ -63,7 +63,7 @@ interface TeaVMTestConfiguration { } }; - TeaVMTestConfiguration JS_MINIFIED = new TeaVMTestConfiguration() { + TeaVMTestConfiguration JS_MINIFIED = new TeaVMTestConfiguration<>() { @Override public String getSuffix() { return "min"; @@ -80,7 +80,7 @@ interface TeaVMTestConfiguration { } }; - TeaVMTestConfiguration WASM_DEFAULT = new TeaVMTestConfiguration() { + TeaVMTestConfiguration WASM_DEFAULT = new TeaVMTestConfiguration<>() { @Override public String getSuffix() { return ""; @@ -99,7 +99,7 @@ interface TeaVMTestConfiguration { } }; - TeaVMTestConfiguration WASM_OPTIMIZED = new TeaVMTestConfiguration() { + TeaVMTestConfiguration WASM_OPTIMIZED = new TeaVMTestConfiguration<>() { @Override public String getSuffix() { return "optimized"; @@ -115,7 +115,7 @@ interface TeaVMTestConfiguration { } }; - TeaVMTestConfiguration C_DEFAULT = new TeaVMTestConfiguration() { + TeaVMTestConfiguration C_DEFAULT = new TeaVMTestConfiguration<>() { @Override public String getSuffix() { return ""; @@ -131,7 +131,7 @@ interface TeaVMTestConfiguration { } }; - TeaVMTestConfiguration C_OPTIMIZED = new TeaVMTestConfiguration() { + TeaVMTestConfiguration C_OPTIMIZED = new TeaVMTestConfiguration<>() { @Override public String getSuffix() { return "optimized";