|
@@ -4,7 +4,6 @@ import net.ranides.assira.generic.TypeToken;
|
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
-import java.util.Set;
|
|
|
|
|
import java.util.function.BiFunction;
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
import java.util.function.Supplier;
|
|
import java.util.function.Supplier;
|
|
@@ -13,7 +12,7 @@ import static net.ranides.assira.junit.NewAssert.assertThrows;
|
|
|
import static net.ranides.assira.reflection.IAttribute.*;
|
|
import static net.ranides.assira.reflection.IAttribute.*;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
|
|
-public class LamdaReflectTest {
|
|
|
|
|
|
|
+public class LambdaReflectTest {
|
|
|
|
|
|
|
|
public static final IClass<?> STRING = IClass.typeinfo(String.class);
|
|
public static final IClass<?> STRING = IClass.typeinfo(String.class);
|
|
|
|
|
|
|
@@ -46,7 +45,7 @@ public class LamdaReflectTest {
|
|
|
@Test
|
|
@Test
|
|
|
public void testInvalidLambda() {
|
|
public void testInvalidLambda() {
|
|
|
assertThrows(IllegalArgumentException.class, ()->{
|
|
assertThrows(IllegalArgumentException.class, ()->{
|
|
|
- LamdaReflect.typeinfo("Hello world");
|
|
|
|
|
|
|
+ LambdaReflect.typeinfo("Hello world");
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -167,8 +166,8 @@ public class LamdaReflectTest {
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void testInlineCall() {
|
|
public void testInlineCall() {
|
|
|
- IMethod m21 = LamdaReflect.typeinfo(pass2((Integer a) -> 3*a));
|
|
|
|
|
- IMethod m11 = LamdaReflect.typeinfo(pass1((Integer a) -> 3*a));
|
|
|
|
|
|
|
+ IMethod m21 = LambdaReflect.typeinfo(pass2((Integer a) -> 3*a));
|
|
|
|
|
+ IMethod m11 = LambdaReflect.typeinfo(pass1((Integer a) -> 3*a));
|
|
|
|
|
|
|
|
assertEquals(24, m21.call(8));
|
|
assertEquals(24, m21.call(8));
|
|
|
assertEquals(24, m21.invoke(null, 8));
|
|
assertEquals(24, m21.invoke(null, 8));
|
|
@@ -189,8 +188,8 @@ public class LamdaReflectTest {
|
|
|
MTFunction.Lame f1 = (a,b,c) -> a.intValue() + b + c;
|
|
MTFunction.Lame f1 = (a,b,c) -> a.intValue() + b + c;
|
|
|
MTFunction.LameLong f2 = (a,b,c) -> (int)a + b + c;
|
|
MTFunction.LameLong f2 = (a,b,c) -> (int)a + b + c;
|
|
|
|
|
|
|
|
- IMethod m1 = LamdaReflect.typeinfo(f1);
|
|
|
|
|
- IMethod m2 = LamdaReflect.typeinfo(f2);
|
|
|
|
|
|
|
+ IMethod m1 = LambdaReflect.typeinfo(f1);
|
|
|
|
|
+ IMethod m2 = LambdaReflect.typeinfo(f2);
|
|
|
|
|
|
|
|
MTFunction<Long> g1 = m1.handle(new TypeToken<MTFunction<Long>>(){});
|
|
MTFunction<Long> g1 = m1.handle(new TypeToken<MTFunction<Long>>(){});
|
|
|
MTFunction<Long> g2 = m2.handle(new TypeToken<MTFunction<Long>>(){});
|
|
MTFunction<Long> g2 = m2.handle(new TypeToken<MTFunction<Long>>(){});
|
|
@@ -200,11 +199,11 @@ public class LamdaReflectTest {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void testAPI(IAttributes exp, Object function1, Object function2, Object function3, Object function4, Object function5) {
|
|
private void testAPI(IAttributes exp, Object function1, Object function2, Object function3, Object function4, Object function5) {
|
|
|
- IMethod m1 = LamdaReflect.typeinfo(function1);
|
|
|
|
|
- IMethod m2 = LamdaReflect.typeinfo(function2);
|
|
|
|
|
- IMethod m3 = LamdaReflect.typeinfo(function3);
|
|
|
|
|
- IMethod m4 = LamdaReflect.typeinfo(function4);
|
|
|
|
|
- IMethod m5 = LamdaReflect.typeinfo(function5);
|
|
|
|
|
|
|
+ IMethod m1 = LambdaReflect.typeinfo(function1);
|
|
|
|
|
+ IMethod m2 = LambdaReflect.typeinfo(function2);
|
|
|
|
|
+ IMethod m3 = LambdaReflect.typeinfo(function3);
|
|
|
|
|
+ IMethod m4 = LambdaReflect.typeinfo(function4);
|
|
|
|
|
+ IMethod m5 = LambdaReflect.typeinfo(function5);
|
|
|
|
|
|
|
|
// name
|
|
// name
|
|
|
assertEquals("apply", m1.name());
|
|
assertEquals("apply", m1.name());
|
|
@@ -254,11 +253,11 @@ public class LamdaReflectTest {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void testLambdaCall(Object function1, Object function2, Object function3, Object function4, Object function5) {
|
|
private void testLambdaCall(Object function1, Object function2, Object function3, Object function4, Object function5) {
|
|
|
- IMethod m1 = LamdaReflect.typeinfo(function1);
|
|
|
|
|
- IMethod m2 = LamdaReflect.typeinfo(function2);
|
|
|
|
|
- IMethod m3 = LamdaReflect.typeinfo(function3);
|
|
|
|
|
- IMethod m4 = LamdaReflect.typeinfo(function4);
|
|
|
|
|
- IMethod m5 = LamdaReflect.typeinfo(function5);
|
|
|
|
|
|
|
+ IMethod m1 = LambdaReflect.typeinfo(function1);
|
|
|
|
|
+ IMethod m2 = LambdaReflect.typeinfo(function2);
|
|
|
|
|
+ IMethod m3 = LambdaReflect.typeinfo(function3);
|
|
|
|
|
+ IMethod m4 = LambdaReflect.typeinfo(function4);
|
|
|
|
|
+ IMethod m5 = LambdaReflect.typeinfo(function5);
|
|
|
|
|
|
|
|
// call
|
|
// call
|
|
|
assertEquals('e', m1.call("hello!"));
|
|
assertEquals('e', m1.call("hello!"));
|
|
@@ -289,11 +288,11 @@ public class LamdaReflectTest {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void testFunctorCall(Object function1, Object function2, Object function3, Object function4, Object function5) {
|
|
private void testFunctorCall(Object function1, Object function2, Object function3, Object function4, Object function5) {
|
|
|
- IMethod m1 = LamdaReflect.typeinfo(function1);
|
|
|
|
|
- IMethod m2 = LamdaReflect.typeinfo(function2);
|
|
|
|
|
- IMethod m3 = LamdaReflect.typeinfo(function3);
|
|
|
|
|
- IMethod m4 = LamdaReflect.typeinfo(function4);
|
|
|
|
|
- IMethod m5 = LamdaReflect.typeinfo(function5);
|
|
|
|
|
|
|
+ IMethod m1 = LambdaReflect.typeinfo(function1);
|
|
|
|
|
+ IMethod m2 = LambdaReflect.typeinfo(function2);
|
|
|
|
|
+ IMethod m3 = LambdaReflect.typeinfo(function3);
|
|
|
|
|
+ IMethod m4 = LambdaReflect.typeinfo(function4);
|
|
|
|
|
+ IMethod m5 = LambdaReflect.typeinfo(function5);
|
|
|
|
|
|
|
|
// call
|
|
// call
|
|
|
assertEquals('e', m1.call("hello!"));
|
|
assertEquals('e', m1.call("hello!"));
|
|
@@ -345,7 +344,7 @@ public class LamdaReflectTest {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void assertFunction2(Object function, IClass<?> ret, IClass<?>... args) {
|
|
private void assertFunction2(Object function, IClass<?> ret, IClass<?>... args) {
|
|
|
- IMethod m = LamdaReflect.typeinfo(function);
|
|
|
|
|
|
|
+ IMethod m = LambdaReflect.typeinfo(function);
|
|
|
|
|
|
|
|
// Class<?> type = function.getClass();
|
|
// Class<?> type = function.getClass();
|
|
|
// System.out.printf(">>>> %s -> %s%n", m.arguments().types(), m.returns());
|
|
// System.out.printf(">>>> %s -> %s%n", m.arguments().types(), m.returns());
|