diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 7e89e755e..7a7f876e6 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -157,9 +157,9 @@ public class GeneratedGenericsFinder implements ASTVisitor { } /**/ - if(ggResult != null) - generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); - + if(ggResult != null) { //Hinzufuegen von Fayez ggResult + //generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + } List listOfClassCons = new ArrayList<>(); for(TPHConstraint clCons: fogg.classConstraints) { @@ -183,7 +183,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons); ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); - if(ggResultAlternative != null) { + if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); System.out.println(generatedGenericsForSF); } diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java index c517136cc..3b9e378ec 100644 --- a/src/test/java/insertGenerics/TestGGFinder.java +++ b/src/test/java/insertGenerics/TestGGFinder.java @@ -12,6 +12,9 @@ import org.junit.Test; import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -22,51 +25,30 @@ import java.util.Set; public class TestGGFinder { - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestGGFinder"; + @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestGGFinder.jav")); + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); } private static class TestResultSet{ } - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); return new TestResultSet(); } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } } diff --git a/src/test/resources/insertGenericsJav/TestGGFinder.jav b/src/test/resources/insertGenericsJav/TestGGFinder.jav index 9ce2691fb..cc94cad58 100644 --- a/src/test/resources/insertGenericsJav/TestGGFinder.jav +++ b/src/test/resources/insertGenericsJav/TestGGFinder.jav @@ -1,4 +1,4 @@ -class TestGGFinder { +public class TestGGFinder { a; id(b) {