diff --git a/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java b/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java index 8c792f60..48e72fc3 100644 --- a/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java +++ b/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java @@ -28,6 +28,22 @@ public final class ConstraintsGenerationUtils throw new AssertionError("No ConstraintsGenerationUtils instance for you"); } + /** + * Generate the constraints for a map of type placeholder and RefType and merge + * these to the already provided constraints. + * + * @param tphMap {@link Map} of {@link TypePlaceholder} and {@link RefType} + * @param constraints {@link ConstraintSet} over {@link Pair} to merge to + * @return The same instance {@code constraints} provided including the merged + * constraints + */ + public static ConstraintSet generateAndMergeConstraints (Map tphMap, + ConstraintSet constraints) { + ConstraintSet generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap); + constraints.addAll(generateConstraints); + return constraints; + } + /** * Generate the constraints for a map of type placeholder and RefType. * diff --git a/src/main/java/de/dhbwstuttgart/inferWildcards/JavaTXCompilerWildcards.java b/src/main/java/de/dhbwstuttgart/inferWildcards/JavaTXCompilerWildcards.java index b8654d83..bb7a3dbd 100644 --- a/src/main/java/de/dhbwstuttgart/inferWildcards/JavaTXCompilerWildcards.java +++ b/src/main/java/de/dhbwstuttgart/inferWildcards/JavaTXCompilerWildcards.java @@ -41,8 +41,6 @@ public class JavaTXCompilerWildcards @Override public ConstraintSet getConstraints () throws ClassNotFoundException, IOException { ConstraintSet constraints = super.getConstraints(); - ConstraintSet generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap); - constraints.addAll(generateConstraints); - return constraints; + return ConstraintsGenerationUtils.generateAndMergeConstraints(tphMap, constraints); } } diff --git a/src/test/java/inferWildcards/TestInferWildcardsJavaTx.java b/src/test/java/inferWildcards/TestInferWildcardsJavaTx.java index 164d8d50..d46265ed 100644 --- a/src/test/java/inferWildcards/TestInferWildcardsJavaTx.java +++ b/src/test/java/inferWildcards/TestInferWildcardsJavaTx.java @@ -9,8 +9,7 @@ import org.junit.Test; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils; -import de.dhbwstuttgart.inferWildcards.ReplaceTypeparamVisitor; -import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; @@ -24,7 +23,6 @@ public class TestInferWildcardsJavaTx @Before public void setup () { resourcePath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards"; - } private JavaTXCompiler getCompiler (String filename) throws ClassNotFoundException, IOException { @@ -32,18 +30,16 @@ public class TestInferWildcardsJavaTx return new JavaTXCompiler(files1); } - private ReplaceTypeparamVisitor generateTph (JavaTXCompiler javaTXCompiler) { + private Map generateTph (JavaTXCompiler javaTXCompiler) { System.out.println("\nReplacements:"); - Map sourceFiles = javaTXCompiler.getSourceFiles(); - ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor(); - sourceFiles.forEach( (k, v) -> v.accept(visitor)); - return visitor; + + return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler); } - private ConstraintSet getGeneratedConstraints (ReplaceTypeparamVisitor visitor) { + private ConstraintSet getGeneratedConstraints (Map tphMap) { System.out.println("\nGenerated TPH:"); - Map tphMap = visitor.getTphMap(); System.out.println(tphMap); + return ConstraintsGenerationUtils.generateConstraints(tphMap); } @@ -65,10 +61,10 @@ public class TestInferWildcardsJavaTx JavaTXCompiler javaTXCompiler = getCompiler("TestClassWildcardsSingle.java"); // Manipulate AST - ReplaceTypeparamVisitor visitor = generateTph(javaTXCompiler); + Map tphMap = generateTph(javaTXCompiler); // Generate Constraints - ConstraintSet generatedConstraints = getGeneratedConstraints(visitor); + ConstraintSet generatedConstraints = getGeneratedConstraints(tphMap); // System.out.println(generatedConstraints); // Constraints @@ -85,10 +81,10 @@ public class TestInferWildcardsJavaTx JavaTXCompiler javaTXCompiler = getCompiler("TestClassWildcardsNested.java"); // Manipulate AST - ReplaceTypeparamVisitor visitor = generateTph(javaTXCompiler); + Map tphMap = generateTph(javaTXCompiler); // Generate Constraints - ConstraintSet generatedConstraints = getGeneratedConstraints(visitor); + ConstraintSet generatedConstraints = getGeneratedConstraints(tphMap); // System.out.println(generatedConstraints); // Constraints @@ -101,10 +97,10 @@ public class TestInferWildcardsJavaTx JavaTXCompiler javaTXCompiler = getCompiler("TestClassWildcardsMap.java"); // Manipulate AST - ReplaceTypeparamVisitor visitor = generateTph(javaTXCompiler); + Map tphMap = generateTph(javaTXCompiler); // Generate Constraints - ConstraintSet generatedConstraints = getGeneratedConstraints(visitor); + ConstraintSet generatedConstraints = getGeneratedConstraints(tphMap); // System.out.println(generatedConstraints); // Constraints @@ -117,10 +113,10 @@ public class TestInferWildcardsJavaTx JavaTXCompiler javaTXCompiler = getCompiler("TestClassWildcardsMapNested.java"); // Manipulate AST - ReplaceTypeparamVisitor visitor = generateTph(javaTXCompiler); + Map tphMap = generateTph(javaTXCompiler); // Generate Constraints - ConstraintSet generatedConstraints = getGeneratedConstraints(visitor); + ConstraintSet generatedConstraints = getGeneratedConstraints(tphMap); // System.out.println(generatedConstraints); // Constraints