Change tests
This commit is contained in:
parent
1ad5540500
commit
f7b60214fa
@ -647,20 +647,23 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void equalizeTypeVariables(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
void equalizeTypeVariables(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
|
System.out.println(input);
|
||||||
for (var pair : new HashSet<>(input)) {
|
for (var pair : new HashSet<>(input)) {
|
||||||
if (pair instanceof PairTPHsmallerTPH ptph) {
|
if (pair instanceof PairTPHsmallerTPH ptph) {
|
||||||
|
System.out.println(pair + " " + ptph.left.getVariance() + " " + ptph.right.getVariance());
|
||||||
if (ptph.left.getVariance() == 1 && ptph.right.getVariance() == -1) {
|
if (ptph.left.getVariance() == 1 && ptph.right.getVariance() == -1) {
|
||||||
addToEquality(equality, ptph.left, ptph.right);
|
addToEquality(equality, ptph.left, ptph.right);
|
||||||
input.remove(ptph);
|
input.remove(ptph);
|
||||||
for (var pair2 : new HashSet<>(input)) {
|
for (var pair2 : new HashSet<>(simplifiedConstraints)) {
|
||||||
if (pair2 instanceof PairTPHsmallerTPH ptph2 && ptph2.right.equals(ptph.left)) {
|
if (pair2.right.equals(ptph.left)) {
|
||||||
input.remove(pair2);
|
simplifiedConstraints.remove(pair2);
|
||||||
addToPairs(input, new PairTPHsmallerTPH(ptph2.left, ptph.right));
|
simplifiedConstraints.add(new PairTPHsmallerTPH(pair2.left, ptph.right));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set<TypePlaceholder> tphs, Map<TypePlaceholder, TypePlaceholder> equality) {
|
void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set<TypePlaceholder> tphs, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
|
@ -18,14 +18,14 @@ public class GenericsResult {
|
|||||||
public Set<ResultPair<?, ?>> get(ClassOrInterface clazz) {
|
public Set<ResultPair<?, ?>> get(ClassOrInterface clazz) {
|
||||||
var generics = this.sigma.computedGenericsOfClasses.get(clazz);
|
var generics = this.sigma.computedGenericsOfClasses.get(clazz);
|
||||||
if (generics == null) return Set.of();
|
if (generics == null) return Set.of();
|
||||||
return generics.txGenerics();
|
return generics.javaGenerics();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Compute generics if not present?
|
// TODO Compute generics if not present?
|
||||||
public Set<ResultPair<?, ?>> get(Method method) {
|
public Set<ResultPair<?, ?>> get(Method method) {
|
||||||
var generics = this.sigma.computedGenericsOfMethods.get(method);
|
var generics = this.sigma.computedGenericsOfMethods.get(method);
|
||||||
if (generics == null) return Set.of();
|
if (generics == null) return Set.of();
|
||||||
return generics.txGenerics();
|
return generics.javaGenerics();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoundsList getBounds(RefTypeOrTPHOrWildcardOrGeneric type, ClassOrInterface clazz) {
|
public BoundsList getBounds(RefTypeOrTPHOrWildcardOrGeneric type, ClassOrInterface clazz) {
|
||||||
|
@ -127,26 +127,22 @@ public class TestGenerics {
|
|||||||
assertEquals(R, RChain);
|
assertEquals(R, RChain);
|
||||||
|
|
||||||
var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||||
var OChain = new BoundsList(new Bound(true, TypePlaceholder.of("AB")), new Bound(true, ASTToTargetAST.OBJECT));
|
|
||||||
assertEquals(O, OChain);
|
|
||||||
var AB = generics.getBounds(id.getReturnType(), result.clazz, id);
|
var AB = generics.getBounds(id.getReturnType(), result.clazz, id);
|
||||||
|
assertEquals(O, AB);
|
||||||
assertEquals(AB, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(AB, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
|
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
|
||||||
var SChain = new BoundsList(new Bound(true, TypePlaceholder.of("R")), new Bound(false, ASTToTargetAST.OBJECT));
|
assertEquals(S, RChain);
|
||||||
assertEquals(S, SChain);
|
|
||||||
assertEquals(generics.getBounds(setA.getReturnType(), result.clazz, setA), RChain);
|
assertEquals(generics.getBounds(setA.getReturnType(), result.clazz, setA), RChain);
|
||||||
|
|
||||||
var X = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
var X = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||||
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||||
var XChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
|
var XChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
|
||||||
var YChain = new BoundsList(new Bound(true, TypePlaceholder.of("Y")), new Bound(true, ASTToTargetAST.OBJECT));
|
|
||||||
assertEquals(X, XChain);
|
assertEquals(X, XChain);
|
||||||
assertEquals(Y, YChain);
|
assertEquals(Y, X);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Not implemented")
|
|
||||||
public void testLocalVarLambda() throws Exception {
|
public void testLocalVarLambda() throws Exception {
|
||||||
var result = computeGenerics("TestLocalVarLambda.jav");
|
var result = computeGenerics("TestLocalVarLambda.jav");
|
||||||
// TODO Generics of lambdas
|
// TODO Generics of lambdas
|
||||||
@ -221,9 +217,10 @@ public class TestGenerics {
|
|||||||
var Q = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
|
var Q = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
|
||||||
assertEquals(Q, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(Q, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
|
System.out.println(otherMethod.getReturnType());
|
||||||
var DYX2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod);
|
var DYX2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod);
|
||||||
assertEquals(DYX, DYX2);
|
assertEquals(DYX, DYX2);
|
||||||
assertEquals(DYX2, DYXChain);
|
assertEquals(DYX, generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -247,7 +244,7 @@ public class TestGenerics {
|
|||||||
var AA = generics.getBounds(m.getReturnType(), result.clazz, m);
|
var AA = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||||
var AC = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
var AC = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||||
assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
assertEquals(AC, new BoundsList(new Bound(true, TypePlaceholder.of("AD")), new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(AC, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
var AH = generics.getBounds(m2.getReturnType(), result.clazz, m2);
|
var AH = generics.getBounds(m2.getReturnType(), result.clazz, m2);
|
||||||
var AL = generics.getBounds(m2.getParameterList().getParameterAt(0).getType(), result.clazz, m2);
|
var AL = generics.getBounds(m2.getParameterList().getParameterAt(0).getType(), result.clazz, m2);
|
||||||
@ -298,9 +295,9 @@ public class TestGenerics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("main changes in between runs")
|
|
||||||
public void testTwoArgs2() throws Exception {
|
public void testTwoArgs2() throws Exception {
|
||||||
var result = computeGenerics("TestTwoArgs2.jav");
|
var result = computeGenerics("TestTwoArgs2.jav");
|
||||||
|
// TODO Test generics
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -327,6 +324,7 @@ public class TestGenerics {
|
|||||||
public void testVector() throws Exception {
|
public void testVector() throws Exception {
|
||||||
var result = computeGenerics("TestVector.jav");
|
var result = computeGenerics("TestVector.jav");
|
||||||
var m = result.findMethod("m");
|
var m = result.findMethod("m");
|
||||||
|
var id = result.findMethod("id");
|
||||||
|
|
||||||
var generics = result.genericsResults.get(0);
|
var generics = result.genericsResults.get(0);
|
||||||
var par1 = generics.resolve(m.getParameterList().getParameterAt(0).getType());
|
var par1 = generics.resolve(m.getParameterList().getParameterAt(0).getType());
|
||||||
@ -334,8 +332,12 @@ public class TestGenerics {
|
|||||||
|
|
||||||
var S = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, m);
|
var S = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, m);
|
||||||
var ACM = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, m);
|
var ACM = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, m);
|
||||||
assertEquals(S, new BoundsList(new Bound(true, TypePlaceholder.of("V")), new Bound(true, TypePlaceholder.of("ACM")), new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(S, new BoundsList(new Bound(true, TypePlaceholder.of("V")), new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
assertEquals(ACM, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
assertEquals(ACM, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
|
||||||
|
var Y = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||||
|
assertEquals(Y, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||||
|
assertEquals(Y, generics.getBounds(id.getReturnType(), result.clazz, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user