forked from JavaTX/JavaCompilerCore
Merge branch 'targetBytecode' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into targetBytecode
This commit is contained in:
commit
a15cbcba7b
BIN
resources/bytecode/javFiles/Cycle.class
Normal file
BIN
resources/bytecode/javFiles/Cycle.class
Normal file
Binary file not shown.
@ -4,10 +4,9 @@ public class TestVector {
|
||||
|
||||
m(v, w) {
|
||||
w.addElement(id(v.elementAt(0)));
|
||||
|
||||
}
|
||||
|
||||
id(x) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -240,8 +240,8 @@ public class ASTToTargetAST {
|
||||
);
|
||||
}
|
||||
|
||||
private final Map<String, FunNGenerator.GenericParameters> usedFunN = new HashMap<>();
|
||||
private final Set<Integer> usedFunNSuperTypes = new HashSet<>();
|
||||
private static final Map<String, FunNGenerator.GenericParameters> usedFunN = new HashMap<>();
|
||||
private static final Set<Integer> usedFunNSuperTypes = new HashSet<>();
|
||||
|
||||
public Map<String, byte[]> auxiliaries = new HashMap<>();
|
||||
|
||||
|
@ -6,5 +6,19 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import java.util.List;
|
||||
|
||||
public record Bound(boolean isOnMethod, RefTypeOrTPHOrWildcardOrGeneric bound) {
|
||||
public static Bound onMethod(String tph) {
|
||||
return new Bound(true, TypePlaceholder.of(tph));
|
||||
}
|
||||
|
||||
public static Bound onMethod(RefTypeOrTPHOrWildcardOrGeneric bound) {
|
||||
return new Bound(true, bound);
|
||||
}
|
||||
|
||||
public static Bound onClass(String tph) {
|
||||
return new Bound(false, TypePlaceholder.of(tph));
|
||||
}
|
||||
|
||||
public static Bound onClass(RefTypeOrTPHOrWildcardOrGeneric bound) {
|
||||
return new Bound(false, bound);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.target.generate;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
import java.util.AbstractList;
|
||||
@ -7,12 +8,19 @@ import java.util.List;
|
||||
|
||||
public class BoundsList extends AbstractList<Bound> {
|
||||
private final List<Bound> bounds;
|
||||
public final RefTypeOrTPHOrWildcardOrGeneric base;
|
||||
|
||||
public BoundsList(List<Bound> bounds) {
|
||||
public BoundsList(RefTypeOrTPHOrWildcardOrGeneric base, List<Bound> bounds) {
|
||||
this.base = base;
|
||||
this.bounds = bounds;
|
||||
}
|
||||
|
||||
public BoundsList(List<Bound> bounds) {
|
||||
this(null, bounds);
|
||||
}
|
||||
|
||||
public BoundsList(Bound... bounds) {
|
||||
this.bounds = List.of(bounds);
|
||||
this(null, List.of(bounds));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,6 +14,7 @@ import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.util.Pair;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -139,6 +140,7 @@ public abstract class GenerateGenerics {
|
||||
this.astToTargetAST = astToTargetAST;
|
||||
for (var constraint : constraints.results) {
|
||||
if (constraint instanceof PairTPHsmallerTPH p) {
|
||||
System.out.println(p.left + " " + p.left.getVariance());
|
||||
simplifiedConstraints.add(new PairLT(new TPH(p.left), new TPH(p.right)));
|
||||
} else if (constraint instanceof PairTPHEqualTPH p) {
|
||||
equality.put(p.getLeft(), p.getRight());
|
||||
@ -212,7 +214,8 @@ public abstract class GenerateGenerics {
|
||||
equality.put(entry.getKey(), to);
|
||||
}
|
||||
}
|
||||
to.setVariance(from.getVariance());
|
||||
System.out.println(from + " -> " + to + " " + from.getVariance());
|
||||
//from.setVariance(to.getVariance());
|
||||
equality.put(from, to);
|
||||
referenced.remove(new TPH(from));
|
||||
referenced.add(new TPH(to));
|
||||
@ -285,7 +288,7 @@ public abstract class GenerateGenerics {
|
||||
superType = methodCall.receiverType;
|
||||
methodCall.receiver.accept(this);
|
||||
for (int i = 0; i < methodCall.arglist.getArguments().size(); i++) {
|
||||
superType = methodCall.signature.get(i);
|
||||
superType = methodCall.arglist.getArguments().get(i).getType();
|
||||
methodCall.arglist.getArguments().get(i).accept(this);
|
||||
}
|
||||
|
||||
@ -345,7 +348,7 @@ public abstract class GenerateGenerics {
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
superType = new de.dhbwstuttgart.syntaxtree.type.Void(new NullToken());
|
||||
superType = new Void(new NullToken());
|
||||
lambdaExpression.methodBody.accept(this);
|
||||
}
|
||||
|
||||
@ -357,9 +360,9 @@ public abstract class GenerateGenerics {
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
superType = new de.dhbwstuttgart.syntaxtree.type.Void(new NullToken());
|
||||
superType = new Void(new NullToken());
|
||||
binary.lexpr.accept(this);
|
||||
superType = new de.dhbwstuttgart.syntaxtree.type.Void(new NullToken());
|
||||
superType = new Void(new NullToken());
|
||||
binary.rexpr.accept(this);
|
||||
}
|
||||
|
||||
@ -373,11 +376,11 @@ public abstract class GenerateGenerics {
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
superType = new de.dhbwstuttgart.syntaxtree.type.Void(new NullToken());
|
||||
superType = new Void(new NullToken());
|
||||
ifStmt.expr.accept(this);
|
||||
superType = new de.dhbwstuttgart.syntaxtree.type.Void(new NullToken());
|
||||
superType = new Void(new NullToken());
|
||||
ifStmt.then_block.accept(this);
|
||||
superType = new de.dhbwstuttgart.syntaxtree.type.Void(new NullToken());
|
||||
superType = new Void(new NullToken());
|
||||
ifStmt.else_block.accept(this);
|
||||
}
|
||||
|
||||
@ -389,7 +392,7 @@ public abstract class GenerateGenerics {
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
superType = new de.dhbwstuttgart.syntaxtree.type.Void(new NullToken());
|
||||
superType = new Void(new NullToken());
|
||||
whileStmt.expr.accept(this);
|
||||
superType = new Void(new NullToken());
|
||||
whileStmt.loopBlock.accept(this);
|
||||
@ -657,7 +660,12 @@ public abstract class GenerateGenerics {
|
||||
}
|
||||
}
|
||||
|
||||
private record ToAdd(TypePlaceholder left, TypePlaceholder right) {}
|
||||
|
||||
void equalizeTypeVariables(Set<Pair> input, Set<TPH> referenced) {
|
||||
|
||||
var elementsToAddToEquality = new ArrayList<ToAdd>();
|
||||
|
||||
for (var pair : new HashSet<>(input)) {
|
||||
if (pair instanceof PairLT ptph && referenced.contains(ptph.left)) {
|
||||
var chain = new ArrayList<TPH>();
|
||||
@ -698,7 +706,8 @@ public abstract class GenerateGenerics {
|
||||
for (var i = 1; i < index; i++) {
|
||||
var cur = chain.get(i);
|
||||
if (!referenced.contains(cur)) continue;
|
||||
addToEquality(cur.resolve(), start.resolve(), referenced);
|
||||
elementsToAddToEquality.add(new ToAdd(cur.resolve(), start.resolve()));
|
||||
//addToEquality(cur.resolve(), start.resolve(), referenced);
|
||||
TPH finalPrev = prev;
|
||||
input.removeIf(p -> p.equals(new PairLT(finalPrev, cur)));
|
||||
for (var pair2 : new HashSet<>(input)) {
|
||||
@ -712,6 +721,11 @@ public abstract class GenerateGenerics {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var pair : elementsToAddToEquality) {
|
||||
System.out.println(pair);
|
||||
addToEquality(pair.left, pair.right, referenced);
|
||||
}
|
||||
}
|
||||
|
||||
void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set<TPH> tphs) {
|
||||
@ -826,6 +840,58 @@ public abstract class GenerateGenerics {
|
||||
}
|
||||
}
|
||||
|
||||
Set<TPH> findConnectionToReturnType(Set<TPH> returnTypes, Set<Pair> input, Set<TPH> visited, TPH tph) {
|
||||
if (returnTypes.contains(tph)) {
|
||||
var res = new HashSet<TPH>();
|
||||
res.add(tph);
|
||||
return res;
|
||||
} else {
|
||||
for (var pair : input) if (pair instanceof PairLT ptph) {
|
||||
if (ptph.left.equals(tph) && !visited.contains(ptph.right)) {
|
||||
visited.add(ptph.right);
|
||||
var result = findConnectionToReturnType(returnTypes, input, visited, ptph.right);
|
||||
if (result.size() > 0) {
|
||||
result.add(ptph.right);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
void eliminateInfimaConnectedToReturnType(Method method, Set<Pair> input, Set<TPH> referenced) {
|
||||
var foundInfima = false;
|
||||
do {
|
||||
foundInfima = false;
|
||||
for (var constraint : new HashSet<>(input)) {
|
||||
var left = constraint.left;
|
||||
Set<PairLT> infima = new HashSet<>();
|
||||
for (var pair : input) {
|
||||
if (pair instanceof PairLT stph) {
|
||||
if (pair.left.equals(constraint.left))
|
||||
infima.add(stph);
|
||||
}
|
||||
}
|
||||
if (infima.size() > 1) {
|
||||
System.out.println(infima);
|
||||
for (var pair : infima) {
|
||||
var returnTypes = findTypeVariables(method.getReturnType());
|
||||
var chain = findConnectionToReturnType(returnTypes, input, new HashSet<>(), pair.left);
|
||||
System.out.println("Find: " + pair.left + " " + chain);
|
||||
chain.remove(pair.left);
|
||||
if (chain.size() > 0) {
|
||||
for (var tph : chain)
|
||||
addToEquality(pair.left.resolve(), tph.resolve(), referenced);
|
||||
foundInfima = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (foundInfima);
|
||||
input.removeIf((i) -> (i instanceof PairLT lt) && lt.left.equals(lt.right));
|
||||
}
|
||||
|
||||
void eliminateInfima(Set<Pair> input, Set<TPH> referenced) {
|
||||
var foundInfima = false;
|
||||
do {
|
||||
@ -850,6 +916,8 @@ public abstract class GenerateGenerics {
|
||||
}
|
||||
}
|
||||
newTph.setVariance(variance);
|
||||
System.out.println(infima + " " + infima.stream().map(i -> i.right.resolve().getVariance()).toList());
|
||||
System.out.println("Infima new TPH " + newTph + " variance " + variance);
|
||||
|
||||
//referenced.add(newTph);
|
||||
addToPairs(input, new PairLT(left, new TPH(newTph)));
|
||||
|
@ -31,7 +31,8 @@ public class GenericsResult {
|
||||
}
|
||||
|
||||
public BoundsList getBounds(RefTypeOrTPHOrWildcardOrGeneric type, ClassOrInterface clazz, Method method) {
|
||||
type = resolve(type);
|
||||
var resolvedType = resolve(type);
|
||||
type = resolvedType;
|
||||
if (type instanceof TypePlaceholder) {
|
||||
var methodGenerics = get(method);
|
||||
var classGenerics = get(clazz);
|
||||
@ -58,9 +59,9 @@ public class GenericsResult {
|
||||
}
|
||||
bound.ifPresent(result::add);
|
||||
} while (bound.isPresent());
|
||||
return new BoundsList(result);
|
||||
return new BoundsList(resolvedType, result);
|
||||
}
|
||||
return new BoundsList(List.of());
|
||||
return new BoundsList(resolvedType, List.of());
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric resolve(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
|
@ -14,6 +14,7 @@ final class JavaGenerics extends GenerateGenerics {
|
||||
@Override
|
||||
void generics(ClassOrInterface owner, Method method, Set<Pair> result, Set<TPH> referenced) {
|
||||
eliminateCycles(result, referenced);
|
||||
eliminateInfimaConnectedToReturnType(method, result, referenced);
|
||||
eliminateInfima(result, referenced);
|
||||
equalizeTypeVariables(result, referenced);
|
||||
eliminateInnerTypeVariables(referenced, result);
|
||||
|
@ -7,10 +7,11 @@ import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||
import static de.dhbwstuttgart.target.generate.ASTToTargetAST.OBJECT;
|
||||
import de.dhbwstuttgart.target.generate.Bound;
|
||||
import static de.dhbwstuttgart.target.generate.Bound.*;
|
||||
import de.dhbwstuttgart.target.generate.BoundsList;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@ -36,6 +37,15 @@ public class TestGenerics {
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertStrictlyEquals(BoundsList a, BoundsList b) {
|
||||
assertEquals(a.base, b.base);
|
||||
assertEquals(a, b);
|
||||
}
|
||||
|
||||
private static void assertStrictlyNotEquals(BoundsList a, BoundsList b) {
|
||||
assertNotEquals(a.base, b.base);
|
||||
}
|
||||
|
||||
private static Result computeGenerics(String filename) throws IOException, ClassNotFoundException {
|
||||
var file = Path.of(rootDirectory + filename).toFile();
|
||||
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()));
|
||||
@ -60,12 +70,12 @@ public class TestGenerics {
|
||||
|
||||
var ECK1 = generics.getBounds(otherMethod.getParameterList().getParameterAt(0).getType(), result.clazz, anyMethod);
|
||||
var ECK2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, anyMethod);
|
||||
var ECKChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
|
||||
assertEquals(ECK1, ECK2);
|
||||
var ECKChain = new BoundsList(onClass(OBJECT));
|
||||
assertStrictlyEquals(ECK1, ECK2);
|
||||
assertEquals(ECK2, generics.getBounds(b.getType(), result.clazz));
|
||||
|
||||
var M = generics.getBounds(a.getType(), result.clazz);
|
||||
var MChain = new BoundsList(new Bound(false, TypePlaceholder.of("ECK")), new Bound(false, ASTToTargetAST.OBJECT));
|
||||
var MChain = new BoundsList(onClass("ECK"), onClass(OBJECT));
|
||||
assertEquals(M, MChain);
|
||||
}
|
||||
|
||||
@ -79,7 +89,7 @@ public class TestGenerics {
|
||||
assertEquals(0, generics.get(fReturn).size());
|
||||
|
||||
var N = generics.getBounds(fReturn.getReturnType(), result.clazz);
|
||||
var NChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
|
||||
var NChain = new BoundsList(onClass(OBJECT));
|
||||
assertEquals(N, NChain);
|
||||
}
|
||||
|
||||
@ -91,21 +101,36 @@ public class TestGenerics {
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
assertEquals(0, generics.get(result.clazz).size());
|
||||
assertEquals(1, generics.get(m).size());
|
||||
assertEquals(2, generics.get(main).size());
|
||||
assertEquals(3, generics.get(m).size());
|
||||
assertEquals(3, generics.get(main).size());
|
||||
|
||||
var N = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||
var N2 = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||
{
|
||||
var AJ = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||
var AK = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
var KWU = generics.getBounds(((RefType) generics.resolve(m.getReturnType())).getParaList().get(0), result.clazz, m);
|
||||
var AK2 = generics.getBounds(((RefType) generics.resolve(m.getReturnType())).getParaList().get(1), result.clazz, m);
|
||||
|
||||
var NChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
|
||||
assertEquals(N, N2);
|
||||
assertEquals(N2, NChain);
|
||||
assertStrictlyEquals(AK, AK2);
|
||||
assertStrictlyNotEquals(AJ, KWU);
|
||||
var NChain = new BoundsList(onMethod(OBJECT));
|
||||
assertEquals(AJ, NChain);
|
||||
assertEquals(AK, NChain);
|
||||
assertEquals(KWU, NChain);
|
||||
}
|
||||
|
||||
var R = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||
assertEquals(R, NChain);
|
||||
{
|
||||
var O = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||
var P = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
||||
var KWQ = generics.getBounds(((RefType) generics.resolve(main.getReturnType())).getParaList().get(1), result.clazz, main);
|
||||
var O2 = generics.getBounds(((RefType) generics.resolve(main.getReturnType())).getParaList().get(0), result.clazz, main);
|
||||
|
||||
var Q2 = generics.getBounds(main.getReturnType(), result.clazz, main);
|
||||
assertEquals(Q2, NChain);
|
||||
assertStrictlyEquals(O, O2);
|
||||
assertStrictlyNotEquals(P, KWQ);
|
||||
var NChain = new BoundsList(onMethod(OBJECT));
|
||||
assertEquals(O, NChain);
|
||||
assertEquals(P, NChain);
|
||||
assertEquals(KWQ, NChain);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -123,13 +148,13 @@ public class TestGenerics {
|
||||
assertEquals(2, generics.get(m).size());
|
||||
|
||||
var R = generics.getBounds(a.getType(), result.clazz);
|
||||
var RChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
|
||||
var RChain = new BoundsList(onClass(OBJECT));
|
||||
assertEquals(R, RChain);
|
||||
|
||||
var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), 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(onMethod(OBJECT)));
|
||||
|
||||
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
|
||||
assertEquals(S, RChain);
|
||||
@ -137,7 +162,7 @@ public class TestGenerics {
|
||||
|
||||
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 XChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
|
||||
var XChain = new BoundsList(onMethod(OBJECT));
|
||||
assertEquals(X, XChain);
|
||||
assertEquals(Y, X);
|
||||
}
|
||||
@ -163,25 +188,25 @@ public class TestGenerics {
|
||||
assertEquals(3, generics.get(main).size());
|
||||
|
||||
var N = generics.getBounds(a.getType(), result.clazz);
|
||||
assertEquals(N, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(N, new BoundsList(onClass(OBJECT)));
|
||||
|
||||
var P = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||
var O = generics.getBounds(id.getReturnType(), result.clazz, id);
|
||||
assertEquals(P, O);
|
||||
assertEquals(O, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(O, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
assertEquals(generics.resolve(m.getParameterList().getParameterAt(0).getType()), generics.resolve(m.getReturnType()));
|
||||
var Y = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||
var AA = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
assertEquals(Y, AA);
|
||||
assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(AA, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
var AI = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||
var AJ = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
var AH = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||
assertEquals(AI, AJ);
|
||||
assertEquals(AJ, AH);
|
||||
assertEquals(AH, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(AH, new BoundsList(onMethod(OBJECT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -193,7 +218,7 @@ public class TestGenerics {
|
||||
assertEquals(1, generics.get(anyMethod).size());
|
||||
|
||||
var M = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
|
||||
assertEquals(M, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(M, new BoundsList(onMethod(OBJECT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -207,12 +232,12 @@ public class TestGenerics {
|
||||
var generics = result.genericsResults.get(0);
|
||||
var M = generics.getBounds(a.getType(), result.clazz);
|
||||
var DYX = generics.getBounds(b.getType(), result.clazz);
|
||||
var MChain = new BoundsList(new Bound(false, TypePlaceholder.of("DYX")), new Bound(false, ASTToTargetAST.OBJECT));
|
||||
var DYXChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
|
||||
var MChain = new BoundsList(onClass("DYX"), onClass(OBJECT));
|
||||
var DYXChain = new BoundsList(onClass(OBJECT));
|
||||
assertEquals(M, MChain);
|
||||
|
||||
var Q = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
|
||||
assertEquals(Q, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(Q, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
System.out.println(otherMethod.getReturnType());
|
||||
var DYX2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod);
|
||||
@ -235,17 +260,17 @@ public class TestGenerics {
|
||||
var generics = result.genericsResults.get(0);
|
||||
var U = generics.getBounds(id2.getParameterList().getParameterAt(0).getType(), result.clazz, id2);
|
||||
var FPT = generics.getBounds(id2.getReturnType(), result.clazz, id2);
|
||||
assertEquals(U, new BoundsList(new Bound(true, TypePlaceholder.of("FPT")), new Bound(false, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(FPT, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(U, new BoundsList(onMethod("FPT"), onClass(OBJECT)));
|
||||
assertEquals(FPT, new BoundsList(onClass(OBJECT)));
|
||||
|
||||
var AA = generics.getBounds(m.getReturnType(), 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(AC, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(AA, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(AC, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
var AH = generics.getBounds(m2.getReturnType(), result.clazz, m2);
|
||||
var AL = generics.getBounds(m2.getParameterList().getParameterAt(0).getType(), result.clazz, m2);
|
||||
assertEquals(AH, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(AH, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(AH, AL);
|
||||
}
|
||||
|
||||
@ -262,32 +287,32 @@ public class TestGenerics {
|
||||
var generics = result.genericsResults.get(0);
|
||||
var AO = generics.getBounds(a.getType(), result.clazz);
|
||||
var AOBound = new BoundsList(
|
||||
new Bound(false, TypePlaceholder.of("Y")),
|
||||
new Bound(false, TypePlaceholder.of("AK")),
|
||||
new Bound(false, TypePlaceholder.of("AE")),
|
||||
new Bound(false, ASTToTargetAST.OBJECT)
|
||||
onClass("Y"),
|
||||
onClass("AK"),
|
||||
onClass("AE"),
|
||||
onClass(OBJECT)
|
||||
);
|
||||
assertEquals(AO, AOBound);
|
||||
|
||||
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
|
||||
var c = new ArrayList<Bound>();
|
||||
c.add(new Bound(true, TypePlaceholder.of("AO")));
|
||||
c.add(onMethod("AO"));
|
||||
c.addAll(AOBound);
|
||||
var SChain = new BoundsList(c);
|
||||
assertEquals(S, SChain);
|
||||
|
||||
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
var YChain = new BoundsList(new Bound(true, TypePlaceholder.of("AE")), new Bound(false, ASTToTargetAST.OBJECT));
|
||||
var YChain = new BoundsList(onMethod("AE"), onClass(OBJECT));
|
||||
var AE = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||
assertEquals(Y, YChain);
|
||||
assertEquals(AE, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(AE, new BoundsList(onClass(OBJECT)));
|
||||
|
||||
// TODO main seems to change between runs
|
||||
/*var AE2 = generics.getBounds(main.getReturnType(), result.clazz, main);
|
||||
var AF = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||
var AG = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
||||
assertEquals(AE, AE2));
|
||||
assertEquals(AF, new BoundsList(new Bound(true, TypePlaceholder.of("AK")), new Bound(true, TypePlaceholder.of("AE")), new Bound(false, ASTToTargetAST.OBJECT))));
|
||||
assertEquals(AF, new BoundsList(onMethod("AK"), onMethod("AE"), onClass(OBJECT))));
|
||||
assertEquals(AG, SChain));*/
|
||||
}
|
||||
|
||||
@ -306,16 +331,16 @@ public class TestGenerics {
|
||||
var generics = result.genericsResults.get(0);
|
||||
var O = generics.getBounds(id.getReturnType(), result.clazz, id);
|
||||
var O2 = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||
assertEquals(O, O2);
|
||||
assertEquals(O2, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertStrictlyEquals(O, O2);
|
||||
assertEquals(O2, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
// TODO Maybe test in other ways if the parameter generics equals the return generics
|
||||
var S = generics.getBounds(main.getReturnType(), result.clazz, main);
|
||||
var S2 = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||
var T = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
||||
assertEquals(S, S2);
|
||||
assertEquals(S2, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(T, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
var S2 = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
||||
var T = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||
assertStrictlyEquals(S, S2);
|
||||
assertEquals(S2, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(T, new BoundsList(onMethod(OBJECT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -330,11 +355,11 @@ public class TestGenerics {
|
||||
|
||||
var S = generics.getBounds(((RefType) par1).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, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(ACM, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(S, new BoundsList(onMethod("V"), onMethod(OBJECT)));
|
||||
assertEquals(ACM, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
var Y = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||
assertEquals(Y, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(Y, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(Y, generics.getBounds(id.getReturnType(), result.clazz, id));
|
||||
}
|
||||
|
||||
@ -348,13 +373,13 @@ public class TestGenerics {
|
||||
var par1 = generics.resolve(add.getParameterList().getParameterAt(0).getType());
|
||||
var ACK = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, add);
|
||||
var O = generics.getBounds(add.getParameterList().getParameterAt(1).getType(), result.clazz, add);
|
||||
assertEquals(ACK, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(O, new BoundsList(new Bound(true, TypePlaceholder.of("ACK")), new Bound(true, ASTToTargetAST.OBJECT)));
|
||||
assertEquals(ACK, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(O, new BoundsList(onMethod("ACK"), onMethod(OBJECT)));
|
||||
|
||||
var par2 = generics.resolve(main.getParameterList().getParameterAt(0).getType());
|
||||
var ACK2 = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, add);
|
||||
var V = generics.getBounds(add.getParameterList().getParameterAt(1).getType(), result.clazz, add);
|
||||
assertEquals(ACK2, ACK);
|
||||
assertStrictlyEquals(ACK2, ACK);
|
||||
assertEquals(V, O);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user