From f3d6fcb417aed7f55d045164cc0af6a5e49b3728 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Sat, 11 Jan 2020 20:19:23 +0100 Subject: [PATCH] add -classpath to ConsoleInterface. Fix bug --- .../dhbwstuttgart/bytecode/BytecodeGenMethod.java | 2 +- .../de/dhbwstuttgart/core/ConsoleInterface.java | 2 +- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 15 ++++++++------- .../packages/LoadDefaultPackageClassesTest.java | 15 ++++++++++++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 5f1e6132..a7664c6a 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -814,7 +814,7 @@ public class BytecodeGenMethod implements StatementVisitor { // mDesc = helper.generateBCForFunN(methCallType,typesOfParams); }else { try { - cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)}, classLoader); + cLoader2 = new URLClassLoader(new URL[] {new URL("file://" + path + "/")}, classLoader); java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods(); System.out.println("Methods of " + receiverName + " "); for(int i = 0; i typeinferenceResult, + public void generateBytecode(String outputPath, List typeinferenceResult, List simplifyResultsForAllSourceFiles) throws IOException { for (File f : sourceFiles.keySet()) { HashMap classFiles = new HashMap<>(); SourceFile sf = sourceFiles.get(f); + String path; + if(outputPath == null){ + path = f.getParent(); //Set path to path of the parsed .jav file + }else{ + path = outputPath + sf.getPkgName().replace(".","/"); //add package path to root path + } BytecodeGen bytecodeGen = new BytecodeGen(classFiles, typeinferenceResult, simplifyResultsForAllSourceFiles, sf, path, classLoader); bytecodeGen.visit(sf); - if(path == null){ - path = f.getParent(); //Set path to path of the parsed .jav file - }else{ - path += sf.getPkgName().replace(".","/"); //add package path to root path - } writeClassFile(bytecodeGen.getClassFiles(), path); } } diff --git a/src/test/java/packages/LoadDefaultPackageClassesTest.java b/src/test/java/packages/LoadDefaultPackageClassesTest.java index 25af87ef..47fcc4d7 100644 --- a/src/test/java/packages/LoadDefaultPackageClassesTest.java +++ b/src/test/java/packages/LoadDefaultPackageClassesTest.java @@ -29,11 +29,24 @@ public class LoadDefaultPackageClassesTest extends TestCase { public void testLoadGenClass() throws IOException, ClassNotFoundException { CompilationEnvironment.loadDefaultPackageClasses(new File( rootDirectory + "Test.jav"), ClassLoader.getSystemClassLoader()); - } + public void testURLClassLoader() throws IOException, ClassNotFoundException { URLClassLoader cl = new URLClassLoader(new URL[]{new URL("file://"+rootDirectory)}, ClassLoader.getSystemClassLoader()); cl.loadClass("Gen"); } + public void testE2E() throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"OL.jav")); + compiler.typeInference(); + compiler.generateBytecode(); + File f = new File(rootDirectory + "OL.class"); + assertTrue(f.exists()); + + compiler = new JavaTXCompiler(new File(rootDirectory+"OLMain.jav")); + compiler.typeInference(); + compiler.generateBytecode(); + f = new File(rootDirectory + "OLMain.class"); + assertTrue(f.exists()); + } }