diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index c43fab5..1cae877 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -14,7 +14,7 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Setup Chrome
- uses: browser-actions/setup-chrome@v1.2.3
+ uses: browser-actions/setup-chrome@v1.7.1
- name: Checkout
uses: actions/checkout@v2
- name: Set up Java 11
diff --git a/annotations/pom.xml b/annotations/pom.xml
index 8dbfba4..6ff9876 100644
--- a/annotations/pom.xml
+++ b/annotations/pom.xml
@@ -4,7 +4,7 @@
org.treblereel.j2cl.processors
parent
- 0.6.3
+ 0.7
annotations
diff --git a/common/pom.xml b/common/pom.xml
index d52696b..7251b70 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -6,7 +6,7 @@
org.treblereel.j2cl.processors
parent
- 0.6.3
+ 0.7
common
diff --git a/pom.xml b/pom.xml
index 4da26cf..6b2cf06 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
org.treblereel.j2cl.processors
parent
- 0.6.3
+ 0.7
pom
GWT3 processors parent
@@ -42,8 +42,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -57,9 +57,9 @@
3.2.4
3.0
- 1.1.0
+ 1.2.1
2.0.0
- 0.11.0-9336533b6
+ v20240622-2
0.11
1.0-rc7
4.8.141
@@ -67,7 +67,7 @@
2.8.0
1.2
3.3.9
- 1.1.0
+ 1.9.20
4.11
@@ -87,41 +87,26 @@
${com.google.elemental2.version}
- com.vertispan.j2cl
+ org.kie.j2cl.tools
frontend-common
${j2cl.version}
- com.vertispan.j2cl
+ org.kie.j2cl.tools
frontend-javac
${j2cl.version}
- org.apache.maven
- maven-aether-provider
- ${maven.aether.provider.version}
+ org.apache.maven.resolver
+ maven-resolver-api
+ ${maven.resolver.version}
- org.eclipse.aether
- aether-impl
- ${org.eclipse.aether.version}
-
-
- org.eclipse.aether
- aether-transport-file
- ${org.eclipse.aether.version}
-
-
- org.eclipse.aether
- aether-transport-http
- ${org.eclipse.aether.version}
-
-
- org.eclipse.aether
- aether-connector-basic
- ${org.eclipse.aether.version}
+ org.apache.maven.resolver
+ maven-resolver-supplier
+ ${maven.resolver.version}
diff --git a/processor/pom.xml b/processor/pom.xml
index 5899aa6..c0aa280 100644
--- a/processor/pom.xml
+++ b/processor/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl.processors
parent
- 0.6.3
+ 0.7
processors
@@ -87,24 +87,12 @@
v20221004
- org.apache.maven
- maven-aether-provider
+ org.apache.maven.resolver
+ maven-resolver-api
- org.eclipse.aether
- aether-impl
-
-
- org.eclipse.aether
- aether-transport-file
-
-
- org.eclipse.aether
- aether-transport-http
-
-
- org.eclipse.aether
- aether-connector-basic
+ org.apache.maven.resolver
+ maven-resolver-supplier
junit
diff --git a/processor/src/main/java/org/treblereel/j2cl/processors/GWT3Processor.java b/processor/src/main/java/org/treblereel/j2cl/processors/GWT3Processor.java
index b59f4f1..31a2649 100644
--- a/processor/src/main/java/org/treblereel/j2cl/processors/GWT3Processor.java
+++ b/processor/src/main/java/org/treblereel/j2cl/processors/GWT3Processor.java
@@ -33,7 +33,7 @@
import org.treblereel.j2cl.processors.generator.resources.GWT3ResourceGenerator;
@AutoService(Processor.class)
-@SupportedSourceVersion(SourceVersion.RELEASE_8)
+@SupportedSourceVersion(SourceVersion.RELEASE_11)
@SupportedAnnotationTypes({
"org.treblereel.j2cl.processors.annotations.GWT3EntryPoint",
"org.treblereel.j2cl.processors.annotations.ES6Module",
diff --git a/processor/src/main/java/org/treblereel/j2cl/processors/generator/GWT3ExportGenerator.java b/processor/src/main/java/org/treblereel/j2cl/processors/generator/GWT3ExportGenerator.java
index 6286b6d..35739cb 100644
--- a/processor/src/main/java/org/treblereel/j2cl/processors/generator/GWT3ExportGenerator.java
+++ b/processor/src/main/java/org/treblereel/j2cl/processors/generator/GWT3ExportGenerator.java
@@ -29,7 +29,9 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.Map;
+import java.util.Queue;
import java.util.Set;
import java.util.stream.Collectors;
import javax.lang.model.element.Element;
@@ -112,13 +114,13 @@ public void generate(Set elements) {
exports.put(checkClazz(parent), new HashSet<>());
exports.get(parent).addAll(methods);
- ElementFilter.methodsIn(parent.getEnclosedElements()).stream()
+ getAllMethodsIn(parent).stream()
.filter(elm -> !elm.getModifiers().contains(Modifier.PRIVATE))
.filter(elm -> !elm.getModifiers().contains(Modifier.NATIVE))
.filter(elm -> !elm.getModifiers().contains(Modifier.ABSTRACT))
.forEach(elm -> exportDTOs.get(parent).addMethod(getMethodDTO(parent, elm)));
- ElementFilter.fieldsIn(parent.getEnclosedElements()).stream()
+ getAllFieldsIn(parent).stream()
.filter(elm -> !elm.getModifiers().contains(Modifier.PRIVATE))
.filter(elm -> !elm.getModifiers().contains(Modifier.NATIVE))
.filter(elm -> !elm.getModifiers().contains(Modifier.ABSTRACT))
@@ -287,9 +289,8 @@ private TypeElement checkClazz(TypeElement parent) {
+ ", mustn't be annotated with @ES6Module");
}
Set constructors =
- ElementFilter.constructorsIn(parent.getEnclosedElements()).stream()
- .collect(Collectors.toSet());
- if (!constructors.isEmpty()) {
+ new HashSet<>(ElementFilter.constructorsIn(parent.getEnclosedElements()));
+ if (parent.getAnnotation(JsType.class) == null && !constructors.isEmpty()) {
constructors.stream()
.filter(elm -> elm.getModifiers().contains(Modifier.PUBLIC))
.filter(elm -> elm.getParameters().isEmpty())
@@ -305,4 +306,34 @@ private TypeElement checkClazz(TypeElement parent) {
return parent;
}
+
+ private Set getAllMethodsIn(TypeElement parent) {
+ Set elements = new HashSet<>();
+ Queue queue = new LinkedList<>();
+ queue.add(parent);
+ while (!queue.isEmpty()) {
+ TypeElement current = queue.poll();
+ elements.addAll(ElementFilter.methodsIn(current.getEnclosedElements()));
+ if (!current.getSuperclass().toString().equals("java.lang.Object")
+ && MoreTypes.asElement(current.getSuperclass()).getKind().isClass()) {
+ queue.offer((TypeElement) MoreTypes.asElement(current.getSuperclass()));
+ }
+ }
+ return elements;
+ }
+
+ private Set getAllFieldsIn(TypeElement parent) {
+ Set elements = new HashSet<>();
+ Queue queue = new LinkedList<>();
+ queue.add(parent);
+ while (!queue.isEmpty()) {
+ TypeElement current = queue.poll();
+ elements.addAll(ElementFilter.fieldsIn(current.getEnclosedElements()));
+ if (!current.getSuperclass().toString().equals("java.lang.Object")
+ && MoreTypes.asElement(current.getSuperclass()).getKind().isClass()) {
+ queue.offer((TypeElement) MoreTypes.asElement(current.getSuperclass()));
+ }
+ }
+ return elements;
+ }
}
diff --git a/processor/src/main/java/org/treblereel/j2cl/processors/generator/resources/MavenArtifactDownloader.java b/processor/src/main/java/org/treblereel/j2cl/processors/generator/resources/MavenArtifactDownloader.java
index 14cbf29..fdfbb4f 100644
--- a/processor/src/main/java/org/treblereel/j2cl/processors/generator/resources/MavenArtifactDownloader.java
+++ b/processor/src/main/java/org/treblereel/j2cl/processors/generator/resources/MavenArtifactDownloader.java
@@ -29,25 +29,19 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.tools.FileObject;
-import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.AbstractRepositoryListener;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
-import org.eclipse.aether.impl.DefaultServiceLocator;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;
-import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
-import org.eclipse.aether.spi.connector.transport.TransporterFactory;
+import org.eclipse.aether.supplier.RepositorySystemSupplier;
import org.eclipse.aether.transfer.AbstractTransferListener;
-import org.eclipse.aether.transport.file.FileTransporterFactory;
-import org.eclipse.aether.transport.http.HttpTransporterFactory;
import org.treblereel.j2cl.processors.exception.GenerationException;
class MavenArtifactDownloader {
@@ -137,19 +131,18 @@ private void download() {
this.artifact = artifactResult.getArtifact();
} catch (ArtifactResolutionException e) {
throw new GenerationException(e);
+ } finally {
+ system.shutdown();
}
}
private RepositorySystem newRepositorySystem() {
- DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
- locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
- locator.addService(TransporterFactory.class, FileTransporterFactory.class);
- locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
- return locator.getService(RepositorySystem.class);
+ RepositorySystemSupplier supplier = new RepositorySystemSupplier();
+ return supplier.get();
}
private RepositorySystemSession newSession(RepositorySystem system) {
- DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
+ DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
LocalRepository localRepo = new LocalRepository(tempDir);
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
session.setTransferListener(new ConsoleTransferListener());
diff --git a/processor/src/main/resources/templates/resources/export.ftlh b/processor/src/main/resources/templates/resources/export.ftlh
index 3ea900d..b6f3691 100644
--- a/processor/src/main/resources/templates/resources/export.ftlh
+++ b/processor/src/main/resources/templates/resources/export.ftlh
@@ -1,25 +1,33 @@
+<#if !isNative>
+/**
+* @fileoverview
+* @suppress {missingProperties}
+*/
+#if>
goog.module('${module}$GWT3Export');
const EXPORT = goog.require('${target}');
<#if isNative>
goog.exportSymbol('${type}', EXPORT);
-<#else>
-const j_l_Object = goog.require('java.lang.Object$impl');
-const $Util = goog.require('nativebootstrap.Util$impl');
-class _EXPORT extends EXPORT {
- constructor() {
- EXPORT.$clinit();
- super();
- this.${ctor}();
+<#list methods as method>
+goog.exportSymbol('${type}.<#if !method.isStatic>prototype.#if>${method.name}', EXPORT.<#if !method.isStatic>prototype.#if>${method.mangleName});
+#list>
+<#else>
+const classProxy = new Proxy(EXPORT, {
+ construct(target, args) {
+ return EXPORT.$create__();
}
-}
-
-$Util.$setClassMetadata(_EXPORT, '${module}');
-goog.exportSymbol('${type}', _EXPORT);
-#if>
+});
+EXPORT.$clinit();
+goog.exportSymbol('${type}', classProxy);
<#list methods as method>
-goog.exportSymbol('${type}.<#if !method.isStatic>prototype.#if>${method.name}', EXPORT.<#if !method.isStatic>prototype.#if>${method.mangleName});
+<#if method.isStatic>
+goog.exportProperty(EXPORT, '${method.name}', EXPORT.${method.mangleName});
+<#else>
+goog.exportSymbol('${type}.prototype.${method.name}', classProxy.prototype.${method.mangleName});
+#if>
#list>
+#if>
diff --git a/tests/commons/pom.xml b/tests/commons/pom.xml
index de7dd15..53dde33 100644
--- a/tests/commons/pom.xml
+++ b/tests/commons/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
common-tests
- 0.6.3
+ 0.7
Common test cases
Common test cases
@@ -15,8 +15,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -24,13 +24,13 @@
3.1.0
3.0.1
3.0
- 0.21.0
- 0.11.0-9336533b6
+ 0.23.1
+ v20240622-2
3.0-beta-02
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -58,20 +58,20 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-annotations
${maven.j2cl.version}
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${maven.j2cl.version}
sources
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-emul
${maven.j2cl.version}
test
@@ -85,7 +85,7 @@
org.treblereel.j2cl.processors
common
- 0.6.3
+ 0.7
test
@@ -107,7 +107,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/entrypoint/jstype/pom.xml b/tests/entrypoint/jstype/pom.xml
index bd1007d..c2fa6f0 100644
--- a/tests/entrypoint/jstype/pom.xml
+++ b/tests/entrypoint/jstype/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
entrypoint-jstype-tests
- 0.6.3
+ 0.7
GWT3 Entry Point Tests for @JsType class
Test cases for the GWT3 Entry Point for @JsType class
@@ -15,8 +15,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -24,14 +24,14 @@
3.1.0
3.0.1
3.0
- 0.21.0
- 0.11.0-9336533b6
+ 0.23.1
+ v20240622-2
4.12.1
4.13.1
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -91,7 +91,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/entrypoint/pojo/pom.xml b/tests/entrypoint/pojo/pom.xml
index 50aa4e6..7f3b301 100644
--- a/tests/entrypoint/pojo/pom.xml
+++ b/tests/entrypoint/pojo/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
entrypoint-pojo-tests
- 0.6.3
+ 0.7
GWT3 Entry Point Tests for Pojo class
Test cases for the GWT3 Entry Point for Pojo class
@@ -15,8 +15,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -24,14 +24,14 @@
3.1.0
3.0.1
3.0
- 0.21.0
- 0.11.0-9336533b6
+ 0.23.1
+ v20240622-2
4.12.1
4.13.1
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -92,7 +92,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/entrypoint/pom.xml b/tests/entrypoint/pom.xml
index 442241c..432f763 100644
--- a/tests/entrypoint/pom.xml
+++ b/tests/entrypoint/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
entrypoint-tests
- 0.6.3
+ 0.7
pom
GWT3 Entry Point Tests
diff --git a/tests/es6shim/pom.xml b/tests/es6shim/pom.xml
index 11eb9d2..0dd8b5b 100644
--- a/tests/es6shim/pom.xml
+++ b/tests/es6shim/pom.xml
@@ -5,7 +5,7 @@
es6shim-tests
org.treblereel.j2cl
- 0.6.3
+ 0.7
jar
ES6SHIM Tests
@@ -16,8 +16,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -25,13 +25,13 @@
3.1.0
3.0.1
3.0
- 0.21.0
- 0.11.0-9336533b6
+ 0.23.1
+ v20240622-2
3.0-beta-02
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -62,20 +62,20 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-annotations
${maven.j2cl.version}
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${maven.j2cl.version}
sources
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-emul
${maven.j2cl.version}
test
@@ -99,7 +99,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/exports/javaenv/pom-advanced.xml b/tests/exports/javaenv/pom-advanced.xml
index f8ff91c..bddff2f 100644
--- a/tests/exports/javaenv/pom-advanced.xml
+++ b/tests/exports/javaenv/pom-advanced.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
javaenv-advanced
- 0.6.3
+ 0.7
jar
GWTExports java env Tests ADVANCED mode
@@ -26,9 +26,9 @@
3.1.0
3.0.1
3.0
- 0.21.0
+ 0.23.1
- 0.11.0-9336533b6
+ v20240622-2
4.12.1
4.13.1
@@ -75,20 +75,20 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-annotations
${maven.j2cl.version}
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${maven.j2cl.version}
sources
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-emul
${maven.j2cl.version}
test
@@ -120,7 +120,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/exports/javaenv/pom.xml b/tests/exports/javaenv/pom.xml
index f5a2adb..ac1f420 100644
--- a/tests/exports/javaenv/pom.xml
+++ b/tests/exports/javaenv/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
javaenv
- 0.6.3
+ 0.7
jar
GWTExports java env Tests BUNDLE_JAR mode
@@ -16,8 +16,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -26,15 +26,15 @@
3.1.0
3.0.1
3.0
- 0.21.0
+ 0.23.1
- 0.11.0-9336533b6
+ v20240622-2
4.12.1
4.13.1
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -75,20 +75,20 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-annotations
${maven.j2cl.version}
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${maven.j2cl.version}
sources
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-emul
${maven.j2cl.version}
test
@@ -120,7 +120,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/exports/jsenv/bundle_jar_pom.xml b/tests/exports/jsenv/bundle_jar_pom.xml
index e8e39bf..13aff21 100644
--- a/tests/exports/jsenv/bundle_jar_pom.xml
+++ b/tests/exports/jsenv/bundle_jar_pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
exports-bundle_jar
- 0.6.3
+ 0.7
jar
GWTExports Tests BUNDLE_JAR mode
@@ -25,7 +25,7 @@
3.1.0
3.0.1
3.0
- 0.21.0
+ 0.23.1
4.12.1
4.13.1
@@ -90,7 +90,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/exports/jsenv/pom.xml b/tests/exports/jsenv/pom.xml
index 5bb94f8..2ea6be0 100644
--- a/tests/exports/jsenv/pom.xml
+++ b/tests/exports/jsenv/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
jsenv
- 0.6.3
+ 0.7
jar
GWTExports Tests ADVANCED mode
@@ -16,8 +16,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -25,14 +25,14 @@
3.1.0
3.0.1
3.0
- 0.21.0
+ 0.23.1
4.12.1
4.13.1
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -90,7 +90,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/exports/pom.xml b/tests/exports/pom.xml
index d6ca4a4..a2414dd 100644
--- a/tests/exports/pom.xml
+++ b/tests/exports/pom.xml
@@ -6,7 +6,7 @@
org.treblereel.j2cl
tests-parent
- 0.6.3
+ 0.7
pom
diff --git a/tests/pom.xml b/tests/pom.xml
index 4e7a89d..379670c 100644
--- a/tests/pom.xml
+++ b/tests/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
tests-parent
- 0.6.3
+ 0.7
pom
GWT3 processors Tests
@@ -16,19 +16,19 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
- 0.21.0
+ 0.23.1
2.17
2.8.2
3.8.0
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
- 0.11.0-9336533b6
+ v20240622-2
4.11
4.12.1
@@ -76,23 +76,23 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-annotations
${j2cl.version}
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${j2cl.version}
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${j2cl.version}
sources
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-emul
${j2cl.version}
diff --git a/tests/resources/pom.xml b/tests/resources/pom.xml
index d4a902a..b0572e0 100644
--- a/tests/resources/pom.xml
+++ b/tests/resources/pom.xml
@@ -6,7 +6,7 @@
org.treblereel.j2cl
tests-parent
- 0.6.3
+ 0.7
resources
diff --git a/tests/resources/src/test/java/org/treblereel/j2cl/processors/test/TextResourcesTest.java b/tests/resources/src/test/java/org/treblereel/j2cl/processors/test/TextResourcesTest.java
index abc24b2..7330183 100644
--- a/tests/resources/src/test/java/org/treblereel/j2cl/processors/test/TextResourcesTest.java
+++ b/tests/resources/src/test/java/org/treblereel/j2cl/processors/test/TextResourcesTest.java
@@ -45,14 +45,14 @@ private String readFileAsString(String fileName) {
@Test
public void testEscape() {
- String content = readFileAsString("escape.txt");
- assertEquals(content, TextTestResourceImpl.INSTANCE.escape().getText());
+ String content = readFileAsString("escape.txt");
+ assertEquals(content, TextTestResourceImpl.INSTANCE.escape().getText());
}
@Test
public void testBigTxt() {
- String content = readFileAsString("bigtextresource.txt");
- assertEquals(content, TextTestResourceImpl.INSTANCE.getBig().getText());
+ String content = readFileAsString("bigtextresource.txt");
+ assertEquals(content, TextTestResourceImpl.INSTANCE.getBig().getText());
}
@Test
@@ -108,6 +108,6 @@ private void assertEquals(String str1, String str2) {
}
private String normalize(String s) {
- return s.replace("\r\n","\n");
+ return s.replace("\r\n", "\n");
}
}
diff --git a/tests/translation/default/pom.xml b/tests/translation/default/pom.xml
index 49ebe03..4c36471 100644
--- a/tests/translation/default/pom.xml
+++ b/tests/translation/default/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
translation-default
- 0.6.3
+ 0.7
jar
Translation Tests en
@@ -16,8 +16,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -25,13 +25,13 @@
3.1.0
3.0.1
3.0
- 0.21.0
- 0.11.0-9336533b6
+ 0.23.1
+ v20240622-2
3.0-beta-02
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -60,19 +60,19 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-annotations
${maven.j2cl.version}
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${maven.j2cl.version}
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-emul
${maven.j2cl.version}
test
@@ -121,7 +121,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/translation/fr/pom.xml b/tests/translation/fr/pom.xml
index 74677e9..69b77d5 100644
--- a/tests/translation/fr/pom.xml
+++ b/tests/translation/fr/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
translation-fr
- 0.6.3
+ 0.7
jar
Translation Tests fr
@@ -16,8 +16,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -25,13 +25,13 @@
3.1.0
3.0.1
3.0
- 0.21.0
- 0.11.0-9336533b6
+ 0.23.1
+ v20240622-2
3.0-beta-02
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -62,20 +62,20 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-annotations
${maven.j2cl.version}
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${maven.j2cl.version}
sources
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-emul
${maven.j2cl.version}
test
@@ -118,7 +118,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/translation/fr_nr/pom.xml b/tests/translation/fr_nr/pom.xml
index c092c85..78344d6 100644
--- a/tests/translation/fr_nr/pom.xml
+++ b/tests/translation/fr_nr/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
translation-fr-nr
- 0.6.3
+ 0.7
jar
Translation Tests fr-nr
@@ -16,8 +16,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -25,13 +25,13 @@
3.1.0
3.0.1
3.0
- 0.21.0
- 0.11.0-9336533b6
+ 0.23.1
+ v20240622-2
3.0-beta-02
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -62,20 +62,20 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-annotations
${maven.j2cl.version}
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${maven.j2cl.version}
sources
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-emul
${maven.j2cl.version}
test
@@ -118,7 +118,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/translation/no_bundle/pom.xml b/tests/translation/no_bundle/pom.xml
index 562ea35..7e08cb4 100644
--- a/tests/translation/no_bundle/pom.xml
+++ b/tests/translation/no_bundle/pom.xml
@@ -6,7 +6,7 @@
org.treblereel.j2cl
translation-tests
- 0.6.3
+ 0.7
translation-no_bundle
@@ -20,8 +20,8 @@
UTF-8
UTF-8
- 1.8
- 1.8
+ 11
+ 11
3.8.0
2.17
2.8.2
@@ -29,13 +29,13 @@
3.1.0
3.0.1
3.0
- 0.21.0
- 0.11.0-9336533b6
+ 0.23.1
+ v20240622-2
3.0-beta-02
2.0.0
1.0.0
- 1.1.0
+ 1.2.1
@@ -66,20 +66,20 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-annotations
${maven.j2cl.version}
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
gwttestcase-emul
${maven.j2cl.version}
sources
test
- com.vertispan.j2cl
+ org.kie.j2cl.tools
junit-emul
${maven.j2cl.version}
test
@@ -122,7 +122,7 @@
- com.vertispan.j2cl
+ org.kie.j2cl.tools
j2cl-maven-plugin
${maven.j2cl.plugin}
diff --git a/tests/translation/pom.xml b/tests/translation/pom.xml
index 0f11fa6..5c106d6 100644
--- a/tests/translation/pom.xml
+++ b/tests/translation/pom.xml
@@ -5,7 +5,7 @@
org.treblereel.j2cl
translation-tests
- 0.6.3
+ 0.7
pom
GWT3 Entry Point Tests
diff --git a/utils/pom.xml b/utils/pom.xml
index b7fee8c..ea96aa5 100644
--- a/utils/pom.xml
+++ b/utils/pom.xml
@@ -5,7 +5,7 @@
parent
org.treblereel.j2cl.processors
- 0.6.3
+ 0.7
4.0.0
@@ -43,12 +43,12 @@
${auto.common.version}
- com.vertispan.j2cl
+ org.kie.j2cl.tools
frontend-common
- com.vertispan.j2cl
+ org.kie.j2cl.tools
frontend-javac
diff --git a/utils/src/main/java/org/treblereel/j2cl/processors/utils/J2CLUtils.java b/utils/src/main/java/org/treblereel/j2cl/processors/utils/J2CLUtils.java
index 48bcd92..bc3f9b2 100644
--- a/utils/src/main/java/org/treblereel/j2cl/processors/utils/J2CLUtils.java
+++ b/utils/src/main/java/org/treblereel/j2cl/processors/utils/J2CLUtils.java
@@ -17,10 +17,12 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
+import static com.google.j2cl.transpiler.ast.TypeDeclaration.Kind;
+import static com.google.j2cl.transpiler.ast.TypeDeclaration.newBuilder;
-import com.google.auto.common.MoreElements;
import com.google.auto.common.MoreTypes;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import com.google.j2cl.common.InternalCompilerError;
import com.google.j2cl.transpiler.ast.ArrayTypeDescriptor;
@@ -29,8 +31,7 @@
import com.google.j2cl.transpiler.ast.FieldDescriptor;
import com.google.j2cl.transpiler.ast.JsEnumInfo;
import com.google.j2cl.transpiler.ast.JsInfo;
-import com.google.j2cl.transpiler.ast.JsMemberType;
-import com.google.j2cl.transpiler.ast.Kind;
+import com.google.j2cl.transpiler.ast.Literal;
import com.google.j2cl.transpiler.ast.MemberDescriptor;
import com.google.j2cl.transpiler.ast.MethodDescriptor;
import com.google.j2cl.transpiler.ast.MethodDescriptor.ParameterDescriptor;
@@ -43,8 +44,11 @@
import com.google.j2cl.transpiler.frontend.javac.JsInteropAnnotationUtils;
import com.google.j2cl.transpiler.frontend.javac.JsInteropUtils;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
-import java.util.function.Predicate;
+import java.util.Map;
import java.util.function.Supplier;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.AnnotatedConstruct;
@@ -66,7 +70,6 @@
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
-import jsinterop.annotations.JsPackage;
/**
* Utility functions to interact with JavaC internal representations.
@@ -74,35 +77,120 @@
*
it's taken from J2CL project
*/
public class J2CLUtils {
- private final Types types;
+ private final Types javacTypes;
private final Elements elements;
private final ProcessingEnvironment processingEnv;
+ private final Map
+ cachedDeclaredTypeDescriptorByDeclaredTypeInNullMarkedScope = new HashMap<>();
+ private final Map
+ cachedDeclaredTypeDescriptorByDeclaredTypeOutOfNullMarkedScope = new HashMap<>();
public J2CLUtils(ProcessingEnvironment processingEnv) {
- this.types = processingEnv.getTypeUtils();
+ this.javacTypes = processingEnv.getTypeUtils();
this.elements = processingEnv.getElementUtils();
this.processingEnv = processingEnv;
+ initWellKnownTypes(TypeDescriptors.getWellKnownTypeNames());
}
- public static boolean hasJsMemberAnnotation(ExecutableElement method) {
- return JsInteropAnnotationUtils.getJsMethodAnnotation(method) != null
- || JsInteropAnnotationUtils.getJsPropertyAnnotation(method) != null
- || JsInteropAnnotationUtils.getJsConstructorAnnotation(method) != null;
+ private boolean isNonNullAnnotation(AnnotationMirror annotation) {
+ DeclaredType annotationType = annotation.getAnnotationType();
+ String name = annotationType.asElement().getSimpleName().toString();
+ return name.equals("NonNull") || name.equals("JsNonNull");
}
- public static boolean isAnonymous(TypeMirror type) {
- if (type.getKind().equals(TypeKind.DECLARED)) {
- DeclaredType declaredType = (DeclaredType) type;
- TypeElement typeElem = (TypeElement) declaredType.asElement();
- if (typeElem.getNestingKind().equals(NestingKind.ANONYMOUS)) {
- return true;
+ private boolean isNullableAnnotation(AnnotationMirror annotation) {
+ DeclaredType annotationType = annotation.getAnnotationType();
+ return annotationType.asElement().getSimpleName().toString().equals("Nullable");
+ }
+
+ private DeclaredTypeDescriptor withNullability(
+ DeclaredTypeDescriptor typeDescriptor, boolean nullable) {
+ return nullable ? typeDescriptor.toNullable() : typeDescriptor.toNonNullable();
+ }
+
+ /**
+ * In case the given type element is nested, return the outermost possible enclosing type element.
+ */
+ private TypeElement toTopLevelTypeBinding(Element element) {
+ if (element.getEnclosingElement().getKind() == ElementKind.PACKAGE) {
+ return (TypeElement) element;
+ }
+ return toTopLevelTypeBinding(element.getEnclosingElement());
+ }
+
+ private boolean isValuesMethod(ExecutableElement methodElement) {
+ return methodElement.getSimpleName().contentEquals("values")
+ && methodElement.getParameters().isEmpty();
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////
+ // Utility methods to process nullability annotations on classes that are compiled separately.
+ // Javac does not present TYPE_USE annotation in the returned type instances.
+ private TypeDescriptor applyParameterNullabilityAnnotations(
+ TypeDescriptor typeDescriptor, ExecutableElement declarationMethodElement, int index) {
+ return typeDescriptor;
+ }
+
+ private int getInnerDepth(DeclaredTypeDescriptor innerType) {
+ if (innerType.getTypeDeclaration().isCapturingEnclosingInstance()) {
+ return getInnerDepth(innerType.getEnclosingTypeDescriptor()) + 1;
+ }
+ return 0;
+ }
+
+ /** Returns true if the element is annotated with @UncheckedCast. */
+ private boolean hasUncheckedCastAnnotation(Element element) {
+ return false;
+ }
+
+ /** Returns true if the element is annotated with @HasNoSideEffects. */
+ private boolean isAnnotatedWithHasNoSideEffects(Element element) {
+ return true;
+ }
+
+ private List getTypeArguments(DeclaredType declaredType) {
+ List typeArguments = new ArrayList<>();
+ DeclaredType currentType = declaredType;
+ do {
+ typeArguments.addAll(currentType.getTypeArguments());
+ Element enclosingElement = currentType.asElement().getEnclosingElement();
+ if (enclosingElement.getKind() == ElementKind.METHOD
+ || enclosingElement.getKind() == ElementKind.CONSTRUCTOR) {
+ typeArguments.addAll(
+ ((Parameterizable) enclosingElement)
+ .getTypeParameters().stream().map(Element::asType).collect(toImmutableList()));
}
+ currentType =
+ currentType.getEnclosingType() instanceof DeclaredType
+ ? (DeclaredType) currentType.getEnclosingType()
+ : null;
+ } while (currentType != null);
+ return typeArguments;
+ }
+
+ private Kind getKindFromTypeBinding(TypeElement typeElement) {
+ if (isEnum(typeElement) && !isAnonymous(typeElement)) {
+ // Do not consider the anonymous classes that constitute enum values as Enums, only the
+ // enum "class" itself is considered Kind.ENUM.
+ return Kind.ENUM;
+ } else if (isClass(typeElement) || (isEnum(typeElement) && isAnonymous(typeElement))) {
+ return Kind.CLASS;
+ } else if (isInterface(typeElement)) {
+ return Kind.INTERFACE;
}
+ throw new InternalCompilerError("Type binding %s not handled.", typeElement);
+ }
+
+ private String getJsName(final TypeElement classSymbol) {
+ return JsInteropAnnotationUtils.getJsName(classSymbol);
+ }
+
+ private boolean hasNullMarkedAnnotation(TypeElement classSymbol) {
return false;
}
- private static List getTypeParameters(TypeElement typeElement) {
+ private List getTypeParameters(TypeElement typeElement) {
List typeParameterElements =
new ArrayList<>(typeElement.getTypeParameters());
Element currentElement = typeElement;
@@ -125,7 +213,7 @@ private static List getTypeParameters(TypeElement typeElem
return typeParameterElements;
}
- public static TypeElement getEnclosingType(Element typeElement) {
+ public TypeElement getEnclosingType(Element typeElement) {
Element enclosing = typeElement.getEnclosingElement();
while (enclosing != null && !(enclosing instanceof TypeElement)) {
enclosing = enclosing.getEnclosingElement();
@@ -133,23 +221,40 @@ public static TypeElement getEnclosingType(Element typeElement) {
return (TypeElement) enclosing;
}
- public static String getJsName(final TypeElement classSymbol) {
- return JsInteropAnnotationUtils.getJsName(classSymbol);
+ private TypeElement getEnclosingType(TypeElement typeElement) {
+ Element enclosing = typeElement.getEnclosingElement();
+ while (enclosing != null && !(enclosing instanceof TypeElement)) {
+ enclosing = enclosing.getEnclosingElement();
+ }
+ return (TypeElement) enclosing;
}
- public static boolean isLocal(TypeElement typeElement) {
- return typeElement.getNestingKind() == NestingKind.LOCAL;
+ private boolean isEnum(TypeElement typeElement) {
+ return typeElement.getKind() == ElementKind.ENUM;
}
- public static boolean isStatic(Element element) {
- return element.getModifiers().contains(Modifier.STATIC);
+ private boolean isAnnotation(TypeElement typeElement) {
+ return typeElement.getKind() == ElementKind.ANNOTATION_TYPE;
}
- public static boolean isNative(Element element) {
- return element.getModifiers().contains(Modifier.NATIVE);
+ private boolean isAnonymous(TypeElement typeElement) {
+ return typeElement.getNestingKind() == NestingKind.ANONYMOUS;
+ }
+
+ private boolean isClass(TypeElement typeElement) {
+ return typeElement.getKind() == ElementKind.CLASS;
+ }
+
+ private boolean isInterface(TypeElement typeElement) {
+ return typeElement.getKind() == ElementKind.INTERFACE
+ || typeElement.getKind() == ElementKind.ANNOTATION_TYPE;
+ }
+
+ private boolean isLocal(TypeElement typeElement) {
+ return typeElement.getNestingKind() == NestingKind.LOCAL;
}
- public static Visibility getVisibility(Element element) {
+ public Visibility getVisibility(Element element) {
if (element.getModifiers().contains(Modifier.PUBLIC)) {
return Visibility.PUBLIC;
} else if (element.getModifiers().contains(Modifier.PROTECTED)) {
@@ -161,296 +266,325 @@ public static Visibility getVisibility(Element element) {
}
}
- public static String getJsNamespace(TypeElement classSymbol) {
- String jsNamespace = JsInteropAnnotationUtils.getJsNamespace(classSymbol);
- if (jsNamespace != null) {
- return jsNamespace;
- }
-
- // Maybe namespace is set via package-info file?
- boolean isTopLevelType = classSymbol.getEnclosingElement().getKind() == ElementKind.PACKAGE;
- if (isTopLevelType) {
- JsPackage jsPackage = classSymbol.getEnclosingElement().getAnnotation(JsPackage.class);
- return jsPackage != null ? jsPackage.namespace() : null;
- }
- return null;
+ private boolean isDeprecated(AnnotatedConstruct binding) {
+ return binding.getAnnotation(Deprecated.class) != null;
}
- private static List getTypeArguments(DeclaredType declaredType) {
- List typeArguments = new ArrayList<>();
- DeclaredType currentType = declaredType;
- do {
- typeArguments.addAll(currentType.getTypeArguments());
- Element enclosingElement = currentType.asElement().getEnclosingElement();
- if (enclosingElement.getKind() == ElementKind.METHOD
- || enclosingElement.getKind() == ElementKind.CONSTRUCTOR) {
- typeArguments.addAll(
- ((Parameterizable) enclosingElement)
- .getTypeParameters().stream().map(Element::asType).collect(toImmutableList()));
- }
- currentType =
- currentType.getEnclosingType() instanceof DeclaredType
- ? (DeclaredType) currentType.getEnclosingType()
- : null;
- } while (currentType != null);
- return typeArguments;
+ private boolean isDefaultMethod(Element element) {
+ return element.getModifiers().contains(Modifier.DEFAULT);
}
- private static DeclaredTypeDescriptor withNullability(
- DeclaredTypeDescriptor typeDescriptor, boolean nullable) {
- return nullable ? typeDescriptor.toNullable() : typeDescriptor.toNonNullable();
+ private boolean isAbstract(Element element) {
+ return element.getModifiers().contains(Modifier.ABSTRACT);
}
- private static boolean isNonNullAnnotation(AnnotationMirror annotation) {
- DeclaredType annotationType = annotation.getAnnotationType();
- String name = annotationType.asElement().getSimpleName().toString();
- return name.equals("NonNull") || name.equals("JsNonNull");
+ private boolean isFinal(Element element) {
+ return element.getModifiers().contains(Modifier.FINAL);
}
- private static boolean isNullableAnnotation(AnnotationMirror annotation) {
- DeclaredType annotationType = annotation.getAnnotationType();
- return annotationType.asElement().getSimpleName().toString().equals("Nullable");
+ public boolean isStatic(Element element) {
+ return element.getModifiers().contains(Modifier.STATIC);
}
- public static boolean isStatic(VariableElement variableElement) {
- return variableElement.getModifiers().contains(Modifier.STATIC);
+ private boolean isNative(Element element) {
+ return element.getModifiers().contains(Modifier.NATIVE);
}
- public static boolean isFinal(Element declarationMethodElement) {
- return declarationMethodElement.getModifiers().contains(Modifier.FINAL);
+ private boolean isSynthetic(Element element) {
+ return false;
+ // return element instanceof Symbol && (((Symbol) element).flags() & Flags.SYNTHETIC) != 0;
}
- public static boolean isInterface(TypeElement typeElement) {
- return typeElement.getKind().isInterface();
+ private MethodDescriptor ctorMethodDescriptorFromJavaConstructor(MethodDescriptor constructor) {
+ return constructor.transform(
+ builder ->
+ builder
+ .setReturnTypeDescriptor(PrimitiveTypes.VOID)
+ .setName(getCtorName(constructor))
+ .setConstructor(false)
+ .setStatic(false)
+ .setOriginalJsInfo(JsInfo.NONE)
+ .removeParameterOptionality()
+ .setOrigin(MethodDescriptor.MethodOrigin.SYNTHETIC_CTOR_FOR_CONSTRUCTOR)
+ .setVisibility(Visibility.PUBLIC));
}
- public static boolean isInterface(TypeMirror typeElement) {
- return isInterface(MoreTypes.asTypeElement(typeElement));
+ private String getCtorName(MethodDescriptor methodDescriptor) {
+ // Synthesize a name that is unique per class to avoid property clashes in JS.
+ return MethodDescriptor.CTOR_METHOD_PREFIX
+ + "__"
+ + methodDescriptor.getEnclosingTypeDescriptor().getMangledName();
}
- public static boolean isDeprecated(AnnotatedConstruct binding) {
- return hasAnnotation(binding, Deprecated.class.getName());
- }
+ private void initWellKnownTypes(Collection wellKnownQualifiedBinaryNames) {
+ if (TypeDescriptors.isInitialized()) {
+ return;
+ }
+ TypeDescriptors.SingletonBuilder builder = new TypeDescriptors.SingletonBuilder();
+ // Add well-known, non-primitive types.
+ wellKnownQualifiedBinaryNames.forEach(
+ binaryName -> {
+ String qualifiedSourceName = binaryName.replace('$', '.');
+ TypeElement element = getTypeElement(qualifiedSourceName);
+ if (element != null) {
+ builder.addReferenceType(createDeclaredTypeDescriptor(element.asType()));
+ }
+ });
+
+ DeclaredTypeDescriptor typeDescriptor =
+ createSyntheticJavaEmulInternalExceptionsTypeDescriptor();
+ builder.addReferenceType(typeDescriptor);
+ builder.buildSingleton();
+ }
+
+ private DeclaredTypeDescriptor createSyntheticJavaEmulInternalExceptionsTypeDescriptor() {
+ TypeDeclaration typeDeclaration =
+ TypeDeclaration.newBuilder()
+ .setClassComponents(ImmutableList.of("Exceptions"))
+ .setNative(false)
+ .setCustomizedJsNamespace("javaemul.internal")
+ .setPackageName("javaemul.internal")
+ .setTypeParameterDescriptors(ImmutableList.of())
+ .setVisibility(Visibility.PUBLIC)
+ .setKind(Kind.CLASS)
+ .build();
- public static boolean hasAnnotation(AnnotatedConstruct construct, String annotationSourceName) {
- return findAnnotationBindingByName(construct.getAnnotationMirrors(), annotationSourceName)
- != null;
+ return DeclaredTypeDescriptor.newBuilder()
+ .setTypeDeclaration(typeDeclaration)
+ .setTypeArgumentDescriptors(Collections.EMPTY_LIST)
+ .build();
}
- public static AnnotationMirror findAnnotationBindingByName(
- List extends AnnotationMirror> annotations, String name) {
- if (annotations == null) {
- return null;
- }
- for (AnnotationMirror annotationBinding : annotations) {
- if (((TypeElement) annotationBinding.getAnnotationType().asElement())
- .getQualifiedName()
- .contentEquals(name)) {
- return annotationBinding;
- }
- }
- return null;
+ public DeclaredTypeDescriptor createDeclaredTypeDescriptor(TypeMirror typeMirror) {
+ return createDeclaredTypeDescriptor(typeMirror, /* inNullMarkedScope= */ false);
}
- public static boolean isDefaultMethod(Element element) {
- return element.getModifiers().contains(Modifier.DEFAULT);
+ private DeclaredTypeDescriptor createDeclaredTypeDescriptor(
+ TypeMirror typeMirror, boolean inNullMarkedScope) {
+ return createTypeDescriptor(typeMirror, inNullMarkedScope, DeclaredTypeDescriptor.class);
}
- public static boolean isClass(TypeElement typeElement) {
- return typeElement.getKind().isClass();
+ /** Creates a specific subclass of TypeDescriptor from a TypeMirror. */
+ public T createTypeDescriptor(TypeMirror typeMirror, Class clazz) {
+ return createTypeDescriptor(typeMirror, /* inNullMarkedScope= */ false, clazz);
}
- public static boolean isEnum(TypeElement typeElement) {
- return typeElement.getKind().equals(ElementKind.ENUM);
+ /** Creates a specific subclass of TypeDescriptor from a TypeMirror. */
+ private T createTypeDescriptor(
+ TypeMirror typeMirror, boolean inNullMarkedScope, Class clazz) {
+ return clazz.cast(createTypeDescriptor(typeMirror, inNullMarkedScope));
}
- public static boolean isAbstract(Element element) {
- return element.getModifiers().contains(Modifier.ABSTRACT);
+ /** Creates a TypeDescriptor from a TypeMirror. */
+ public TypeDescriptor createTypeDescriptor(TypeMirror typeMirror) {
+ return createTypeDescriptor(typeMirror, /* inNullMarkedScope= */ false);
}
- public static boolean isJsEnum(TypeElement typeElement) {
- return JsInteropUtils.isJsEnum(typeElement);
+ /** Creates a TypeDescriptor from a TypeMirror. */
+ private TypeDescriptor createTypeDescriptor(TypeMirror typeMirror, boolean inNullMarkedScope) {
+ return createTypeDescriptorWithNullability(typeMirror, ImmutableList.of(), inNullMarkedScope);
}
- public TypeDeclaration createDeclarationForType(final TypeElement typeElement) {
- if (typeElement == null) {
+ /** Creates a type descriptor for the given TypeMirror, taking into account nullability. */
+ private TypeDescriptor createTypeDescriptorWithNullability(
+ TypeMirror typeMirror,
+ List extends AnnotationMirror> elementAnnotations,
+ boolean inNullMarkedScope) {
+ if (typeMirror == null || typeMirror.getKind() == TypeKind.NONE) {
return null;
}
+ if (typeMirror.getKind().isPrimitive()) {
+ return PrimitiveTypes.get(typeMirror.toString());
+ }
- boolean isFromSource = false;
- // Compute these first since they're reused in other calculations.
- String packageName = getPackageOf(typeElement).getQualifiedName().toString();
- boolean isAbstract = isAbstract(typeElement) && !isInterface(typeElement);
- boolean isFinal = isFinal(typeElement);
-
- Supplier> declaredMethods =
- () -> {
- ImmutableList.Builder listBuilder = ImmutableList.builder();
- for (ExecutableElement methodElement :
- ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
- MethodDescriptor methodDescriptor = createDeclarationMethodDescriptor(methodElement);
- listBuilder.add(methodDescriptor);
- }
- return listBuilder.build();
- };
+ if (typeMirror.getKind() == TypeKind.VOID) {
+ return PrimitiveTypes.VOID;
+ }
- Supplier> declaredFields =
- () ->
- typeElement.getEnclosedElements().stream()
- .filter(
- element ->
- element.getKind() == ElementKind.FIELD
- || element.getKind() == ElementKind.ENUM_CONSTANT)
- .map(VariableElement.class::cast)
- .map(this::createFieldDescriptor)
- .collect(toImmutableList());
+ if (typeMirror.getKind() == TypeKind.INTERSECTION) {
+ throw new InternalCompilerError("Intersection types are not supported.");
+ // return createIntersectionType((IntersectionClassType) typeMirror);
+ }
- JsEnumInfo jsEnumInfo = JsInteropUtils.getJsEnumInfo(typeElement);
+ if (typeMirror.getKind() == TypeKind.UNION) {
+ throw new InternalCompilerError("Union types are not supported.");
+ // return createUnionType((UnionClassType) typeMirror);
+ }
- List typeParameterElements = getTypeParameters(typeElement);
+ if (typeMirror.getKind() == TypeKind.NULL) {
+ return TypeDescriptors.get().javaLangObject;
+ }
- boolean isNullMarked = isNullMarked(typeElement);
- return TypeDeclaration.newBuilder()
- .setClassComponents(getClassComponents(typeElement))
- .setEnclosingTypeDeclaration(createDeclarationForType(getEnclosingType(typeElement)))
- .setInterfaceTypeDescriptorsFactory(
- () ->
- createTypeDescriptors(
- typeElement.getInterfaces(),
- isNullMarked,
- DeclaredTypeDescriptor.class,
- typeElement))
- .setUnparameterizedTypeDescriptorFactory(
- () -> createDeclaredTypeDescriptor(typeElement.asType()))
- .setHasAbstractModifier(isAbstract)
- .setKind(getKindFromTypeBinding(typeElement))
- .setCapturingEnclosingInstance(capturesEnclosingInstance(typeElement))
- .setFinal(isFinal)
- .setFunctionalInterface(isFunctionalInterface(typeElement.asType()))
- .setJsFunctionInterface(JsInteropUtils.isJsFunction(typeElement))
- .setJsType(JsInteropUtils.isJsType(typeElement))
- .setJsEnumInfo(jsEnumInfo)
- .setNative(JsInteropUtils.isJsNativeType(typeElement))
- .setAnonymous(isAnonymous(typeElement))
- .setLocal(isLocal(typeElement))
- .setSimpleJsName(getJsName(typeElement))
- .setCustomizedJsNamespace(getJsNamespace(typeElement))
- .setNullMarked(isNullMarked)
- .setPackageName(packageName)
- .setSuperTypeDescriptorFactory(
- () ->
- (DeclaredTypeDescriptor)
- applyNullabilityAnnotations(
- createDeclaredTypeDescriptor(typeElement.getSuperclass(), isNullMarked),
- typeElement,
- (obj) -> false))
- .setTypeParameterDescriptors(
- typeParameterElements.stream()
- .map(TypeParameterElement::asType)
- .map(javax.lang.model.type.TypeVariable.class::cast)
- .map(this::createTypeVariable)
- .collect(toImmutableList()))
- .setVisibility(getVisibility(typeElement))
- .setDeclaredMethodDescriptorsFactory(declaredMethods)
- .setDeclaredFieldDescriptorsFactory(declaredFields)
- .setUnusableByJsSuppressed(JsInteropAnnotationUtils.isUnusableByJsSuppressed(typeElement))
- .setDeprecated(isDeprecated(typeElement))
- .build();
- }
+ if (typeMirror.getKind() == TypeKind.TYPEVAR) {
+ return createTypeVariable((javax.lang.model.type.TypeVariable) typeMirror);
+ }
- public MethodDescriptor createDeclarationMethodDescriptor(ExecutableElement methodElement) {
- DeclaredTypeDescriptor enclosingTypeDescriptor =
- createDeclaredTypeDescriptor(methodElement.getEnclosingElement().asType());
- return createDeclarationMethodDescriptor(methodElement, enclosingTypeDescriptor);
- }
+ if (typeMirror.getKind() == TypeKind.WILDCARD) {
+ return createWildcardTypeVariable(
+ ((javax.lang.model.type.WildcardType) typeMirror).getExtendsBound());
+ }
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // Utility methods to process nullability annotations on classes that are compiled separately.
- // Javac does not present TYPE_USE annotation in the returned type instances.
- private static TypeDescriptor applyParameterNullabilityAnnotations(
- TypeDescriptor typeDescriptor, ExecutableElement declarationMethodElement, int index) {
- return applyNullabilityAnnotations(typeDescriptor, declarationMethodElement, (obj) -> false);
- // position ->
- // position.parameter_index == index
- // && position.type == TargetType.METHOD_FORMAL_PARAMETER);
- }
+ boolean isNullable = isNullable(typeMirror, elementAnnotations, inNullMarkedScope);
+ if (typeMirror.getKind() == TypeKind.ARRAY) {
+ ArrayType arrayType = (ArrayType) typeMirror;
+ TypeDescriptor componentTypeDescriptor =
+ createTypeDescriptor(arrayType.getComponentType(), inNullMarkedScope);
+ return ArrayTypeDescriptor.newBuilder()
+ .setComponentTypeDescriptor(componentTypeDescriptor)
+ .setNullable(isNullable)
+ .build();
+ }
- private static TypeDescriptor applyNullabilityAnnotations(
- TypeDescriptor typeDescriptor,
- Element declarationMethodElement,
- Predicate