From c6d896fa3bdf8f6ecae01776cc30dbf500e1850c Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Sat, 30 Jan 2021 22:06:27 +0100 Subject: [PATCH] modified: ../../../main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: ../../java/insertGenerics/TestGGFinder.java modified: TestGGFinder.jav --- .../GeneratedGenericsFinder.java | 8 +-- .../java/insertGenerics/TestGGFinder.java | 52 ++++++------------- .../insertGenericsJav/TestGGFinder.jav | 2 +- 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 7e89e755..7a7f876e 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 c517136c..3b9e378e 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 9ce2691f..cc94cad5 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) {