From 5e354cc546aeeafd87f6242c6836abe725f14ac5 Mon Sep 17 00:00:00 2001 From: Molly Tian Date: Mon, 11 Dec 2023 10:44:46 -0800 Subject: [PATCH] Add an example of @JsOverlay static final field to java readable and integration tests. PiperOrigin-RevId: 589872389 --- .../j2cl/integration/java/jsoverlay/Main.java | 9 ++++-- .../j2cl/readable/java/jsoverlay/Main.java | 15 ++++++---- ...rfaceWithOverlay$$Overlay.impl.java.js.txt | 2 -- ...erfaceWithOverlay$$Overlay.js.mappings.txt | 3 -- ...sTypeWithOverlay$$Overlay.impl.java.js.txt | 2 -- ...JsTypeWithOverlay$$Overlay.js.mappings.txt | 3 -- ...hOverlayConstant$$Overlay.impl.java.js.txt | 28 +++++++++++++++++++ ...peWithOverlayConstant$$Overlay.java.js.txt | 7 +++++ ...thOverlayConstant$$Overlay.js.mappings.txt | 10 +++++++ .../output_closure/Main.impl.java.js.txt | 6 ++-- .../jsoverlay/output_closure/Main.java.js.txt | 1 + .../output_closure/Main.js.mappings.txt | 7 +++-- .../output_kt/Main+J2ObjCCompat.h.txt | 11 -------- .../java/jsoverlay/output_kt/Main.kt.txt | 24 +++++++++------- 14 files changed, 84 insertions(+), 44 deletions(-) create mode 100644 transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.impl.java.js.txt create mode 100644 transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.java.js.txt create mode 100644 transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.js.mappings.txt diff --git a/transpiler/javatests/com/google/j2cl/integration/java/jsoverlay/Main.java b/transpiler/javatests/com/google/j2cl/integration/java/jsoverlay/Main.java index 10868cca2d..b329c29d32 100644 --- a/transpiler/javatests/com/google/j2cl/integration/java/jsoverlay/Main.java +++ b/transpiler/javatests/com/google/j2cl/integration/java/jsoverlay/Main.java @@ -19,12 +19,12 @@ import static com.google.j2cl.integration.testing.Asserts.assertTrue; import jsinterop.annotations.JsOverlay; +import jsinterop.annotations.JsPackage; import jsinterop.annotations.JsType; public class Main { @JsType(isNative = true, namespace = "test.foo") static class NativeJsTypeWithOverlay { - @JsOverlay public static final int COMPILE_TIME_CONSTANT = 1; @JsOverlay public static Object staticField = new Object(); public native int m(); @@ -59,6 +59,11 @@ private Object getStaticField() { } } + @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") + static class NativeJsTypeWithOverlayConstant { + @JsOverlay public static final int COMPILE_TIME_CONSTANT = 1; + } + @JsType(isNative = true, namespace = "test.foo") static final class NativeFinalJsTypeWithOverlay { public native int e(); @@ -83,7 +88,7 @@ public static void testNativeJsWithOverlay() { NativeJsTypeWithOverlay object = new NativeJsTypeWithOverlay(); assertTrue(6 == object.callM()); assertTrue(20 == NativeJsTypeWithOverlay.fun(4, 5)); - assertTrue(1 == NativeJsTypeWithOverlay.COMPILE_TIME_CONSTANT); + assertTrue(1 == NativeJsTypeWithOverlayConstant.COMPILE_TIME_CONSTANT); assertTrue(object.getStaticField() != null); assertTrue(NativeJsTypeWithOverlay.staticField != null); NativeJsTypeWithOverlay.staticField = null; diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/Main.java b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/Main.java index 27f739d7a2..897ce4de6f 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/Main.java +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/Main.java @@ -24,8 +24,6 @@ public class Main { @JsType(isNative = true, namespace = "test.foo") public interface NativeJsTypeInterfaceWithOverlay { - @JsOverlay String COMPILE_TIME_CONSTANT = "10"; - @JsOverlay Object staticField = new Object(); int m(); @@ -46,8 +44,6 @@ public int m() { public static class NativeJsTypeWithOverlay { public static int nonJsOverlayField; - @JsOverlay public static final int COMPILE_TIME_CONSTANT = 10; - @JsOverlay public static Object staticField = new Object(); public native int m(); @@ -100,6 +96,12 @@ public final void overlay() {} public static void overlay(NativeJsTypeWithOverlay o) {} } + @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") + static class NativeJsTypeWithOverlayConstant { + @JsOverlay public static final int COMPILE_TIME_CONSTANT = 10; + @JsOverlay public static final String STRING_COMPILE_TIME_CONSTANT = "10"; + } + @JsFunction private interface Intf { void run(); @@ -113,13 +115,14 @@ public void test() { NativeJsTypeWithOverlay.bar(); n.foo(); int a = - NativeJsTypeWithOverlay.COMPILE_TIME_CONSTANT + NativeJsTypeWithOverlay.nonJsOverlayField; + NativeJsTypeWithOverlayConstant.COMPILE_TIME_CONSTANT + + NativeJsTypeWithOverlay.nonJsOverlayField; NativeJsTypeWithOverlay.staticField = null; NativeJsTypeWithOverlay.varargs(1, 2, 3); n.baz(); String b = - NativeJsTypeInterfaceWithOverlay.COMPILE_TIME_CONSTANT + NativeJsTypeWithOverlayConstant.STRING_COMPILE_TIME_CONSTANT + NativeJsTypeInterfaceWithOverlay.staticField; } diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeInterfaceWithOverlay$$Overlay.impl.java.js.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeInterfaceWithOverlay$$Overlay.impl.java.js.txt index d254c0fac7..7f5b70c6c8 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeInterfaceWithOverlay$$Overlay.impl.java.js.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeInterfaceWithOverlay$$Overlay.impl.java.js.txt @@ -27,8 +27,6 @@ class $Overlay { j_l_Object = goog.module.get('java.lang.Object$impl'); } } -/**@const {string} @nodts*/ -$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay = '10'; /**@private {*} @nodts*/ $Overlay.$static_staticField__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay; diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeInterfaceWithOverlay$$Overlay.js.mappings.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeInterfaceWithOverlay$$Overlay.js.mappings.txt index 3c84503042..0238d8f004 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeInterfaceWithOverlay$$Overlay.js.mappings.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeInterfaceWithOverlay$$Overlay.js.mappings.txt @@ -8,8 +8,5 @@ [NativeJsTypeInterfaceWithOverlay] => [$Overlay.$clinit = () =>{};] "jsoverlay.Main$NativeJsTypeInterfaceWithOverlay$$Overlay." [NativeJsTypeInterfaceWithOverlay] => [$Overlay.$loadModules();] "jsoverlay.Main$NativeJsTypeInterfaceWithOverlay$$Overlay." [@JsOverlay Object staticField = new Object();] => [$Overlay.$static_staticField__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay = j_l_Object.$create__();] "jsoverlay.Main$NativeJsTypeInterfaceWithOverlay$$Overlay." -[@JsOverlay String COMPILE_TIME_CONSTANT = "10";] => [/**@const {string} @nodts*/ -$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay = '10';] -[COMPILE_TIME_CONSTANT] => [f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay] [NativeJsTypeInterfaceWithOverlay] => [/**@private {*} @nodts*/ $Overlay.$static_staticField__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay;] diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlay$$Overlay.impl.java.js.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlay$$Overlay.impl.java.js.txt index f138aee758..1f20fc4102 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlay$$Overlay.impl.java.js.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlay$$Overlay.impl.java.js.txt @@ -74,8 +74,6 @@ class $Overlay { j_l_Object = goog.module.get('java.lang.Object$impl'); } } -/**@const {number} @nodts*/ -$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay = 10; /**@private {*} @nodts*/ $Overlay.$static_staticField__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay; $Util.$setClassMetadata($Overlay, 'test.foo.NativeJsTypeWithOverlay'); diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlay$$Overlay.js.mappings.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlay$$Overlay.js.mappings.txt index 2c46e1c88d..a030675c9e 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlay$$Overlay.js.mappings.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlay$$Overlay.js.mappings.txt @@ -43,8 +43,5 @@ [NativeJsTypeWithOverlay] => [$Overlay.$clinit = () =>{};] "jsoverlay.Main$NativeJsTypeWithOverlay$$Overlay." [NativeJsTypeWithOverlay] => [$Overlay.$loadModules();] "jsoverlay.Main$NativeJsTypeWithOverlay$$Overlay." [@JsOverlay public static Object staticField = new Object();] => [$Overlay.$static_staticField__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay = j_l_Object.$create__();] "jsoverlay.Main$NativeJsTypeWithOverlay$$Overlay." -[@JsOverlay public static final int COMPILE_TIME_CONSTANT = 10;] => [/**@const {number} @nodts*/ -$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay = 10;] -[COMPILE_TIME_CONSTANT] => [f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay] [NativeJsTypeWithOverlay] => [/**@private {*} @nodts*/ $Overlay.$static_staticField__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay;] diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.impl.java.js.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.impl.java.js.txt new file mode 100644 index 0000000000..4bea74b229 --- /dev/null +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.impl.java.js.txt @@ -0,0 +1,28 @@ +goog.module('jsoverlay.Main.NativeJsTypeWithOverlayConstant.$Overlay$impl'); + +const $Util = goog.require('nativebootstrap.Util$impl'); + +/** @nodts */ +class $Overlay { + /** @nodts */ + static $clinit() { + $Overlay.$clinit = () =>{}; + $Overlay.$loadModules(); + } + /** @nodts @return {boolean} */ + static $isInstance(/** ? */ instance) { + return instance instanceof Object; + } + + /** @nodts */ + static $loadModules() {} +} +/**@const {number} @nodts*/ +$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay = 10; +/**@const {string} @nodts*/ +$Overlay.f_STRING_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay = '10'; +$Util.$setClassMetadata($Overlay, 'Object'); + +exports = $Overlay; + +//# sourceMappingURL=Main$NativeJsTypeWithOverlayConstant$$Overlay.js.map diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.java.js.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.java.js.txt new file mode 100644 index 0000000000..07a0960640 --- /dev/null +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.java.js.txt @@ -0,0 +1,7 @@ +goog.module('jsoverlay.Main.NativeJsTypeWithOverlayConstant.$Overlay'); + +goog.require('nativebootstrap.Util'); + +const $Overlay = goog.require('jsoverlay.Main.NativeJsTypeWithOverlayConstant.$Overlay$impl'); +/** @nodts */ +exports = $Overlay; diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.js.mappings.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.js.mappings.txt new file mode 100644 index 0000000000..a916aa0884 --- /dev/null +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main$NativeJsTypeWithOverlayConstant$$Overlay.js.mappings.txt @@ -0,0 +1,10 @@ +[NativeJsTypeWithOverlayConstant] => [$Overlay] +[NativeJsTypeWithOverlayConstant] => [$clinit] +[NativeJsTypeWithOverlayConstant] => [$Overlay.$clinit = () =>{};] "jsoverlay.Main$NativeJsTypeWithOverlayConstant$$Overlay." +[NativeJsTypeWithOverlayConstant] => [$Overlay.$loadModules();] "jsoverlay.Main$NativeJsTypeWithOverlayConstant$$Overlay." +[@JsOverlay public static final int COMPILE_TIME_CONSTANT = 10;] => [/**@const {number} @nodts*/ +$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay = 10;] +[COMPILE_TIME_CONSTANT] => [f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay] +[@JsOverlay public static final String STRING_COMPILE_TIME_CONSTANT = "10";] => [/**@const {string} @nodts*/ +$Overlay.f_STRING_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay = '10';] +[STRING_COMPILE_TIME_CONSTANT] => [f_STRING_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay] diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.impl.java.js.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.impl.java.js.txt index 612d09b91a..cefb7c48f1 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.impl.java.js.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.impl.java.js.txt @@ -7,6 +7,7 @@ let j_l_String = goog.forwardDeclare('java.lang.String$impl'); let NativeJsTypeInterfaceWithOverlay_$Overlay = goog.forwardDeclare('jsoverlay.Main.NativeJsTypeInterfaceWithOverlay.$Overlay$impl'); let NativeJsTypeInterfaceWithOverlayImpl = goog.forwardDeclare('jsoverlay.Main.NativeJsTypeInterfaceWithOverlayImpl$impl'); let $Overlay = goog.forwardDeclare('jsoverlay.Main.NativeJsTypeWithOverlay.$Overlay$impl'); +let NativeJsTypeWithOverlayConstant_$Overlay = goog.forwardDeclare('jsoverlay.Main.NativeJsTypeWithOverlayConstant.$Overlay$impl'); let NativeJsTypeInterfaceWithOverlay = goog.forwardDeclare('test.foo.NativeJsTypeInterfaceWithOverlay'); let NativeJsTypeWithOverlay = goog.forwardDeclare('test.foo.NativeJsTypeWithOverlay'); let $Arrays = goog.forwardDeclare('vmbootstrap.Arrays$impl'); @@ -36,11 +37,11 @@ class Main extends j_l_Object { NativeJsTypeWithOverlay.n(); $Overlay.m_bar__int(); $Overlay.m_foo__$devirt__jsoverlay_Main_NativeJsTypeWithOverlay__int(n); - let a = $Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay + NativeJsTypeWithOverlay.nonJsOverlayField | 0; + let a = NativeJsTypeWithOverlayConstant_$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay + NativeJsTypeWithOverlay.nonJsOverlayField | 0; $Overlay.f_staticField__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay = null; $Overlay.m_varargs__arrayOf_int__int(/**@type {!Array}*/ ($Arrays.$init([1, 2, 3], $$int))); $Overlay.m_baz__$devirt__jsoverlay_Main_NativeJsTypeWithOverlay__int(n); - let b = j_l_String.m_valueOf__java_lang_Object__java_lang_String(NativeJsTypeInterfaceWithOverlay_$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay) + j_l_String.m_valueOf__java_lang_Object__java_lang_String(NativeJsTypeInterfaceWithOverlay_$Overlay.f_staticField__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay); + let b = j_l_String.m_valueOf__java_lang_Object__java_lang_String(NativeJsTypeWithOverlayConstant_$Overlay.f_STRING_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay) + j_l_String.m_valueOf__java_lang_Object__java_lang_String(NativeJsTypeInterfaceWithOverlay_$Overlay.f_staticField__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay); } /** @nodts */ m_testOverlayInterface__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay__void(/** NativeJsTypeInterfaceWithOverlay */ foo) { @@ -71,6 +72,7 @@ class Main extends j_l_Object { NativeJsTypeInterfaceWithOverlay_$Overlay = goog.module.get('jsoverlay.Main.NativeJsTypeInterfaceWithOverlay.$Overlay$impl'); NativeJsTypeInterfaceWithOverlayImpl = goog.module.get('jsoverlay.Main.NativeJsTypeInterfaceWithOverlayImpl$impl'); $Overlay = goog.module.get('jsoverlay.Main.NativeJsTypeWithOverlay.$Overlay$impl'); + NativeJsTypeWithOverlayConstant_$Overlay = goog.module.get('jsoverlay.Main.NativeJsTypeWithOverlayConstant.$Overlay$impl'); NativeJsTypeWithOverlay = goog.module.get('test.foo.NativeJsTypeWithOverlay'); $Arrays = goog.module.get('vmbootstrap.Arrays$impl'); $$int = goog.module.get('vmbootstrap.primitives.$int$impl'); diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.java.js.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.java.js.txt index 30820d574d..a0b15b1a5c 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.java.js.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.java.js.txt @@ -5,6 +5,7 @@ goog.require('java.lang.String'); goog.require('jsoverlay.Main.NativeJsTypeInterfaceWithOverlay.$Overlay'); goog.require('jsoverlay.Main.NativeJsTypeInterfaceWithOverlayImpl'); goog.require('jsoverlay.Main.NativeJsTypeWithOverlay.$Overlay'); +goog.require('jsoverlay.Main.NativeJsTypeWithOverlayConstant.$Overlay'); goog.require('nativebootstrap.Util'); goog.require('test.foo.NativeJsTypeInterfaceWithOverlay'); goog.require('test.foo.NativeJsTypeWithOverlay'); diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.js.mappings.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.js.mappings.txt index accfd270b7..69b1d64352 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.js.mappings.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_closure/Main.js.mappings.txt @@ -17,14 +17,15 @@ [NativeJsTypeWithOverlay.bar();] => [$Overlay.m_bar__int();] "jsoverlay.Main.test" [n.foo();] => [$Overlay.m_foo__$devirt__jsoverlay_Main_NativeJsTypeWithOverlay__int(n);] "jsoverlay.Main.test" [int a = - NativeJsTypeWithOverlay.COMPILE_TIME_CONSTANT + NativeJsTypeWithOverlay.nonJsOverlayField;] => [let a = $Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay + NativeJsTypeWithOverlay.nonJsOverlayField | 0;] "jsoverlay.Main.test" + NativeJsTypeWithOverlayConstant.COMPILE_TIME_CONSTANT + + NativeJsTypeWithOverlay.nonJsOverlayField;] => [let a = NativeJsTypeWithOverlayConstant_$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay + NativeJsTypeWithOverlay.nonJsOverlayField | 0;] "jsoverlay.Main.test" [a] => [a] "a" [NativeJsTypeWithOverlay.staticField = null;] => [$Overlay.f_staticField__jsoverlay_Main_NativeJsTypeWithOverlay_$Overlay = null;] "jsoverlay.Main.test" [NativeJsTypeWithOverlay.varargs(1, 2, 3);] => [$Overlay.m_varargs__arrayOf_int__int(/**@type {!Array}*/ ($Arrays.$init([1, 2, 3], $$int)));] "jsoverlay.Main.test" [n.baz();] => [$Overlay.m_baz__$devirt__jsoverlay_Main_NativeJsTypeWithOverlay__int(n);] "jsoverlay.Main.test" [String b = - NativeJsTypeInterfaceWithOverlay.COMPILE_TIME_CONSTANT - + NativeJsTypeInterfaceWithOverlay.staticField;] => [let b = j_l_String.m_valueOf__java_lang_Object__java_lang_String(NativeJsTypeInterfaceWithOverlay_$Overlay.f_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay) + j_l_String.m_valueOf__java_lang_Object__java_lang_String(NativeJsTypeInterfaceWithOverlay_$Overlay.f_staticField__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay);] "jsoverlay.Main.test" + NativeJsTypeWithOverlayConstant.STRING_COMPILE_TIME_CONSTANT + + NativeJsTypeInterfaceWithOverlay.staticField;] => [let b = j_l_String.m_valueOf__java_lang_Object__java_lang_String(NativeJsTypeWithOverlayConstant_$Overlay.f_STRING_COMPILE_TIME_CONSTANT__jsoverlay_Main_NativeJsTypeWithOverlayConstant_$Overlay) + j_l_String.m_valueOf__java_lang_Object__java_lang_String(NativeJsTypeInterfaceWithOverlay_$Overlay.f_staticField__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay_$Overlay);] "jsoverlay.Main.test" [b] => [b] "b" [testOverlayInterface] => [m_testOverlayInterface__jsoverlay_Main_NativeJsTypeInterfaceWithOverlay__void] [foo] => [foo] "foo" diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_kt/Main+J2ObjCCompat.h.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_kt/Main+J2ObjCCompat.h.txt index 5e2d25f78f..d9ca001cb0 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_kt/Main+J2ObjCCompat.h.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_kt/Main+J2ObjCCompat.h.txt @@ -9,7 +9,6 @@ @class J2ktJsoverlayMain_NativeJsTypeInterfaceWithOverlayCompanion; @class J2ktJsoverlayMain_NativeJsTypeWithOverlay; @class J2ktJsoverlayMain_NativeJsTypeWithOverlayCompanion; -@class NSString; @protocol J2ktJsoverlayMain_NativeJsTypeInterfaceWithOverlay; @@ -27,10 +26,6 @@ NS_INLINE void JsoverlayMain_testOverlayInterfaceImpl(void) { @compatibility_alias JsoverlayMain_NativeJsTypeInterfaceWithOverlayCompanion J2ktJsoverlayMain_NativeJsTypeInterfaceWithOverlayCompanion; -NS_INLINE NSString* JsoverlayMain_NativeJsTypeInterfaceWithOverlay_get_COMPILE_TIME_CONSTANT(void) { - return J2ktJsoverlayMain_NativeJsTypeInterfaceWithOverlayCompanion.shared.COMPILE_TIME_CONSTANT_; -} - NS_INLINE id _Nullable JsoverlayMain_NativeJsTypeInterfaceWithOverlay_get_staticField(void) { return J2ktJsoverlayMain_NativeJsTypeInterfaceWithOverlayCompanion.shared.staticField_; } @@ -39,8 +34,6 @@ NS_INLINE id _Nullable JsoverlayMain_NativeJsTypeInterfaceWithOverlay_get_static @compatibility_alias JsoverlayMain_NativeJsTypeWithOverlayCompanion J2ktJsoverlayMain_NativeJsTypeWithOverlayCompanion; -#define JsoverlayMain_NativeJsTypeWithOverlay_COMPILE_TIME_CONSTANT 10 - NS_INLINE jint JsoverlayMain_NativeJsTypeWithOverlay_get_nonJsOverlayField(void) { return J2ktJsoverlayMain_NativeJsTypeWithOverlayCompanion.shared.nonJsOverlayField_; } @@ -49,10 +42,6 @@ NS_INLINE void JsoverlayMain_NativeJsTypeWithOverlay_set_nonJsOverlayField(jint J2ktJsoverlayMain_NativeJsTypeWithOverlayCompanion.shared.nonJsOverlayField_ = value; } -NS_INLINE jint JsoverlayMain_NativeJsTypeWithOverlay_get_COMPILE_TIME_CONSTANT(void) { - return J2ktJsoverlayMain_NativeJsTypeWithOverlayCompanion.shared.COMPILE_TIME_CONSTANT_; -} - NS_INLINE id _Nullable JsoverlayMain_NativeJsTypeWithOverlay_get_staticField(void) { return J2ktJsoverlayMain_NativeJsTypeWithOverlayCompanion.shared.staticField_; } diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_kt/Main.kt.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_kt/Main.kt.txt index f1ddb18665..6a54889a1b 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_kt/Main.kt.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsoverlay/output_kt/Main.kt.txt @@ -42,11 +42,11 @@ open class Main { Main.NativeJsTypeWithOverlay.n() Main.NativeJsTypeWithOverlay.bar_private_2() n!!.foo_private_2() - val a: Int = Main.NativeJsTypeWithOverlay.COMPILE_TIME_CONSTANT + Main.NativeJsTypeWithOverlay.nonJsOverlayField + val a: Int = Main.NativeJsTypeWithOverlayConstant.COMPILE_TIME_CONSTANT + Main.NativeJsTypeWithOverlay.nonJsOverlayField Main.NativeJsTypeWithOverlay.staticField = null Main.NativeJsTypeWithOverlay.varargs(1, 2, 3) n!!.baz_private_2() - val b: String? = Main.NativeJsTypeInterfaceWithOverlay.COMPILE_TIME_CONSTANT + Main.NativeJsTypeInterfaceWithOverlay.staticField + val b: String? = Main.NativeJsTypeWithOverlayConstant.STRING_COMPILE_TIME_CONSTANT + Main.NativeJsTypeInterfaceWithOverlay.staticField } @ObjCName("testOverlayInterface") @@ -82,10 +82,7 @@ open class Main { @ObjCName("J2ktJsoverlayMain_NativeJsTypeInterfaceWithOverlayCompanion", exact = true) companion object { - @ObjCName("COMPILE_TIME_CONSTANT_") - @JsOverlay - const val COMPILE_TIME_CONSTANT: String = "10" - + @JvmField @ObjCName("staticField_") @JsOverlay val staticField: Any? = Any() @@ -138,10 +135,6 @@ open class Main { @ObjCName("nonJsOverlayField_") var nonJsOverlayField: Int = 0 - @ObjCName("COMPILE_TIME_CONSTANT_") - @JsOverlay - const val COMPILE_TIME_CONSTANT: Int = 10 - @JvmField @ObjCName("staticField_") @JsOverlay @@ -182,6 +175,17 @@ open class Main { } } + @JsType(name = "Object", namespace = JsPackage.GLOBAL, isNative = true) + open class NativeJsTypeWithOverlayConstant internal constructor() { + companion object { + @JsOverlay + const val COMPILE_TIME_CONSTANT: Int = 10 + + @JsOverlay + const val STRING_COMPILE_TIME_CONSTANT: String = "10" + } + } + @JsFunction fun interface Intf { @ObjCName("run")