Apply Java 11 syntax

This commit is contained in:
Alexey Andreev 2022-11-17 14:36:55 +01:00
parent 06748fa12b
commit 238873cbe7
2 changed files with 29 additions and 34 deletions

View File

@ -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<? extends VariableReader> arguments, InvocationType type) {
if (type == InvocationType.VIRTUAL) {
ValueDependencyInfo instanceDep = methodDep.getVariable(instance.getIndex());
Set<MethodReference> 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<>();

View File

@ -29,7 +29,7 @@ interface TeaVMTestConfiguration<T extends TeaVMTarget> {
void apply(T target);
TeaVMTestConfiguration<JavaScriptTarget> JS_DEFAULT = new TeaVMTestConfiguration<JavaScriptTarget>() {
TeaVMTestConfiguration<JavaScriptTarget> JS_DEFAULT = new TeaVMTestConfiguration<>() {
@Override
public String getSuffix() {
return "";
@ -46,7 +46,7 @@ interface TeaVMTestConfiguration<T extends TeaVMTarget> {
}
};
TeaVMTestConfiguration<JavaScriptTarget> JS_OPTIMIZED = new TeaVMTestConfiguration<JavaScriptTarget>() {
TeaVMTestConfiguration<JavaScriptTarget> JS_OPTIMIZED = new TeaVMTestConfiguration<>() {
@Override
public String getSuffix() {
return "optimized";
@ -63,7 +63,7 @@ interface TeaVMTestConfiguration<T extends TeaVMTarget> {
}
};
TeaVMTestConfiguration<JavaScriptTarget> JS_MINIFIED = new TeaVMTestConfiguration<JavaScriptTarget>() {
TeaVMTestConfiguration<JavaScriptTarget> JS_MINIFIED = new TeaVMTestConfiguration<>() {
@Override
public String getSuffix() {
return "min";
@ -80,7 +80,7 @@ interface TeaVMTestConfiguration<T extends TeaVMTarget> {
}
};
TeaVMTestConfiguration<WasmTarget> WASM_DEFAULT = new TeaVMTestConfiguration<WasmTarget>() {
TeaVMTestConfiguration<WasmTarget> WASM_DEFAULT = new TeaVMTestConfiguration<>() {
@Override
public String getSuffix() {
return "";
@ -99,7 +99,7 @@ interface TeaVMTestConfiguration<T extends TeaVMTarget> {
}
};
TeaVMTestConfiguration<WasmTarget> WASM_OPTIMIZED = new TeaVMTestConfiguration<WasmTarget>() {
TeaVMTestConfiguration<WasmTarget> WASM_OPTIMIZED = new TeaVMTestConfiguration<>() {
@Override
public String getSuffix() {
return "optimized";
@ -115,7 +115,7 @@ interface TeaVMTestConfiguration<T extends TeaVMTarget> {
}
};
TeaVMTestConfiguration<CTarget> C_DEFAULT = new TeaVMTestConfiguration<CTarget>() {
TeaVMTestConfiguration<CTarget> C_DEFAULT = new TeaVMTestConfiguration<>() {
@Override
public String getSuffix() {
return "";
@ -131,7 +131,7 @@ interface TeaVMTestConfiguration<T extends TeaVMTarget> {
}
};
TeaVMTestConfiguration<CTarget> C_OPTIMIZED = new TeaVMTestConfiguration<CTarget>() {
TeaVMTestConfiguration<CTarget> C_OPTIMIZED = new TeaVMTestConfiguration<>() {
@Override
public String getSuffix() {
return "optimized";