forked from JavaTX/JavaCompilerCore
Examples
This commit is contained in:
parent
5d0d7a6d94
commit
e31f1c59e1
13
resources/bytecode/javFiles/Chain.jav
Normal file
13
resources/bytecode/javFiles/Chain.jav
Normal file
@ -0,0 +1,13 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
public class Chain {
|
||||
x = 5;
|
||||
|
||||
chain() {
|
||||
return this;
|
||||
}
|
||||
|
||||
m() {
|
||||
return this.chain().chain().chain().x;
|
||||
}
|
||||
}
|
15
resources/bytecode/javFiles/FunctionalInterface.jav
Normal file
15
resources/bytecode/javFiles/FunctionalInterface.jav
Normal 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;
|
||||
}
|
||||
}
|
@ -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 {
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user