forked from JavaTX/JavaCompilerCore
Test für ASP anfügen
This commit is contained in:
parent
99ce7c1122
commit
9840281d83
@ -43,6 +43,8 @@ public class ASTFactory {
|
|||||||
}
|
}
|
||||||
int modifier = jreClass.getModifiers();
|
int modifier = jreClass.getModifiers();
|
||||||
boolean isInterface = jreClass.isInterface();
|
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();
|
java.lang.Class superjreClass = jreClass.getSuperclass();
|
||||||
RefType superClass;
|
RefType superClass;
|
||||||
if(superjreClass != null){
|
if(superjreClass != null){
|
||||||
|
@ -30,7 +30,7 @@ public class SuperWildcardType extends WildcardType{
|
|||||||
* Beispiel: ? super Integer.
|
* Beispiel: ? super Integer.
|
||||||
* Integer wird zurückgegeben.
|
* Integer wird zurückgegeben.
|
||||||
*/
|
*/
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric get_SuperType()
|
public RefTypeOrTPHOrWildcardOrGeneric getInnerType()
|
||||||
{
|
{
|
||||||
return this.innerType;
|
return this.innerType;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import java.io.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ClingoTest {
|
public class ClingoTest {
|
||||||
public static final String rootDirectory = "~/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards";
|
|
||||||
public static final String tempDirectory = "/tmp/";
|
public static final String tempDirectory = "/tmp/";
|
||||||
private final TypePlaceholder testType = TypePlaceholder.fresh(new NullToken());
|
private final TypePlaceholder testType = TypePlaceholder.fresh(new NullToken());
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,29 +1,98 @@
|
|||||||
package asp;
|
package asp;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
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.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
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.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.io.File;
|
||||||
import java.util.HashSet;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.io.PrintWriter;
|
||||||
|
import java.sql.Ref;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class UnifyWithoutWildcards {
|
public class UnifyWithoutWildcards {
|
||||||
|
|
||||||
public Collection<ClassOrInterface> getFC() {
|
public static final String tempDirectory = "/tmp/";
|
||||||
Set<ClassOrInterface> ret = new HashSet<>();
|
|
||||||
ret.add(ASTFactory.createObjectClass());
|
@Test
|
||||||
ret.add(ASTFactory.createClass(java.util.List.class));
|
public void adapt() throws InterruptedException, IOException, ClassNotFoundException {
|
||||||
|
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> 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<Pair> 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<List<TypePlaceholder>>{
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(RefType refType) {
|
||||||
|
ArrayList<TypePlaceholder> ret = new ArrayList<>();
|
||||||
|
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
|
||||||
|
ret.addAll(param.acceptTV(this));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(SuperWildcardType superWildcardType) {
|
||||||
|
return superWildcardType.getInnerType().acceptTV(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(TypePlaceholder typePlaceholder) {
|
||||||
|
return Arrays.asList(typePlaceholder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
|
return extendsWildcardType.getInnerType().acceptTV(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(GenericRefType genericRefType) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Collection<TypePlaceholder> getInvolvedTPHS(ConstraintSet<Pair> toTest) {
|
||||||
|
List<TypePlaceholder> 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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstraintSet<Pair> getPairs() {
|
private Collection<ClassOrInterface> getFC() {
|
||||||
ConstraintSet<Pair> ret = new ConstraintSet<>();
|
Set<ClassOrInterface> ret = new HashSet<>();
|
||||||
ret.addUndConstraint(new Pair(TypePlaceholder.fresh(new NullToken()), ASTFactory.createObjectType(), PairOperator.SMALLERDOT));
|
ret.add(ASTFactory.createClass(Matrix.class));
|
||||||
|
//ret.add(ASTFactory.createObjectClass());
|
||||||
|
//ret.add(ASTFactory.createClass(java.util.List.class));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
private class Matrix extends Vector<Vector<Integer>>{}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user