From 6c8657b7a89f3e474ab3f7637946bc5bb60c30d0 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Wed, 10 Apr 2024 09:42:31 +0200 Subject: [PATCH] Work on #308 --- .../java/de/dhbwstuttgart/core/JavaTXCompiler.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 46522989..e5ffcaa2 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -738,15 +738,13 @@ public class JavaTXCompiler { for (File f : sourceFiles.keySet()) { HashMap classFiles = new HashMap<>(); SourceFile sf = sourceFiles.get(f); - File path; + File path = outputPath; if (outputPath == null) { path = f.getParentFile(); // Set path to path of the parsed .jav file - } else { - path = new File(outputPath, sf.getPkgName().replace(".", "/")); // add package path to root path } var generatedClasses = generateBytecode(sf, typeinferenceResult); - writeClassFile(generatedClasses, path); + writeClassFile(generatedClasses, path, outputPath == null); } } @@ -765,12 +763,12 @@ public class JavaTXCompiler { return generatedClasses; } - public synchronized void writeClassFile(Map classFiles, File path) throws IOException { + public synchronized void writeClassFile(Map classFiles, File path, boolean preserveHierarchy) throws IOException { FileOutputStream output; for (JavaClassName name : classFiles.keySet()) { byte[] bytecode = classFiles.get(name); System.out.println("generating " + name + ".class file ..."); - var subPath = Path.of(path.toString(), name.getPackageName().split("\\.")).toFile(); + var subPath = preserveHierarchy ? path : Path.of(path.toString(), name.getPackageName().split("\\.")).toFile(); File outputFile = new File(subPath, name.getClassName() + ".class"); outputFile.getAbsoluteFile().getParentFile().mkdirs(); output = new FileOutputStream(outputFile);