Allow @JsOverlay on effectively final methods.
This pactch starts allowing @JsOverlay in private methods and methods on
final classes as these are effectively final.
Bug: #9342
Bug-Link: https://github.com/gwtproject/gwt/issues/9342
Change-Id: I0372071eacf7a3089e2dd4f83fce5495901cff4d
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/JsInteropRestrictionChecker.java b/dev/core/src/com/google/gwt/dev/jjs/impl/JsInteropRestrictionChecker.java
index e917cc9..9a34f4d 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/JsInteropRestrictionChecker.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/JsInteropRestrictionChecker.java
@@ -336,8 +336,12 @@
assert method.getOverriddenMethods().isEmpty();
- if (method.getBody() == null || (!method.isFinal() && !method.isStatic()
- && !method.isDefaultMethod())) {
+ if (method.getBody() == null
+ || (!method.isFinal()
+ && !method.getEnclosingType().isFinal()
+ && !method.isPrivate()
+ && !method.isStatic()
+ && !method.isDefaultMethod())) {
logError(member, "JsOverlay method '%s' cannot be non-final nor native.", memberDescription);
}
}
diff --git a/dev/core/test/com/google/gwt/dev/jjs/impl/JsInteropRestrictionCheckerTest.java b/dev/core/test/com/google/gwt/dev/jjs/impl/JsInteropRestrictionCheckerTest.java
index 46028ce..e7edec8 100644
--- a/dev/core/test/com/google/gwt/dev/jjs/impl/JsInteropRestrictionCheckerTest.java
+++ b/dev/core/test/com/google/gwt/dev/jjs/impl/JsInteropRestrictionCheckerTest.java
@@ -1604,11 +1604,15 @@
addSnippetImport("jsinterop.annotations.JsType");
addSnippetImport("jsinterop.annotations.JsOverlay");
addSnippetClassDecl(
+ "@JsType(isNative=true) public static final class FinalType {",
+ " @JsOverlay public void n() { }",
+ "}",
"@JsType(isNative=true) public static class Buggy {",
" @JsOverlay public static Object object = new Object();",
" @JsOverlay public static void m() { }",
" @JsOverlay public static void m(int x) { }",
" @JsOverlay private static void m(boolean x) { }",
+ " @JsOverlay private void m(String x) { }",
" @JsOverlay public final void n() { }",
" @JsOverlay public final void n(int x) { }",
" @JsOverlay private final void n(boolean x) { }",