test & fix: add Testcase for Heritage-detection and removed unnecessary creation of Constraints.
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 5m42s
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 5m42s
This commit is contained in:
parent
4f0162ba64
commit
96eb504174
22
resources/bytecode/javFiles/SwitchCaseHeritageDetection.jav
Normal file
22
resources/bytecode/javFiles/SwitchCaseHeritageDetection.jav
Normal file
@ -0,0 +1,22 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.Object;
|
||||
import java.lang.Float;
|
||||
import java.lang.String;
|
||||
|
||||
public class NumberOrText{}
|
||||
public class Text extends NumberOrText{};
|
||||
public class Number extends NumberOrText{};
|
||||
|
||||
|
||||
public record Cons(Integer a, NumberOrText l){}
|
||||
|
||||
|
||||
public class SwitchCaseHeritageDetection {
|
||||
public main(o) {
|
||||
return switch(o) {
|
||||
case Cons(a, Text b) -> "Second Element is a Text";
|
||||
case Cons(a, Number b) -> "Second Element is a Number";
|
||||
default -> "None of the above cases";
|
||||
};
|
||||
}
|
||||
}
|
@ -10,8 +10,8 @@ public record Rec(Object a, Object b) {}
|
||||
public class SwitchInfered {
|
||||
public main(o) {
|
||||
return switch (o) {
|
||||
case Rec(a, b) -> a;
|
||||
default -> 0;
|
||||
case Rec(a, b) -> "asd";
|
||||
default -> "cde";
|
||||
};
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
sealed interface List<A> permits Cons, Nil {}
|
||||
|
||||
record Cons(A a, List<A> l) implements List<A> {}
|
||||
|
||||
record Nil()implements List<A> {
|
||||
|
||||
void m(x) {
|
||||
switch(x) {
|
||||
case Cons(a, Cons(b, List<A> l)) -> System.out.println(a);
|
||||
case Cons(a, Nil()) -> System.out.println(a);
|
||||
case Nil() -> System.out.println("Nil");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -877,8 +877,6 @@ public class TYPEStmt implements StatementVisitor {
|
||||
var clazz = interestingClasses.get(j);
|
||||
for (int k = 0; k < clazz.getConstructors().size(); k++) {
|
||||
var constructor = clazz.getConstructors().get(k);
|
||||
//Erster Constraint wahrscheinlich unnötig.
|
||||
constraintsSet.addUndConstraint(new Pair( clazz.getFieldDecl().get(i).getType(), constructor.getParameterList().getParameterAt(i).getType(), PairOperator.SMALLERDOT, loc(constructor.getParameterList().getParameterAt(i).getOffset())));
|
||||
constraintsSet.addUndConstraint(new Pair(supPattern.getType(), constructor.getParameterList().getParameterAt(i).getType(), PairOperator.SMALLERDOT, loc(constructor.getParameterList().getParameterAt(i).getOffset())));
|
||||
|
||||
}
|
||||
|
@ -696,18 +696,25 @@ public class TestComplete {
|
||||
@Ignore("Not implemented")
|
||||
@Test
|
||||
public void testRecordList() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "recordList.jav");
|
||||
var clazz = classFiles.get("Nil");
|
||||
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchCaseHeritageDetection.jav");
|
||||
var clazz = classFiles.get("SwitchCaseHeritageDetection");
|
||||
var clazzAbst = classFiles.get("NumberOrText");
|
||||
var clazzStringer = classFiles.get("Text");
|
||||
var clazzNumber = classFiles.get("Number");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
var swtch = clazz.getDeclaredMethod("m", Object.class);
|
||||
var swtch = clazz.getDeclaredMethod("main", Object.class);
|
||||
|
||||
//var record = classFiles.get("Rec");
|
||||
//var ctor = record.getDeclaredConstructor(Object.class, Object.class);
|
||||
//var r1 = ctor.newInstance(1, 1);
|
||||
var record = classFiles.get("Cons");
|
||||
|
||||
|
||||
assertEquals(swtch.invoke(instance, null), 2);
|
||||
|
||||
var ctor = record.getDeclaredConstructor(Integer.class, clazzAbst.getConstructor().newInstance().getClass());
|
||||
var r1 = ctor.newInstance(1, clazzStringer.getConstructor().newInstance());
|
||||
var r2 = ctor.newInstance(1, clazzNumber.getConstructor().newInstance());
|
||||
|
||||
|
||||
assertEquals(swtch.invoke(instance, r1), "Second Element is a Text");
|
||||
assertEquals(swtch.invoke(instance, r2), "Second Element is a Number");
|
||||
}
|
||||
|
||||
@Ignore("Not implemented")
|
||||
|
Loading…
Reference in New Issue
Block a user