diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index b0683569..8dc34ecf 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -43,6 +43,8 @@ public class ASTFactory { } int modifier = jreClass.getModifiers(); boolean isInterface = jreClass.isInterface(); + //see: https://stackoverflow.com/questions/9934774/getting-generic-parameter-from-supertype-class + //ParameterizedType parameterSuperClass = (ParameterizedType) jreClass.getGenericSuperclass(); java.lang.Class superjreClass = jreClass.getSuperclass(); RefType superClass; if(superjreClass != null){ diff --git a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java index f630583e..740c80e5 100644 --- a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java @@ -30,7 +30,7 @@ public class SuperWildcardType extends WildcardType{ * Beispiel: ? super Integer. * Integer wird zurückgegeben. */ - public RefTypeOrTPHOrWildcardOrGeneric get_SuperType() + public RefTypeOrTPHOrWildcardOrGeneric getInnerType() { return this.innerType; } diff --git a/test/asp/ClingoTest.java b/test/asp/ClingoTest.java index d7656d8a..f47b644c 100644 --- a/test/asp/ClingoTest.java +++ b/test/asp/ClingoTest.java @@ -20,7 +20,6 @@ import java.io.*; import java.util.*; public class ClingoTest { - public static final String rootDirectory = "~/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards"; public static final String tempDirectory = "/tmp/"; private final TypePlaceholder testType = TypePlaceholder.fresh(new NullToken()); @Test diff --git a/test/asp/UnifyWithoutWildcards.java b/test/asp/UnifyWithoutWildcards.java index 9e7c867d..6fd6373e 100644 --- a/test/asp/UnifyWithoutWildcards.java +++ b/test/asp/UnifyWithoutWildcards.java @@ -1,29 +1,98 @@ package asp; 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.ASPGenerator; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; -import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; +import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import org.junit.Test; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Ref; +import java.util.*; public class UnifyWithoutWildcards { - public Collection getFC() { - Set ret = new HashSet<>(); - ret.add(ASTFactory.createObjectClass()); - ret.add(ASTFactory.createClass(java.util.List.class)); + public static final String tempDirectory = "/tmp/"; + + @Test + public void adapt() throws InterruptedException, IOException, ClassNotFoundException { + ConstraintSet testSet = new ConstraintSet<>(); + List list = Arrays.asList(TypePlaceholder.fresh(new NullToken())); + RefType t1 = new RefType(new JavaClassName("Matrix"), new NullToken()); + RefType t2 = new RefType(new JavaClassName("Vector"), list, new NullToken()); + testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); + run(testSet); + } + + public ResultSet run(ConstraintSet toTest) throws IOException, InterruptedException, ClassNotFoundException { + String content = ""; + content = new ASPGenerator(toTest, this.getFC()).getASP(); + + PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); + writer.println(content); + writer.close(); + Clingo clingo = new Clingo(Arrays.asList(new File(tempDirectory + "test.lp"))); + String result = clingo.runClingo(); + ResultSet resultSet = ASPParser.parse(result, getInvolvedTPHS(toTest)); + return resultSet; + } + + private static class TPHExtractor implements TypeVisitor>{ + @Override + public List visit(RefType refType) { + ArrayList ret = new ArrayList<>(); + for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){ + ret.addAll(param.acceptTV(this)); + } + return ret; + } + + @Override + public List visit(SuperWildcardType superWildcardType) { + return superWildcardType.getInnerType().acceptTV(this); + } + + @Override + public List visit(TypePlaceholder typePlaceholder) { + return Arrays.asList(typePlaceholder); + } + + @Override + public List visit(ExtendsWildcardType extendsWildcardType) { + return extendsWildcardType.getInnerType().acceptTV(this); + } + + @Override + public List visit(GenericRefType genericRefType) { + return new ArrayList<>(); + } + } + private Collection getInvolvedTPHS(ConstraintSet toTest) { + List ret = new ArrayList<>(); + toTest.map((Pair p)-> { + ret.addAll(p.TA1.acceptTV(new TPHExtractor())); + ret.addAll(p.TA2.acceptTV(new TPHExtractor())); + return p; + }); return ret; } - public ConstraintSet getPairs() { - ConstraintSet ret = new ConstraintSet<>(); - ret.addUndConstraint(new Pair(TypePlaceholder.fresh(new NullToken()), ASTFactory.createObjectType(), PairOperator.SMALLERDOT)); + private Collection getFC() { + Set ret = new HashSet<>(); + ret.add(ASTFactory.createClass(Matrix.class)); + //ret.add(ASTFactory.createObjectClass()); + //ret.add(ASTFactory.createClass(java.util.List.class)); return ret; } + private class Matrix extends Vector>{} }