diff --git a/classlib/src/main/java/org/teavm/classlib/impl/ReflectionDependencyListener.java b/classlib/src/main/java/org/teavm/classlib/impl/ReflectionDependencyListener.java index a1f57eb60..9de0b742c 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/ReflectionDependencyListener.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/ReflectionDependencyListener.java @@ -314,6 +314,9 @@ public class ReflectionDependencyListener extends AbstractDependencyListener { case INTEGER: boxMethod = new MethodReference(Integer.class, "valueOf", int.class, Integer.class); break; + case LONG: + boxMethod = new MethodReference(Long.class, "valueOf", long.class, Long.class); + break; case FLOAT: boxMethod = new MethodReference(Float.class, "valueOf", float.class, Float.class); break; @@ -351,6 +354,9 @@ public class ReflectionDependencyListener extends AbstractDependencyListener { case INTEGER: unboxMethod = new MethodReference(Integer.class, "intValue", int.class); break; + case LONG: + unboxMethod = new MethodReference(Long.class, "longValue", long.class); + break; case FLOAT: unboxMethod = new MethodReference(Float.class, "floatValue", float.class); break; diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/reflect/FieldTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/reflect/FieldTest.java index 1fd1ab354..5ecc15b37 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/reflect/FieldTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/reflect/FieldTest.java @@ -40,6 +40,7 @@ public class FieldTest { + "java.lang.String org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.d;" + "long org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.e;" + "private static short org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.f;" + + "long org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.g;" + "static boolean org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.initialized;", sb.toString()); } @@ -52,6 +53,14 @@ public class FieldTest { assertEquals(23, result); } + @Test + public void fieldReadLong() throws NoSuchFieldException, IllegalAccessException { + ReflectableType instance = new ReflectableType(); + Field field = instance.getClass().getDeclaredField("g"); + Object result = field.get(instance); + assertEquals(Long.MAX_VALUE, result); + } + @Test public void fieldWritten() throws NoSuchFieldException, IllegalAccessException { ReflectableType instance = new ReflectableType(); @@ -116,10 +125,9 @@ public class FieldTest { @Reflectable private boolean b; @Reflectable Object c; @Reflectable String d; - long e; - @Reflectable private static short f = 99; + @Reflectable long g; static boolean initialized = true; @@ -129,6 +137,7 @@ public class FieldTest { c = "foo"; d = "bar"; e = 42; + g = Long.MAX_VALUE; } } diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/reflect/MethodTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/reflect/MethodTest.java index 11590e043..6d5185e1e 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/reflect/MethodTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/reflect/MethodTest.java @@ -36,6 +36,7 @@ public class MethodTest { assertEquals("" + "java.lang.Object Foo.baz();" + + "public void Foo.accept(long);" + "public void Foo.bar(java.lang.Object);", text); } @@ -46,7 +47,7 @@ public class MethodTest { String text = collectMethods(Foo.class.getMethods()); - assertEquals("public void Foo.bar(java.lang.Object);", text); + assertEquals("public void Foo.accept(long);public void Foo.bar(java.lang.Object);", text); } @Test @@ -94,6 +95,7 @@ public class MethodTest { private void callMethods() { new Foo().bar(null); new Foo().baz(); + new Foo().accept(0); new SuperClass().f(); new SubClass().g(); new SuperClassWithBridge().f(); @@ -118,6 +120,10 @@ public class MethodTest { static class Foo { Object value; + @Reflectable + public void accept(long l) { + } + @Reflectable public void bar(Object value) { this.value = value;