Skip to content

Commit 5024596

Browse files
committed
Modify JavaHelper.ts to read, compile and run multiple class files.
1 parent 42b8271 commit 5024596

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/commons/utils/JavaHelper.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function javaRun(
1818
isUsingCse: boolean,
1919
options?: { uploadIsActive?: boolean; uploads?: UploadResult }
2020
) {
21-
let compiled = {};
21+
let compiled: {[key: string]: string} = {};
2222

2323
const stderr = (type: 'TypeCheck' | 'Compile' | 'Runtime', msg: string) => {
2424
context.errors.push({
@@ -110,10 +110,12 @@ export async function javaRun(
110110
}
111111

112112
try {
113-
const classFile = compileFromSource(javaCode);
114-
compiled = {
115-
'Main.class': Buffer.from(new BinaryWriter().generateBinary(classFile)).toString('base64')
116-
};
113+
const binaryWriter = new BinaryWriter();
114+
const classes = compileFromSource(javaCode);
115+
classes.forEach(c => {
116+
compiled[c.className + '.class']
117+
= Buffer.from(binaryWriter.generateBinary(c.classFile)).toString('base64');
118+
});
117119
} catch (e) {
118120
stderr('Compile', e);
119121
return Promise.resolve({ status: 'error' });

0 commit comments

Comments
 (0)