diff --git a/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java index 30c06169..ab6ef51b 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java @@ -22,26 +22,29 @@ import java.util.*; public class ASPFactory implements TypeVisitor{ - public String generateASP(ConstraintSet constraints, Collection fcClasses) throws ClassNotFoundException{ + public static String generateASP(ConstraintSet constraints, Collection fcClasses) throws ClassNotFoundException{ ASPFactory factory = new ASPFactory(); - convertFC(fcClasses); + factory.convertFC(fcClasses); List> constraints1 = constraints.cartesianProduct().iterator().next(); for(Constraint constraint : constraints1){ for(Pair p : constraint){ - convertPair(p); + factory.convertPair(p); } } - return writer.getASPFile(); + return factory.writer.getASPFile(); } ASPWriter writer = new ASPWriter(); + boolean isFCType = false; private void convertFC(Collection classes) throws ClassNotFoundException { Set fc = FCGenerator.toFC(classes); + isFCType = true; for(Pair fcp : fc){ convertPair(fcp); } + isFCType = false; } private void convertPair(Pair p){ @@ -96,7 +99,8 @@ public class ASPFactory implements TypeVisitor{ params.add(param.acceptTV(this)); } String typeName = ASPStringConverter.toConstant(refType.getName()); - ASPStatement stmt = makeStatement(ASPRule.ASP_TYPE.toString(), pointer, typeName, convertParameterlist(params)); + String ruleName = isFCType?ASPRule.ASP_TYPE.toString():ASPRule.ASP_FCTYPE.toString(); + ASPStatement stmt = makeStatement(ruleName, pointer, typeName, convertParameterlist(params)); writer.add(stmt); return pointer; } @@ -110,6 +114,7 @@ public class ASPFactory implements TypeVisitor{ public String visit(TypePlaceholder typePlaceholder) { String name = ASPStringConverter.toConstant(typePlaceholder.getName()); ASPStatement stmt = makeStatement(ASPRule.ASP_TYPE_VAR.toString(), name); + writer.add(stmt); return name; } diff --git a/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java index 3f999a41..a3752fcc 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java @@ -17,8 +17,7 @@ import java.util.List; public class ASPGenerator { ASPWriter writer = new ASPWriter(); - private final String asp; - +/* public ASPGenerator(ConstraintSet constraints, Collection fcClasses) throws ClassNotFoundException { List> constraints1 = constraints.cartesianProduct().iterator().next(); List constraintPairs = new ArrayList<>(); @@ -27,9 +26,10 @@ public class ASPGenerator { } asp = toASP(constraintPairs, FCGenerator.toFC(fcClasses)); } + */ public String getASP(){ - return asp; + return ""; } private String toASP(List constraintSet, Collection fc){ diff --git a/test/asp/ClingoTest.java b/test/asp/ClingoTest.java index f47b644c..248cf5a2 100644 --- a/test/asp/ClingoTest.java +++ b/test/asp/ClingoTest.java @@ -2,6 +2,7 @@ package asp; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.sat.asp.parser.ASPParser; +import de.dhbwstuttgart.sat.asp.writer.ASPFactory; import de.dhbwstuttgart.sat.asp.writer.ASPGenerator; import de.dhbwstuttgart.sat.asp.Clingo; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; @@ -25,7 +26,7 @@ public class ClingoTest { @Test public void test() throws IOException, InterruptedException, ClassNotFoundException { String content = ""; - content = new ASPGenerator(this.getPairs(), this.getFC()).getASP(); + content = ASPFactory.generateASP(this.getPairs(), this.getFC()); PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); writer.println(content); diff --git a/test/asp/UnifyWithoutWildcards.java b/test/asp/UnifyWithoutWildcards.java index 998ec56c..cb414f6c 100644 --- a/test/asp/UnifyWithoutWildcards.java +++ b/test/asp/UnifyWithoutWildcards.java @@ -4,6 +4,7 @@ import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.sat.asp.Clingo; import de.dhbwstuttgart.sat.asp.parser.ASPParser; +import de.dhbwstuttgart.sat.asp.writer.ASPFactory; import de.dhbwstuttgart.sat.asp.writer.ASPGenerator; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; @@ -32,12 +33,13 @@ public class UnifyWithoutWildcards { RefType t2 = new RefType(new JavaClassName("Vector"), list, new NullToken()); testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); ResultSet resultSet = run(testSet); - System.out.println(resultSet); + System.out.println(resultSet.results); + assert resultSet.results.size() > 0; } public ResultSet run(ConstraintSet toTest) throws IOException, InterruptedException, ClassNotFoundException { String content = ""; - content = new ASPGenerator(toTest, this.getFC()).getASP(); + content = ASPFactory.generateASP(toTest, this.getFC()); PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); writer.println(content); diff --git a/test/asp/typeinference/ASPTest.java b/test/asp/typeinference/ASPTest.java index cea141f9..112d2023 100644 --- a/test/asp/typeinference/ASPTest.java +++ b/test/asp/typeinference/ASPTest.java @@ -1,6 +1,7 @@ package asp.typeinference; import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.sat.asp.writer.ASPFactory; import de.dhbwstuttgart.sat.asp.writer.ASPGenerator; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.SourceFile; @@ -55,8 +56,8 @@ public class ASPTest { } final ConstraintSet cons = compiler.getConstraints(); - ASPGenerator generator = new ASPGenerator(cons, allClasses); - System.out.println(generator.getASP()); + String asp = ASPFactory.generateASP(cons, allClasses); + System.out.println(asp); } static String readFile(String path, Charset encoding)