From 7785c2d0aad61da34e4d81f597307d8779e5ad73 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Mon, 5 Aug 2024 11:54:13 +0200 Subject: [PATCH 1/2] Fix equals method of ClassOrInterface --- .../java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index 71240ae9..834fabb7 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -188,9 +188,8 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ClassOrInterface that = (ClassOrInterface) o; - return Objects.equals(name, that.name); + if (!(o instanceof ClassOrInterface other)) return false; + return Objects.equals(name, other.name); } @Override From ce4347dd96c5f224c78fb113192678309c8e81ee Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Tue, 6 Aug 2024 12:42:09 +0200 Subject: [PATCH 2/2] Fix Y Test #341 --- resources/bytecode/javFiles/Y.jav | 40 +++++-------------- .../StatementGenerator.java | 2 + src/test/java/TestComplete.java | 6 ++- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/resources/bytecode/javFiles/Y.jav b/resources/bytecode/javFiles/Y.jav index 0c14b498..b2e65047 100644 --- a/resources/bytecode/javFiles/Y.jav +++ b/resources/bytecode/javFiles/Y.jav @@ -2,41 +2,21 @@ import java.lang.Integer; public class Y { y; - //factorial; - public Y() { - 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().getY(); - factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); }); + y = f -> t -> f.apply(y.apply(f)).apply(t); } } -ergibt Parse-Error -class fac1 { - factorial; - - fac1() { +public class Fac1 { + public factorial; + public Fac1() { var y; - y = new Y<>().y; + var tmp = new Y<>(); // TODO Having new Y<>().y on one line doesn't work, see FIXME in StatementGenerator + y = tmp.y; factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); }); } - public static void main(String args[]) { - System.out.println(new fac1().factorial.apply(3)); + + public fac(v) { + return factorial.apply(v); } - -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index f4587b6b..573b53f2 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -697,6 +697,7 @@ 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 @@ -779,6 +780,7 @@ 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: diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index c4599e02..3b1e5392 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -602,7 +602,11 @@ public class TestComplete { @Test public void yTest() throws Exception { var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Y.jav"); - var instance = classFiles.get("Y").getDeclaredConstructor().newInstance(); + + var fac1 = classFiles.get("Fac1"); + var instance = fac1.getDeclaredConstructor().newInstance(); + var fac = fac1.getDeclaredMethod("fac", Integer.class); + assertEquals(fac.invoke(instance, 10), 3628800); } @Test