From 91f4bdc7992fade6479bfefaabb4e8af186086b7 Mon Sep 17 00:00:00 2001 From: Stefan Haustein Date: Wed, 6 Dec 2023 06:25:50 -0800 Subject: [PATCH] Remove getSuperclass() from the j2kt API, as it's not supported and ideally we'd see that at build time. Also address one use case in Truth by moving the corresponding platform check to Platform.java and adding platform overloads. RELNOTES=n/a PiperOrigin-RevId: 588404095 --- .../main/java/com/google/common/truth/Platform.java | 7 +++++++ .../main/java/com/google/common/truth/Subject.java | 11 ++--------- .../truth/super/com/google/common/truth/Platform.java | 4 ++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/google/common/truth/Platform.java b/core/src/main/java/com/google/common/truth/Platform.java index c6a2f76d9..d24da88b5 100644 --- a/core/src/main/java/com/google/common/truth/Platform.java +++ b/core/src/main/java/com/google/common/truth/Platform.java @@ -362,4 +362,11 @@ static boolean kotlinRangeContains(Iterable haystack, @Nullable Object needle throw newLinkageError(e); } }); + + static boolean classMetadataUnsupported() { + // https://github.com/google/truth/issues/198 + // TODO(cpovirk): Consider whether to remove instanceof tests under GWT entirely. + // TODO(cpovirk): Run more Truth tests under GWT, and add tests for this. + return false; + } } diff --git a/core/src/main/java/com/google/common/truth/Subject.java b/core/src/main/java/com/google/common/truth/Subject.java index 94d9e1692..bcb8e4d0d 100644 --- a/core/src/main/java/com/google/common/truth/Subject.java +++ b/core/src/main/java/com/google/common/truth/Subject.java @@ -299,7 +299,7 @@ public void isInstanceOf(Class clazz) { return; } if (!isInstanceOfType(actual, clazz)) { - if (classMetadataUnsupported()) { + if (Platform.classMetadataUnsupported()) { throw new UnsupportedOperationException( actualCustomStringRepresentation() + ", an instance of " @@ -320,7 +320,7 @@ public void isNotInstanceOf(Class clazz) { if (clazz == null) { throw new NullPointerException("clazz"); } - if (classMetadataUnsupported()) { + if (Platform.classMetadataUnsupported()) { throw new UnsupportedOperationException( "isNotInstanceOf is not supported under -XdisableClassMetadata"); } @@ -1185,13 +1185,6 @@ private static String typeDescriptionOrGuess( return UPPER_CAMEL.to(LOWER_CAMEL, actualClass); } - private static boolean classMetadataUnsupported() { - // https://github.com/google/truth/issues/198 - // TODO(cpovirk): Consider whether to remove instanceof tests under GWT entirely. - // TODO(cpovirk): Run more Truth tests under GWT, and add tests for this. - return String.class.getSuperclass() == null; - } - private void doFail(ImmutableList facts) { checkNotNull(metadata).fail(facts); } diff --git a/core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java b/core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java index 4642f8ab9..3bb24af2e 100644 --- a/core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java +++ b/core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java @@ -268,5 +268,9 @@ static boolean isKotlinRange(Iterable iterable) { static boolean kotlinRangeContains(Iterable haystack, @Nullable Object needle) { throw new AssertionError(); // never called under GWT because isKotlinRange returns false } + + static boolean classMetadataUnsupported() { + return String.class.getSuperclass() == null; + } }