diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 35e83cc6..dfdba215 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -136,7 +136,11 @@ public class GeneratedGenericsFinder implements ASTVisitor { //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //Rueckgabe an generatedGenericsForSF fogg = new FamilyOfGeneratedGenerics(tphExtractor); - System.out.println("fogg: "+ fogg.methodConstraintsWithPosition); + System.out.println("fogg.allConstraints: "+ fogg.allConstraints); + System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); + System.out.println("fogg.classConstraints: "+ fogg.classConstraints); + System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); + tphsClass = tphExtractor.tphsClass; simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass); if(!isVisited) { diff --git a/src/test/java/insertGenerics/TestAny.java b/src/test/java/insertGenerics/TestAny.java new file mode 100644 index 00000000..6c6d2a95 --- /dev/null +++ b/src/test/java/insertGenerics/TestAny.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestAny { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestAny.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + 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); + } + } + 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/java/insertGenerics/TestTPHsAndGenerics2.java b/src/test/java/insertGenerics/TestTPHsAndGenerics2.java new file mode 100644 index 00000000..fc5a90e6 --- /dev/null +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics2.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestTPHsAndGenerics2 { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestTPHSAndGenerics2.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + 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); + } + } + 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/TestAny.jav b/src/test/resources/insertGenericsJav/TestAny.jav new file mode 100644 index 00000000..9ba18b63 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestAny.jav @@ -0,0 +1,13 @@ +class Example { + a; + b = a; + anyMethod() { + var f; + return f; + } + otherMethod(e) { + b = e; + e = a; + return e; + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestReturnVar.jav b/src/test/resources/insertGenericsJav/TestReturnVar.jav index 8906df24..0688e5b8 100644 --- a/src/test/resources/insertGenericsJav/TestReturnVar.jav +++ b/src/test/resources/insertGenericsJav/TestReturnVar.jav @@ -1,5 +1,6 @@ class VarReturn { anyMethod() { + var f; return f; } } \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav b/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav index 6ef08afe..16275a50 100644 --- a/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav +++ b/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav @@ -1,13 +1,12 @@ -class Example() { +class Example { a; b = a; anyMethod() { - f; + var f; return f; } otherMethod(e) { - this.b = e; - e = this.a; + e = a; return e; } } \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestTPHsAndGenerics2.jav b/src/test/resources/insertGenericsJav/TestTPHsAndGenerics2.jav new file mode 100644 index 00000000..9cdc21f7 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestTPHsAndGenerics2.jav @@ -0,0 +1,13 @@ +class TPHsAndGenerics2 { + id = x -> x; + id2 (x) { + return id.apply(x); + } + m(a, b){ + var c = m2(a,b); + return a; + } + m2(a, b){ + return b; + } +} \ No newline at end of file