From a7720fbf20b3b8888e80dc7f8aceccffecc5600f Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Tue, 31 Jan 2023 13:49:19 +0100 Subject: [PATCH] Don't append new class files, overwrite them --- src/main/java/de/dhbwstuttgart/bytecode/Codegen.java | 6 +++--- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index 9d196167..ee604779 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java @@ -979,7 +979,7 @@ public class Codegen { } private void generateConstructor(TargetConstructor constructor) { - MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "", constructor.getDescriptor(), constructor.getSignature(), null); + MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "", constructor.getDescriptor(), null, null); mv.visitCode(); var state = new State(null, mv, 1); for (var param: constructor.parameters()) @@ -1027,8 +1027,8 @@ public class Codegen { } public byte[] generate() { - cw.visit(V1_8, clazz.modifiers() | ACC_PUBLIC, clazz.qualifiedName(), - generateSignature(clazz), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object", + cw.visit(V1_8, clazz.modifiers() | ACC_PUBLIC | ACC_SUPER, clazz.qualifiedName(), + null, clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object", clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new) ); clazz.fields().forEach(this::generateField); diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 67e553e6..ce312d01 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -909,7 +909,7 @@ public class JavaTXCompiler { // "/testBytecode/generatedBC/" +name+".class")); File outputFile = new File(path, name.getClassName() + ".class"); outputFile.getAbsoluteFile().getParentFile().mkdirs(); - output = new FileOutputStream(outputFile); + output = new FileOutputStream(outputFile, false); output.write(bytecode); output.close(); System.out.println(name + ".class file generated");