diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 5be20f2d..8e4d2a5d 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -3,16 +3,13 @@ */ package de.dhbwstuttgart.bytecode.genericsGenerator; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; +import java.util.*; import de.dhbwstuttgart.bytecode.TPHExtractor; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.MethodAndConstraints; import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; import de.dhbwstuttgart.bytecode.utilities.MethodUtility; import de.dhbwstuttgart.bytecode.utilities.Resolver; @@ -142,7 +139,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); - /**/ + /* tphsClass = tphExtractor.tphsClass; //PL 2020-01-15 //Es muss ggResult aus fogg gebildet werden @@ -156,11 +153,35 @@ public class GeneratedGenericsFinder implements ASTVisitor { addMethodConstraints(simplifiedConstraints, ggResult, m); } - /**/ + if(ggResult != null) generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); - System.out.println("ddd"); + */ + + List listOfClassCons = new ArrayList<>(); + for(TPHConstraint clCons: fogg.classConstraints) { + GenericsGeneratorResult ggR = new GenericsGeneratorResult(clCons, new HashSet<>()); + listOfClassCons.add(ggR); + } + + GenericGeneratorResultsForAllMethods ggRfaM = null; + for(String methID: fogg.methodConstraintsWithPosition.keySet()) { + List listOfMethAndCons = new ArrayList<>(); + List listOfGGR = new ArrayList<>(); + for(TPHConstraint methCons: fogg.methodConstraintsWithPosition.get(methID)) { + GenericsGeneratorResult ggR = new GenericsGeneratorResult(methCons, new HashSet<>()); + listOfGGR.add(ggR); + } + MethodAndConstraints mac = new MethodAndConstraints(methID, listOfGGR); + listOfMethAndCons.add(mac); + ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons); + } + ggResult = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); + + if(ggResult != null) { + generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + } } diff --git a/src/test/java/insertGenerics/MethodsTest.java b/src/test/java/insertGenerics/MethodsTest.java deleted file mode 100644 index 91e67a1d..00000000 --- a/src/test/java/insertGenerics/MethodsTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.ClassOrInterface; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import junit.framework.TestResult; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -public class MethodsTest { - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - public static final String fileDirectory = rootDirectory + "TestGGFinder.jav"; - - @Test - public void testVisit(ClassOrInterface coi) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(new File(fileDirectory)); - SourceFile sf = compiler.sourceFiles.get(compiler.sourceFiles.keySet()); - List results = compiler.typeInference(); - - GeneratedGenericsFinder ggf = new GeneratedGenericsFinder(sf, results); - ClassOrInterface coiHere = coi; - ggf.visit(coiHere); - //assert results.size()>0; - } -} diff --git a/src/test/java/insertGenerics/TryTest.java b/src/test/java/insertGenerics/TryTest.java deleted file mode 100644 index d0b1ae2f..00000000 --- a/src/test/java/insertGenerics/TryTest.java +++ /dev/null @@ -1,92 +0,0 @@ -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 TryTest { - - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestGGFinder.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - //filesToTest.add(new File(rootDirectory+"fc.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda3.jav")); - //filesToTest.add(new File(rootDirectory+"Vector.jav")); - //filesToTest.add(new File(rootDirectory+"Generics.jav")); - //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); - //filesToTest.add(new File(rootDirectory+"Matrix.jav")); - //filesToTest.add(new File(rootDirectory+"Import.jav")); - // //filesToTest.add(new File(rootDirectory+"Faculty.jav")); - // //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); - // //filesToTest.add(new File(rootDirectory+"test.jav")); - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); -// System.out.println(ASTTypePrinter.print(sf)); -// System.out.println("---------------------------1"); -// System.out.println(ASTPrinter.print(sf)); -// System.out.println("---------------------------2"); - } - 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("---------------------------3"); - System.out.println(ASTPrinter.print(sf)); -// System.out.println("---------------------------4"); - //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("---------------------------51"); - System.out.println(s); - System.out.println("---------------------------52"); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -}