From 75f35c097220946990ebc5cde3674f2a88c27e1d Mon Sep 17 00:00:00 2001 From: Roberto Lublinerman Date: Thu, 31 Aug 2023 10:25:43 -0700 Subject: [PATCH] Update JRE interfaces to agree with their Kotlin definition. It is an invariant that calls are always resolved to an exisitng source method so when these do not agree the calls target to a `MethodDescriptor` for a method that does not exist in the type. PiperOrigin-RevId: 561692981 --- jre/java/java/util/Collection.java | 4 ++ jre/java/java/util/List.java | 5 ++- jre/java/java/util/ListIterator.java | 6 +++ jre/java/java/util/Set.java | 5 +++ .../integration/asynckotlintest/data/BUILD | 44 ------------------- .../junit/integration/kotlintest/data/BUILD | 28 ------------ .../j2cl/tools/rta/TypeGraphBuilder.java | 14 ++++-- 7 files changed, 29 insertions(+), 77 deletions(-) diff --git a/jre/java/java/util/Collection.java b/jre/java/java/util/Collection.java index 1710ae9343..176edd52ff 100644 --- a/jre/java/java/util/Collection.java +++ b/jre/java/java/util/Collection.java @@ -44,6 +44,10 @@ public interface Collection extends Iterable { boolean containsAll(Collection c); + @JsIgnore + @Override + Iterator iterator(); + boolean isEmpty(); @JsIgnore diff --git a/jre/java/java/util/List.java b/jre/java/java/util/List.java index f8c3ac7f02..b62f863e09 100644 --- a/jre/java/java/util/List.java +++ b/jre/java/java/util/List.java @@ -18,7 +18,6 @@ import static javaemul.internal.InternalPreconditions.checkNotNull; import java.util.function.UnaryOperator; - import jsinterop.annotations.JsIgnore; import jsinterop.annotations.JsMethod; import jsinterop.annotations.JsNonNull; @@ -43,6 +42,10 @@ public interface List extends Collection { @JsMethod(name = "getAtIndex") E get(int index); + @JsIgnore + @Override + Iterator iterator(); + int indexOf(Object o); int lastIndexOf(Object o); diff --git a/jre/java/java/util/ListIterator.java b/jre/java/java/util/ListIterator.java index 527cfe5233..5f82a40670 100644 --- a/jre/java/java/util/ListIterator.java +++ b/jre/java/java/util/ListIterator.java @@ -29,6 +29,12 @@ public interface ListIterator extends Iterator { void add(E o); + @Override + boolean hasNext(); + + @Override + E next(); + boolean hasPrevious(); int nextIndex(); diff --git a/jre/java/java/util/Set.java b/jre/java/java/util/Set.java index 8a5bf8cb38..57fe186080 100644 --- a/jre/java/java/util/Set.java +++ b/jre/java/java/util/Set.java @@ -26,6 +26,11 @@ */ @JsType public interface Set extends Collection { + + @JsIgnore + @Override + Iterator iterator(); + @JsIgnore @Override default Spliterator spliterator() { diff --git a/junit/generator/javatests/com/google/j2cl/junit/integration/asynckotlintest/data/BUILD b/junit/generator/javatests/com/google/j2cl/junit/integration/asynckotlintest/data/BUILD index d029ea85f6..6d3ae43f29 100644 --- a/junit/generator/javatests/com/google/j2cl/junit/integration/asynckotlintest/data/BUILD +++ b/junit/generator/javatests/com/google/j2cl/junit/integration/asynckotlintest/data/BUILD @@ -19,154 +19,110 @@ ASYNC_TEST_DEPS = [ j2cl_test_integration_test_data( name = "TestAfterWithFailingAsyncTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestAsyncAfterWillTimeOut", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestAsyncBeforeWillTimeOut", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestChainingWithException", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestNonAsyncTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestResolvesAfterDelay", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestMethodOrder", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestStructuralThenable", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestListenableFuture", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS + ["//third_party:guava"], ) j2cl_test_integration_test_data( name = "TestReturnsNullForAsyncAfter", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestReturnsNullForAsyncBefore", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestReturnsNullForPromise", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestReturnsVoidTimeoutProvided", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestReturnTypeNotStructuralPromise", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestReturnTypeNotStructuralPromiseThenParameterCount", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS + ["//third_party:gwt-jsinterop-annotations"], ) j2cl_test_integration_test_data( name = "TestReturnTypeNotStructuralPromiseThenParameterNotJsType", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS + ["//third_party:gwt-jsinterop-annotations"], ) j2cl_test_integration_test_data( name = "TestReturnTypeNotStructuralPromiseThenNameRedefined", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS + ["//third_party:gwt-jsinterop-annotations"], ) j2cl_test_integration_test_data( name = "TestTimeOutNotProvided", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS + ["//third_party:guava"], ) j2cl_test_integration_test_data( name = "TestWillTimeOut", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestWithExpectedException", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestFailingAsyncAfter", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) j2cl_test_integration_test_data( name = "TestFailingAsyncBefore", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, deps = ASYNC_TEST_DEPS, ) diff --git a/junit/generator/javatests/com/google/j2cl/junit/integration/kotlintest/data/BUILD b/junit/generator/javatests/com/google/j2cl/junit/integration/kotlintest/data/BUILD index ea1e554ff2..786facee37 100644 --- a/junit/generator/javatests/com/google/j2cl/junit/integration/kotlintest/data/BUILD +++ b/junit/generator/javatests/com/google/j2cl/junit/integration/kotlintest/data/BUILD @@ -12,8 +12,6 @@ package( j2cl_test_integration_test_data( name = "BeforeAndAfterTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -21,8 +19,6 @@ j2cl_test_integration_test_data( j2cl_test_integration_test_data( name = "ChildTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -31,8 +27,6 @@ j2cl_test_integration_test_data( j2cl_test_integration_test_data( name = "ChildWithNewMethodsTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -41,8 +35,6 @@ j2cl_test_integration_test_data( j2cl_test_integration_test_data( name = "GrandChildWithNewMethodsTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -51,8 +43,6 @@ j2cl_test_integration_test_data( j2cl_test_integration_test_data( name = "ExpectedExceptionTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -65,8 +55,6 @@ kotlin_and_j2cl_library( j2cl_test_integration_test_data( name = "IgnoreTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -80,16 +68,12 @@ kotlin_and_j2cl_library( j2cl_test_integration_test_data( name = "MethodOrderingTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = ["CLOSURE"], deps = [":MethodOrderingTestParent"], ) j2cl_test_integration_test_data( name = "SimpleFailingTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -97,8 +81,6 @@ j2cl_test_integration_test_data( j2cl_test_integration_test_data( name = "SimplePassingTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -111,8 +93,6 @@ kotlin_and_j2cl_library( j2cl_test_integration_test_data( name = "SimpleSuite", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -121,8 +101,6 @@ j2cl_test_integration_test_data( j2cl_test_integration_test_data( name = "SuiteOfSuite", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -131,8 +109,6 @@ j2cl_test_integration_test_data( j2cl_test_integration_test_data( name = "ThrowsInAfterTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -140,8 +116,6 @@ j2cl_test_integration_test_data( j2cl_test_integration_test_data( name = "ThrowsInBeforeTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], @@ -149,8 +123,6 @@ j2cl_test_integration_test_data( j2cl_test_integration_test_data( name = "ThrowsOnConstructionTest", - # TODO(b/225411185): Enable when RTA works with Kotlin output. - enable_rta = False, platforms = [ "CLOSURE", ], diff --git a/tools/java/com/google/j2cl/tools/rta/TypeGraphBuilder.java b/tools/java/com/google/j2cl/tools/rta/TypeGraphBuilder.java index d638ae6709..dc6f70f59c 100644 --- a/tools/java/com/google/j2cl/tools/rta/TypeGraphBuilder.java +++ b/tools/java/com/google/j2cl/tools/rta/TypeGraphBuilder.java @@ -75,10 +75,16 @@ private static void buildCrossReferences(Map typesByName, LibraryI } for (MethodInvocation methodInvocation : memberInfo.getInvokedMethodsList()) { - Type enclosingType = - typesByName.get(libraryInfo.getTypeMap(methodInvocation.getEnclosingType())); - Member referencedMember = enclosingType.getMemberByName(methodInvocation.getMethod()); - member.addReferencedMember(checkNotNull(referencedMember)); + String enclosingTypeName = libraryInfo.getTypeMap(methodInvocation.getEnclosingType()); + String methodName = methodInvocation.getMethod(); + + Type enclosingType = typesByName.get(enclosingTypeName); + member.addReferencedMember( + checkNotNull( + enclosingType.getMemberByName(methodName), + "Missing %s.%s", + enclosingTypeName, + methodName)); } } }