mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-09 00:14:10 -08:00
Fix bug in dependency checker. Additional test cases for lambdas
This commit is contained in:
parent
8cd134bc90
commit
0b7e78d9f9
|
@ -337,7 +337,7 @@ class DependencyGraphBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassReaderSource classSource = checker.getClassSource();
|
ClassReaderSource classSource = checker.getClassSource();
|
||||||
if (classSource.isSuperType(filterClass.getName(), className).orElse(false)) {
|
if (!classSource.isSuperType(filterClass.getName(), className).orElse(false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MethodReference methodRef = new MethodReference(className, methodDesc);
|
MethodReference methodRef = new MethodReference(className, methodDesc);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.teavm.classlib.java.lang;
|
package org.teavm.classlib.java.lang;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -16,9 +17,33 @@ public class LambdaTest {
|
||||||
assertArrayEquals(new Integer[] { 3, 5, 7 }, array);
|
assertArrayEquals(new Integer[] { 3, 5, 7 }, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lambdaWorksWithLiteral() {
|
||||||
|
A[] src = { new A(1), new A(2), new A(3) };
|
||||||
|
A[] array = map(src, A::inc);
|
||||||
|
assertEquals(3, array.length);
|
||||||
|
assertEquals(2, array[0].value);
|
||||||
|
assertEquals(3, array[1].value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lambdaWorksWithFieldLiteral() {
|
||||||
|
A[] src = { new A(1), new A(2), new A(3) };
|
||||||
|
int[] array = mapToInt(src, a -> a.value);
|
||||||
|
assertArrayEquals(new int[] { 1, 2, 3 }, array);
|
||||||
|
}
|
||||||
|
|
||||||
static <T> T[] map(T[] array, Function<T> f) {
|
static <T> T[] map(T[] array, Function<T> f) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
T[] result = (T[])Array.newInstance(array.getClass().getComponentType(), array.length);
|
T[] result = (T[]) Array.newInstance(array.getClass().getComponentType(), array.length);
|
||||||
|
for (int i = 0; i < result.length; ++i) {
|
||||||
|
result[i] = f.apply(array[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static <T> int[] mapToInt(T[] array, IntFunction<T> f) {
|
||||||
|
int[] result = new int[array.length];
|
||||||
for (int i = 0; i < result.length; ++i) {
|
for (int i = 0; i < result.length; ++i) {
|
||||||
result[i] = f.apply(array[i]);
|
result[i] = f.apply(array[i]);
|
||||||
}
|
}
|
||||||
|
@ -28,4 +53,24 @@ public class LambdaTest {
|
||||||
interface Function<T> {
|
interface Function<T> {
|
||||||
T apply(T value);
|
T apply(T value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IntFunction<T> {
|
||||||
|
int apply(T value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class A {
|
||||||
|
int value;
|
||||||
|
|
||||||
|
A(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
A inc() {
|
||||||
|
return new A(value + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user