From 90bcc648db261cd9bce9b281555077f27e5037e3 Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Sun, 7 Apr 2024 14:44:17 -0500 Subject: [PATCH 1/2] Clarify non-native @JsType support for Java 16 records Does not attempt to address native support - like enums, if this is to be supported, it will likely require its own annotation and semantics. Fixes #6 --- java/jsinterop/annotations/JsType.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/java/jsinterop/annotations/JsType.java b/java/jsinterop/annotations/JsType.java index f7fda98..6a4b784 100644 --- a/java/jsinterop/annotations/JsType.java +++ b/java/jsinterop/annotations/JsType.java @@ -28,7 +28,7 @@ * *

Marking an object with JsType is similar to marking each public member of the class with * {@link JsProperty}/{@link JsMethod}/{@link JsConstructor} respectively. In order for this to work - * correctly the JavaScript name needs to be unique for each member. Some unobvious ways to cause + * correctly the JavaScript name needs to be unique for each member. Some nonobvious ways to cause * name collisions are: * *

* + *

When applied to {@code record} components, the annotation will only apply to the accessor and + * not to the field - otherwise this would result in a naming conflict. Additionally, the JavaBean + * style convention is not required, as record accessors do not being with {@code get-} or + * {@code is-}. + * *

Note: In JavaScript, instance members are defined on the prototype and class members are * defined on the constructor function of the type which mimics ES6 class style. */ diff --git a/java/jsinterop/annotations/JsType.java b/java/jsinterop/annotations/JsType.java index 6a4b784..258dced 100644 --- a/java/jsinterop/annotations/JsType.java +++ b/java/jsinterop/annotations/JsType.java @@ -48,9 +48,6 @@ *

For native interfaces with no particular JavaScript type associated with them (e.g. structural * types) it is recommended to use {@code namespace = JsPackage.GLOBAL} and {@code name = '?'}. * - *

If a Java {@code record} is marked a "non-native" JsType public accessor methods are treated - * as though they are annotated with {@link JsProperty}. - * *

Instanceof and Castability: * *

If the JsType is native, the generated code will try to mimic Javascript semantics.