Compare commits
No commits in common. "94c359f7a11a919f81d5d409176ea780e8c6038a" and "96eb5041746731e3339d4dafc164d1be2049ad74" have entirely different histories.
94c359f7a1
...
96eb504174
@ -1,2 +0,0 @@
|
||||
public record Bug343() {
|
||||
}
|
@ -3,7 +3,7 @@ import java.lang.Object;
|
||||
import java.lang.Float;
|
||||
import java.lang.String;
|
||||
|
||||
public record Rec(Object a, Object b) {}
|
||||
public record Rec(Object a, Object b) {}
|
||||
|
||||
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.Object;
|
||||
import java.lang.Float;
|
||||
import java.lang.String;
|
||||
|
||||
sealed interface List permits LinkedElem {}
|
||||
|
||||
|
||||
public record LinkedElem(Integer a,List l) implements List{} //Implementiert List und wird auch permittet
|
||||
public record Elem(Integer c) implements List{} //Implementiert List, wird aber nicht permittet
|
||||
|
||||
public class SwitchCaseHeritageDetection {
|
||||
public main(o) {
|
||||
return switch(o) {
|
||||
case LinkedElem(a, Elem(e)) -> a + e;
|
||||
case LinkedElem(a, LinkedElem(e, Elem(f))) -> a + e + f;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -2,21 +2,41 @@ import java.lang.Integer;
|
||||
|
||||
public class Y {
|
||||
y;
|
||||
//factorial;
|
||||
|
||||
public Y() {
|
||||
y = f -> t -> f.apply(y.apply(f)).apply(t);
|
||||
y = f -> t -> f.apply(y.apply(f)).apply(t);
|
||||
//factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
|
||||
}
|
||||
/*
|
||||
getY() {
|
||||
return y;
|
||||
}
|
||||
*/
|
||||
}
|
||||
/*
|
||||
class fac1 {
|
||||
factorial;
|
||||
|
||||
fac1() {
|
||||
var y;
|
||||
y = new Y<Integer,Integer,Integer,Integer,Integer>().getY();
|
||||
factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
|
||||
}
|
||||
}
|
||||
|
||||
public class Fac1 {
|
||||
public factorial;
|
||||
public Fac1() {
|
||||
ergibt Parse-Error
|
||||
class fac1 {
|
||||
factorial;
|
||||
|
||||
fac1() {
|
||||
var y;
|
||||
var tmp = new Y<>(); // TODO Having new Y<>().y on one line doesn't work, see FIXME in StatementGenerator
|
||||
y = tmp.y;
|
||||
y = new Y<>().y;
|
||||
factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
|
||||
}
|
||||
|
||||
public fac(v) {
|
||||
return factorial.apply(v);
|
||||
public static void main(String args[]) {
|
||||
System.out.println(new fac1().factorial.apply(3));
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
@ -698,7 +698,6 @@ public class StatementGenerator {
|
||||
if (!Objects.isNull(expr.methodCall())) {
|
||||
return convert(expr.methodCall(), expr.expression(), offset);
|
||||
} else if (!Objects.isNull(expr.identifier())) {
|
||||
// FIXME This is not the right way of handling any of this
|
||||
return generateLocalOrFieldVarOrClassName(expr.getText(), offset);
|
||||
} else {
|
||||
// Für alle anderen Optionen, wie Feldzugriff, Aufrufe von super oder explizite
|
||||
@ -781,7 +780,6 @@ public class StatementGenerator {
|
||||
* @return
|
||||
*/
|
||||
private Expression generateLocalOrFieldVarOrClassName(String expression, Token offset) {
|
||||
// FIXME Why does this take a String argument???
|
||||
String[] parts = expression.split("\\.");
|
||||
if (parts.length < 2) {
|
||||
// Check for localVar:
|
||||
|
@ -254,10 +254,7 @@ public class SyntaxTreeGenerator {
|
||||
List<RefType> implementedInterfaces = new ArrayList<>();
|
||||
List<Pattern> constructorParameters = new ArrayList<>();
|
||||
List<Statement> constructorStatements = new ArrayList<>();
|
||||
|
||||
List<Java17Parser.RecordComponentContext> components = recordDeclaration.recordHeader().recordComponentList() != null ?
|
||||
recordDeclaration.recordHeader().recordComponentList().recordComponent(): List.of();
|
||||
for (RecordComponentContext component : components) {
|
||||
for (RecordComponentContext component : recordDeclaration.recordHeader().recordComponentList().recordComponent()) {
|
||||
int fieldmodifiers = allmodifiers.get("private") + allmodifiers.get("final");
|
||||
String fieldname = component.identifier().getText();
|
||||
Token fieldoffset = component.getStart();
|
||||
|
@ -863,7 +863,26 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
if (el.getPattern() instanceof RecordPattern) {
|
||||
var pattern = (RecordPattern) recType.getPattern();
|
||||
recursiveAddRecordConstraints(pattern);
|
||||
|
||||
var allClasses = info.getAvailableClasses();
|
||||
var interestingClasses = allClasses.stream().filter(as -> as.getClassName().equals(((RefType) el.getType()).getName())).toList();
|
||||
|
||||
var test = "";
|
||||
|
||||
var constructors = interestingClasses.get(0).getConstructors();
|
||||
|
||||
for (int i = 0; i < pattern.getSubPattern().size(); i++) {
|
||||
var supPattern = pattern.getSubPattern().get(i);
|
||||
for (int j = 0; j < interestingClasses.size(); j++) {
|
||||
var clazz = interestingClasses.get(j);
|
||||
for (int k = 0; k < clazz.getConstructors().size(); k++) {
|
||||
var constructor = clazz.getConstructors().get(k);
|
||||
constraintsSet.addUndConstraint(new Pair(supPattern.getType(), constructor.getParameterList().getParameterAt(i).getType(), PairOperator.SMALLERDOT, loc(constructor.getParameterList().getParameterAt(i).getOffset())));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -877,37 +896,6 @@ public class TYPEStmt implements StatementVisitor {
|
||||
switchStack.pop();
|
||||
}
|
||||
|
||||
public void recursiveAddRecordConstraints(RecordPattern el) {
|
||||
var pattern = el;
|
||||
|
||||
var allClasses = info.getAvailableClasses();
|
||||
var interestingClasses = allClasses.stream().filter(as -> as.getClassName().equals(((RefType) el.getType()).getName())).toList();
|
||||
|
||||
var test = "";
|
||||
|
||||
var constructors = interestingClasses.get(0).getConstructors();
|
||||
|
||||
for (int i = 0; i < pattern.getSubPattern().size(); i++) {
|
||||
var supPattern = pattern.getSubPattern().get(i);
|
||||
if (supPattern instanceof RecordPattern) {
|
||||
recursiveAddRecordConstraints((RecordPattern) supPattern);
|
||||
} else {
|
||||
for (int j = 0; j < interestingClasses.size(); j++) {
|
||||
var clazz = interestingClasses.get(j);
|
||||
for (int k = 0; k < clazz.getConstructors().size(); k++) {
|
||||
var constructor = clazz.getConstructors().get(k);
|
||||
constraintsSet.addUndConstraint(new Pair(supPattern.getType(), constructor.getParameterList().getParameterAt(i).getType(), PairOperator.SMALLERDOT, loc(constructor.getParameterList().getParameterAt(i).getOffset())));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(SwitchBlock switchBlock) {
|
||||
for (var stmt : switchBlock.statements) {
|
||||
|
@ -605,11 +605,7 @@ public class TestComplete {
|
||||
@Test
|
||||
public void yTest() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Y.jav");
|
||||
|
||||
var fac1 = classFiles.get("Fac1");
|
||||
var instance = fac1.getDeclaredConstructor().newInstance();
|
||||
var fac = fac1.getDeclaredMethod("fac", Integer.class);
|
||||
assertEquals(fac.invoke(instance, 10), 3628800);
|
||||
var instance = classFiles.get("Y").getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -680,6 +676,7 @@ public class TestComplete {
|
||||
assertEquals(swtch.invoke(instance, "Some string"), 0);
|
||||
}
|
||||
|
||||
@Ignore("Not implemented")
|
||||
@Test
|
||||
public void testSwitchInfered() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchInfered.jav");
|
||||
@ -696,9 +693,9 @@ public class TestComplete {
|
||||
assertEquals(swtch.invoke(instance, r1), "asd");
|
||||
}
|
||||
|
||||
|
||||
@Ignore("Not implemented")
|
||||
@Test
|
||||
public void testSwitchCaseHeritageDetection() throws Exception {
|
||||
public void testRecordList() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchCaseHeritageDetection.jav");
|
||||
var clazz = classFiles.get("SwitchCaseHeritageDetection");
|
||||
var clazzAbst = classFiles.get("NumberOrText");
|
||||
@ -719,32 +716,6 @@ public class TestComplete {
|
||||
assertEquals(swtch.invoke(instance, r1), "Second Element is a Text");
|
||||
assertEquals(swtch.invoke(instance, r2), "Second Element is a Number");
|
||||
}
|
||||
@Ignore("Not implemented")
|
||||
@Test
|
||||
public void testSwitchListRecord() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchRecordList.jav");
|
||||
|
||||
var clazz = classFiles.get("SwitchCaseHeritageDetection");
|
||||
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
var swtch = clazz.getDeclaredMethod("main", Object.class);
|
||||
|
||||
var linkedElem = classFiles.get("LinkedElem");
|
||||
var listInterface = classFiles.get("List");
|
||||
var elem = classFiles.get("Elem");
|
||||
|
||||
|
||||
var constructorLinkedElem = linkedElem.getDeclaredConstructor(Integer.class, listInterface);
|
||||
var constructorElem = elem.getConstructor(Integer.class);
|
||||
|
||||
|
||||
|
||||
var listWithMoreThanOneElement = constructorLinkedElem.newInstance(5, constructorLinkedElem.newInstance(1, constructorElem.newInstance(5)));
|
||||
assertEquals(swtch.invoke(instance, listWithMoreThanOneElement), 11);
|
||||
|
||||
var listWithOneElement = constructorLinkedElem.newInstance(5, constructorElem.newInstance(5));
|
||||
assertEquals(swtch.invoke(instance, listWithOneElement), 10);
|
||||
}
|
||||
|
||||
@Ignore("Not implemented")
|
||||
@Test
|
||||
@ -1221,11 +1192,4 @@ public class TestComplete {
|
||||
var clazz = classFiles.get("Bug338");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug343() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug343.jav");
|
||||
var clazz = classFiles.get("Bug343");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user