forked from JavaTX/JavaCompilerCore
Work on #308
This commit is contained in:
parent
e6cd4038e2
commit
6c8657b7a8
@ -738,15 +738,13 @@ public class JavaTXCompiler {
|
||||
for (File f : sourceFiles.keySet()) {
|
||||
HashMap<JavaClassName, byte[]> 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<JavaClassName, byte[]> classFiles, File path) throws IOException {
|
||||
public synchronized void writeClassFile(Map<JavaClassName, byte[]> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user