This commit is contained in:
Daniel Holle 2023-10-27 14:27:47 +02:00
parent 5d0d7a6d94
commit e31f1c59e1
4 changed files with 46 additions and 2 deletions

View File

@ -0,0 +1,13 @@
import java.lang.Integer;
public class Chain {
x = 5;
chain() {
return this;
}
m() {
return this.chain().chain().chain().x;
}
}

View File

@ -0,0 +1,15 @@
import java.lang.Integer;
import java.util.function.Function;
public class FunctionalInterface {
Integer accept(Function<Integer, Integer> f) {
return f.apply(20);
}
Integer m() {
var v = accept(i -> {
return i * 10;
});
return v;
}
}

View File

@ -1,6 +1,4 @@
package de.dhbwstuttgart.target.tree.expression;
import de.dhbwstuttgart.target.tree.type.TargetType;
public record TargetForEach(TargetExpression vardecl, TargetExpression list) implements TargetExpression {
}

View File

@ -736,4 +736,22 @@ public class TestComplete {
var m = clazz.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instance, 10), 60);
}
@Test
public void testFunctionalInterface() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "FunctionalInterface.jav");
var clazz = classFiles.get("FunctionalInterface");
var instance = clazz.getDeclaredConstructor().newInstance();
var m = clazz.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instance, 20), 400);
}
@Test
public void testChain() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Chain.jav");
var clazz = classFiles.get("Chain");
var instance = clazz.getDeclaredConstructor().newInstance();
var m = clazz.getDeclaredMethod("m");
assertEquals(m.invoke(instance), 5);
}
}