Skip to content

Commit

Permalink
Suppress an unusable-by-js warning.
Browse files Browse the repository at this point in the history
And enable a setting that at least _shows_ us that warning (though it doesn't fail the build).

Fixes #6602

RELNOTES=Suppressed [an `unusable-by-js` warning](#6602) seen by users of `guava-gwt`.
PiperOrigin-RevId: 544409394
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jun 29, 2023
1 parent 1dc5f8c commit f2f4f86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions guava-gwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
<module>com.google.common.ForceGuavaCompilation</module>
<failOnError>true</failOnError>
<logLevel>${gwt.logLevel}</logLevel>
<generateJsInteropExports>true</generateJsInteropExports>
<validateOnly>true</validateOnly>
<sourceLevel>1.8</sourceLevel>
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,21 @@ static <E extends Enum<E>> Class<E> getDeclaringClassOrObjectForJ2cl(E e) {
return result;
}

/*
* If I understand correctly:
*
* This needs to be a @JsMethod so that J2CL knows to look for a JavaScript implemention of
* it in Platform.native.js. (The JavaScript implementation inline below is visible to *GWT*, but
* *J2CL* doesn't look at it.)
*
* However, once it's a @JsMethod, GWT produces a warning. That's because (a) the *other* purpose
* of @JsMethod is to make a method *callable* from JavaScript and (b) this method would not be
* useful to call from vanilla JavaScript because it returns an instance of Class, which can't be
* converted to a standard JavaScript type. (Contrast to something like String or boolean.) Since
* we're not calling it from JavaScript, we suppress the warning.
*/
@JsMethod
@SuppressWarnings("unusable-by-js")
private static native <E extends Enum<E>> @Nullable Class<E> getDeclaringClassOrNullForJ2cl(
E e) /*-{
return [email protected]::getDeclaringClass()();
Expand Down

0 comments on commit f2f4f86

Please sign in to comment.