Skip to content

Commit

Permalink
Update JRE interfaces to agree with their Kotlin definition.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rluble authored and copybara-github committed Aug 31, 2023
1 parent d03e794 commit 75f35c0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 77 deletions.
4 changes: 4 additions & 0 deletions jre/java/java/util/Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public interface Collection<E> extends Iterable<E> {

boolean containsAll(Collection<?> c);

@JsIgnore
@Override
Iterator<E> iterator();

boolean isEmpty();

@JsIgnore
Expand Down
5 changes: 4 additions & 1 deletion jre/java/java/util/List.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,6 +42,10 @@ public interface List<E> extends Collection<E> {
@JsMethod(name = "getAtIndex")
E get(int index);

@JsIgnore
@Override
Iterator<E> iterator();

int indexOf(Object o);

int lastIndexOf(Object o);
Expand Down
6 changes: 6 additions & 0 deletions jre/java/java/util/ListIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public interface ListIterator<E> extends Iterator<E> {

void add(E o);

@Override
boolean hasNext();

@Override
E next();

boolean hasPrevious();

int nextIndex();
Expand Down
5 changes: 5 additions & 0 deletions jre/java/java/util/Set.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
*/
@JsType
public interface Set<E> extends Collection<E> {

@JsIgnore
@Override
Iterator<E> iterator();

@JsIgnore
@Override
default Spliterator<E> spliterator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ package(

j2cl_test_integration_test_data(
name = "BeforeAndAfterTest",
# TODO(b/225411185): Enable when RTA works with Kotlin output.
enable_rta = False,
platforms = [
"CLOSURE",
],
)

j2cl_test_integration_test_data(
name = "ChildTest",
# TODO(b/225411185): Enable when RTA works with Kotlin output.
enable_rta = False,
platforms = [
"CLOSURE",
],
Expand All @@ -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",
],
Expand All @@ -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",
],
Expand All @@ -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",
],
Expand All @@ -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",
],
Expand All @@ -80,25 +68,19 @@ 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",
],
)

j2cl_test_integration_test_data(
name = "SimplePassingTest",
# TODO(b/225411185): Enable when RTA works with Kotlin output.
enable_rta = False,
platforms = [
"CLOSURE",
],
Expand All @@ -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",
],
Expand All @@ -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",
],
Expand All @@ -131,26 +109,20 @@ 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",
],
)

j2cl_test_integration_test_data(
name = "ThrowsInBeforeTest",
# TODO(b/225411185): Enable when RTA works with Kotlin output.
enable_rta = False,
platforms = [
"CLOSURE",
],
)

j2cl_test_integration_test_data(
name = "ThrowsOnConstructionTest",
# TODO(b/225411185): Enable when RTA works with Kotlin output.
enable_rta = False,
platforms = [
"CLOSURE",
],
Expand Down
14 changes: 10 additions & 4 deletions tools/java/com/google/j2cl/tools/rta/TypeGraphBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ private static void buildCrossReferences(Map<String, Type> 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));
}
}
}
Expand Down

0 comments on commit 75f35c0

Please sign in to comment.