Static blocks (might be needed for something)
This commit is contained in:
parent
eaef00ff54
commit
124dea2e58
@ -3,6 +3,11 @@ import java.lang.Integer;
|
||||
public class Static {
|
||||
static i = 20;
|
||||
|
||||
static {
|
||||
var x = 30;
|
||||
i = x;
|
||||
}
|
||||
|
||||
static m() {
|
||||
return i;
|
||||
}
|
||||
|
@ -296,7 +296,6 @@ public class SyntaxTreeGenerator {
|
||||
|
||||
private void convert(ClassBodyDeclarationContext classBody, List<Field> fields, List<Constructor> constructors, List<Method> methods, JavaClassName name, RefType superClass, GenericsRegistry generics) {
|
||||
MemberdeclContext member;
|
||||
// Statement-Blöcke und "leere Zeilen" (;) werden noch nicht berücksichtigt
|
||||
if (classBody instanceof MemberdeclContext) {
|
||||
member = (MemberdeclContext) classBody;
|
||||
Integer membermodifiers = 0;
|
||||
@ -327,6 +326,11 @@ public class SyntaxTreeGenerator {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (classBody instanceof Java17Parser.ClassblockContext ctx && ctx.STATIC() != null) {
|
||||
// Static blocks
|
||||
var stmtgen = new StatementGenerator(superClass, compiler, reg, generics, this.fields, new HashMap<>());
|
||||
var block = stmtgen.convert(((Java17Parser.ClassblockContext) classBody).block(), false);
|
||||
staticFieldInitializations.addAll(block.statements);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -725,6 +725,6 @@ public class TestComplete {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Static.jav");
|
||||
var clazz = classFiles.get("Static");
|
||||
var m = clazz.getDeclaredMethod("m");
|
||||
assertEquals(m.invoke(null), 20);
|
||||
assertEquals(m.invoke(null), 30);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user