forked from JavaTX/JavaCompilerCore
generate the constraints for all tph
This commit is contained in:
parent
26953665c9
commit
b59aabeea5
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.inferWildcards;
|
package de.dhbwstuttgart.inferWildcards;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@ -21,6 +22,16 @@ public final class ConstraintsGenerationUtils
|
|||||||
throw new AssertionError("No ConstraintsGenerationUtils instance for you");
|
throw new AssertionError("No ConstraintsGenerationUtils instance for you");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public static ConstraintSet generateConstraints (Map<TypePlaceholder, RefType> tphMap) {
|
||||||
|
ConstraintSet constraintSet = new ConstraintSet<>();
|
||||||
|
tphMap.forEach( (tph, refType) -> {
|
||||||
|
ConstraintSet constraintSet2 = generateConstraints(refType, tph);
|
||||||
|
constraintSet.addAll(constraintSet2);
|
||||||
|
});
|
||||||
|
return constraintSet;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public static ConstraintSet generateConstraints (RefType refType, TypePlaceholder tph) {
|
public static ConstraintSet generateConstraints (RefType refType, TypePlaceholder tph) {
|
||||||
ConstraintSet constraintSet = new ConstraintSet<>();
|
ConstraintSet constraintSet = new ConstraintSet<>();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.inferWildcards;
|
package de.dhbwstuttgart.inferWildcards;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@ -13,7 +14,7 @@ public class ReplaceTypeparamVisitor
|
|||||||
extends AbstractASTWalker
|
extends AbstractASTWalker
|
||||||
{
|
{
|
||||||
|
|
||||||
private final Map<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric> tphMap;
|
private final Map<TypePlaceholder, RefType> tphMap;
|
||||||
|
|
||||||
public ReplaceTypeparamVisitor () {
|
public ReplaceTypeparamVisitor () {
|
||||||
this.tphMap = new HashMap<>();
|
this.tphMap = new HashMap<>();
|
||||||
@ -23,7 +24,10 @@ public class ReplaceTypeparamVisitor
|
|||||||
public void visit (RefType refType) {
|
public void visit (RefType refType) {
|
||||||
if (!refType.getParaList().isEmpty()) {
|
if (!refType.getParaList().isEmpty()) {
|
||||||
System.out.println("Type: " + refType);
|
System.out.println("Type: " + refType);
|
||||||
generateTypePlaceholder(refType);
|
List<RefTypeOrTPHOrWildcardOrGeneric> paraList = refType.getParaList();
|
||||||
|
paraList.stream().filter(e -> e instanceof RefType).map(RefType.class::cast)
|
||||||
|
.forEach(this::generateTypePlaceholder);
|
||||||
|
|
||||||
}
|
}
|
||||||
super.visit(refType);
|
super.visit(refType);
|
||||||
}
|
}
|
||||||
@ -34,7 +38,7 @@ public class ReplaceTypeparamVisitor
|
|||||||
return tph;
|
return tph;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric> getTphMap () {
|
public Map<TypePlaceholder, RefType> getTphMap () {
|
||||||
return tphMap;
|
return tphMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,11 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||||
import de.dhbwstuttgart.inferWildcards.ReplaceTypeparamVisitor;
|
import de.dhbwstuttgart.inferWildcards.ReplaceTypeparamVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
|
||||||
@ -39,7 +42,13 @@ public class TestInferWildcardsJavaTx
|
|||||||
Map<File, SourceFile> sourceFiles = javaTXCompiler.getSourceFiles();
|
Map<File, SourceFile> sourceFiles = javaTXCompiler.getSourceFiles();
|
||||||
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
|
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
|
||||||
sourceFiles.entrySet().forEach(e -> e.getValue().accept(visitor));
|
sourceFiles.entrySet().forEach(e -> e.getValue().accept(visitor));
|
||||||
System.out.println(visitor.getTphMap());
|
|
||||||
|
// Generate Constraints
|
||||||
|
Map<TypePlaceholder, RefType> tphMap = visitor.getTphMap();
|
||||||
|
System.out.println(tphMap);
|
||||||
|
ConstraintSet generatedConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||||
|
System.out.println(generatedConstraints);
|
||||||
|
|
||||||
|
|
||||||
// Constraints
|
// Constraints
|
||||||
ConstraintSet<Pair> constraints = javaTXCompiler.getConstraints();
|
ConstraintSet<Pair> constraints = javaTXCompiler.getConstraints();
|
||||||
|
Loading…
Reference in New Issue
Block a user