Skip to content

Commit

Permalink
Remove getSuperclass() from the j2kt API, as it's not supported and i…
Browse files Browse the repository at this point in the history
…deally 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
  • Loading branch information
stefanhaustein authored and Google Java Core Libraries committed Dec 6, 2023
1 parent d532e91 commit 91f4bdc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/com/google/common/truth/Platform.java
Expand Up @@ -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;
}
}
11 changes: 2 additions & 9 deletions core/src/main/java/com/google/common/truth/Subject.java
Expand Up @@ -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 "
Expand All @@ -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");
}
Expand Down Expand Up @@ -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<Fact> facts) {
checkNotNull(metadata).fail(facts);
}
Expand Down
Expand Up @@ -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;
}
}

0 comments on commit 91f4bdc

Please sign in to comment.