diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java index bc61985..3ce8d81 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java @@ -205,38 +205,4 @@ public class TypedClass implements TypedNode { return cw.toByteArray(); } - - - public static void main(String[] args) { - TypedClass c = new TypedClass(); - c.setClassName("SomeClass"); - - //Fields - TypedDeclaration f1 = new TypedDeclaration("someNumber", Type.INT); - TypedDeclaration f2 = new TypedDeclaration("someChar", Type.CHAR); - c.typedDeclarations = List.of(f1, f2); - - //Constructors - TypedConstructor constructor = new TypedConstructor("SomeClass", List.of(new TypedParameter("test", Type.INT)), new TypedBlock(new ArrayList<>(), new ArrayList<>())); - c.typedConstructors = List.of(constructor); - - //Methods - c.typedMethods = new ArrayList<>(); - TypedMethod m = new TypedMethod(); - m.setName("someMethod"); - m.setReturnType(Type.INT); - m.setTypedParameters(List.of(new TypedParameter("test", Type.INT))); - TypedIfElse ifs = new TypedIfElse(); - TypedBinary cond = new TypedBinary(); - cond.setOp(Operator.GT); - //cond.setLeft(??); - cond.setRight(new TypedIntLiteral(12)); - ifs.setTypedCon(cond); - m.setTypedBlock(new TypedBlock(List.of(), List.of(ifs, new TypedReturn()))); - c.typedMethods.add(m); - - //codeGen - byte[] code = c.codeGen(); - CodeGenUtils.writeClassfile(code, "SomeClass"); - } } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java index 2396544..0dd4bea 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java @@ -119,7 +119,11 @@ public class TypedFieldVarAccess implements TypedExpression { if (recursiveOwnerChain != null) { ownerChainName = recursiveOwnerChain.getType().getReference(); } else { - ownerChainName = type.getReference(); + if (type.getKind() == Type.Kind.REFERENCE) { + ownerChainName = type.getReference(); + } else { + ownerChainName = ctx.getClassContext().getName(); + } } ctx.getMv().visitFieldInsn(Opcodes.GETFIELD, ownerChainName, name, type.getDescriptor()); } else { diff --git a/src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java b/src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java index 8f5ee7f..b0691c1 100644 --- a/src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java +++ b/src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java @@ -6,12 +6,9 @@ public class ClassCanBeBytecoded { public int test(int var1) { - int i; - i = 0; - while (i < 10) { - i = i + 1; - var1 = var1 + 1; - if (var1 == 5) { + for (int i = 0; i < 12; i = i + 1) { + var1 = this.c.c.c.c.x + this.x; + if (var1 * 3 == 0) { break; } }