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()) {
|
for (File f : sourceFiles.keySet()) {
|
||||||
HashMap<JavaClassName, byte[]> classFiles = new HashMap<>();
|
HashMap<JavaClassName, byte[]> classFiles = new HashMap<>();
|
||||||
SourceFile sf = sourceFiles.get(f);
|
SourceFile sf = sourceFiles.get(f);
|
||||||
File path;
|
File path = outputPath;
|
||||||
if (outputPath == null) {
|
if (outputPath == null) {
|
||||||
path = f.getParentFile(); // Set path to path of the parsed .jav file
|
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);
|
var generatedClasses = generateBytecode(sf, typeinferenceResult);
|
||||||
writeClassFile(generatedClasses, path);
|
writeClassFile(generatedClasses, path, outputPath == null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -765,12 +763,12 @@ public class JavaTXCompiler {
|
|||||||
return generatedClasses;
|
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;
|
FileOutputStream output;
|
||||||
for (JavaClassName name : classFiles.keySet()) {
|
for (JavaClassName name : classFiles.keySet()) {
|
||||||
byte[] bytecode = classFiles.get(name);
|
byte[] bytecode = classFiles.get(name);
|
||||||
System.out.println("generating " + name + ".class file ...");
|
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");
|
File outputFile = new File(subPath, name.getClassName() + ".class");
|
||||||
outputFile.getAbsoluteFile().getParentFile().mkdirs();
|
outputFile.getAbsoluteFile().getParentFile().mkdirs();
|
||||||
output = new FileOutputStream(outputFile);
|
output = new FileOutputStream(outputFile);
|
||||||
|
Loading…
Reference in New Issue
Block a user