Bug 166 - Wenn Fehlermeldung "Bytecode generation aborted due to

duplicate field name&signature"

... dann die bereits (on the fly) erzeugten Bytecode-Files wieder
löschen
This commit is contained in:
michael 2020-04-14 18:47:30 +02:00
parent 48a12fdc57
commit b025d376fd
2 changed files with 7 additions and 19 deletions

View File

@ -18,7 +18,7 @@
<classpathentry kind="lib" path="lib/icu4j.jar"/>
<classpathentry kind="lib" path="lib/j2objc-annotations.jar"/>
<classpathentry kind="lib" path="lib/javassist.jar"/>
<classpathentry kind="lib" path="lib/JavaTXcompiler.jar"/>
<classpathentry kind="lib" path="lib/JavaTXcompiler.jar" sourcepath="/JavaTXcompiler/src/main/java"/>
<classpathentry kind="lib" path="lib/javax.json.jar"/>
<classpathentry kind="lib" path="lib/jsr305.jar"/>
<classpathentry kind="lib" path="lib/listenablefuture.jar"/>

View File

@ -30,6 +30,7 @@ import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
@ -103,6 +104,7 @@ public class Typinferenz {
} catch (BytecodeGeneratorError | IOException ex) {
ErrorMarker toAdd = new ErrorMarker(ex.getMessage(), new CodePoint(sf.getOffset()));
ret.add(toAdd);
deleteClassFileIfExists(outputDirectory, sf.getClasses());
}
}
}
@ -184,27 +186,13 @@ public class Typinferenz {
}
}
public void writeClassFile(String outputDirectory, HashMap<String, byte[]> classFiles) {
FileOutputStream output;
for (String name : classFiles.keySet()) {
byte[] bytecode = classFiles.get(name);
try {
System.out.println("generating" + name + ".class file");
// output = new FileOutputStream(new File(System.getProperty("user.dir") +
// "/testBytecode/generatedBC/" +name+".class"));
output = new FileOutputStream(new File(outputDirectory + name + ".class"));
output.write(bytecode);
output.close();
System.out.println(name + ".class file generated");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
public void deleteClassFileIfExists(String outputDirectory, List<ClassOrInterface> clazzes) {
for (ClassOrInterface clazz : clazzes) {
File toDelete = new File(outputDirectory + clazz.getClassName() + ".class");
toDelete.delete();
}
}
}
public SourceFile getSourceFile() {
return parsedSource;
}