diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/AstWriter.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/AstWriter.java similarity index 99% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/AstWriter.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/AstWriter.java index 6f53eea8a..7ac5dbbc5 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/AstWriter.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/AstWriter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.io.IOException; import java.util.Collections; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/FunctorImpl.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/FunctorImpl.java similarity index 96% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/FunctorImpl.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/FunctorImpl.java index 198291c0a..6758a71d8 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/FunctorImpl.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/FunctorImpl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JS.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JS.java similarity index 99% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JS.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JS.java index 496759487..98d9d97b6 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JS.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JS.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.lang.reflect.Array; import java.util.function.Function; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSOAliasRenderer.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java similarity index 93% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSOAliasRenderer.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java index 9ad375ac9..8a5e7f097 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSOAliasRenderer.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.io.IOException; import java.util.Map; import org.teavm.codegen.SourceWriter; import org.teavm.javascript.RenderingContext; -import org.teavm.jso.plugin.JSODependencyListener.ExposedClass; +import org.teavm.jso.impl.JSDependencyListener.ExposedClass; import org.teavm.model.MethodDescriptor; import org.teavm.vm.BuildTarget; import org.teavm.vm.spi.RendererListener; @@ -28,12 +28,12 @@ import org.teavm.vm.spi.RendererListener; * * @author Alexey Andreev */ -class JSOAliasRenderer implements RendererListener { +class JSAliasRenderer implements RendererListener { private static String variableChars = "abcdefghijklmnopqrstuvwxyz"; - private JSODependencyListener dependencyListener; + private JSDependencyListener dependencyListener; private SourceWriter writer; - public JSOAliasRenderer(JSODependencyListener dependencyListener) { + public JSAliasRenderer(JSDependencyListener dependencyListener) { this.dependencyListener = dependencyListener; } diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyAstEmitter.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyAstEmitter.java similarity index 98% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyAstEmitter.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyAstEmitter.java index 0683f027d..29c46d1e8 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyAstEmitter.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyAstEmitter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.io.IOException; import org.mozilla.javascript.ast.AstNode; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyBloatedEmitter.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyBloatedEmitter.java similarity index 99% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyBloatedEmitter.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyBloatedEmitter.java index fdfc07b7d..72a26288c 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyBloatedEmitter.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyBloatedEmitter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.io.IOException; import org.teavm.codegen.SourceWriter; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyEmitter.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyEmitter.java similarity index 97% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyEmitter.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyEmitter.java index f793f765e..b2a51273f 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyEmitter.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyEmitter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.io.IOException; import org.teavm.codegen.SourceWriter; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyGenerator.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyGenerator.java similarity index 98% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyGenerator.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyGenerator.java index f97b4f0ee..b154cd9f8 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyGenerator.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyGenerator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.io.IOException; import org.teavm.codegen.SourceWriter; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyInlineUtil.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyInlineUtil.java similarity index 99% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyInlineUtil.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyInlineUtil.java index 509387e30..716d0a119 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyInlineUtil.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyInlineUtil.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.util.HashMap; import java.util.Map; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyRef.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyRef.java similarity index 96% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyRef.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyRef.java index 6138a2313..6fb271ba4 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyRef.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyRef.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyRepository.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyRepository.java similarity index 97% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyRepository.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyRepository.java index 9f81cb6ea..dee6d002b 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSBodyRepository.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSBodyRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.util.HashMap; import java.util.HashSet; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java similarity index 95% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java index 25e0d665c..bbb4bae90 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.io.IOException; import java.io.StringReader; @@ -78,18 +78,18 @@ import org.teavm.model.util.ProgramUtils; * * @author Alexey Andreev */ -class JavascriptNativeProcessor { +class JSClassProcessor { private ClassReaderSource classSource; private Program program; private List replacement = new ArrayList<>(); - private NativeJavascriptClassRepository nativeRepos; + private JSTypeHelper typeHelper; private Diagnostics diagnostics; private int methodIndexGenerator; private Map overridenMethodCache = new HashMap<>(); - public JavascriptNativeProcessor(ClassReaderSource classSource) { + public JSClassProcessor(ClassReaderSource classSource) { this.classSource = classSource; - nativeRepos = new NativeJavascriptClassRepository(classSource); + typeHelper = new JSTypeHelper(classSource); } public ClassReaderSource getClassSource() { @@ -97,11 +97,11 @@ class JavascriptNativeProcessor { } public boolean isNative(String className) { - return nativeRepos.isJavaScriptClass(className); + return typeHelper.isJavaScriptClass(className); } public boolean isNativeImplementation(String className) { - return nativeRepos.isJavaScriptImplementation(className); + return typeHelper.isJavaScriptImplementation(className); } public void setDiagnostics(Diagnostics diagnostics) { @@ -109,7 +109,7 @@ class JavascriptNativeProcessor { } public MethodReference isFunctor(String className) { - if (!nativeRepos.isJavaScriptImplementation(className)) { + if (!typeHelper.isJavaScriptImplementation(className)) { return null; } ClassReader cls = classSource.get(className); @@ -138,7 +138,7 @@ class JavascriptNativeProcessor { public void processClass(ClassHolder cls) { Set preservedMethods = new HashSet<>(); for (String iface : cls.getInterfaces()) { - if (nativeRepos.isJavaScriptClass(iface)) { + if (typeHelper.isJavaScriptClass(iface)) { addPreservedMethods(iface, preservedMethods); } } @@ -314,7 +314,7 @@ class JavascriptNativeProcessor { return processJSBodyInvocation(repository, method, callLocation, invoke); } - if (!nativeRepos.isJavaScriptClass(invoke.getMethod().getClassName())) { + if (!typeHelper.isJavaScriptClass(invoke.getMethod().getClassName())) { return false; } @@ -452,14 +452,14 @@ class JavascriptNativeProcessor { name = redefinedMethodName.getString(); } } - if (method.getResultType() != ValueType.VOID && !isSupportedType(method.getResultType())) { + if (method.getResultType() != ValueType.VOID && !typeHelper.isSupportedType(method.getResultType())) { diagnostics.error(callLocation, "Method {{m0}} is not a proper native JavaScript method " + "declaration", invoke.getMethod()); return false; } for (ValueType arg : method.getParameterTypes()) { - if (!isSupportedType(arg)) { + if (!typeHelper.isSupportedType(arg)) { diagnostics.error(callLocation, "Method {{m0}} is not a proper native JavaScript method " + "or constructor declaration", invoke.getMethod()); return false; @@ -521,12 +521,13 @@ class JavascriptNativeProcessor { if (!isStatic) { ValueType paramType = ValueType.object(methodToProcess.getOwnerName()); paramTypes[offset++] = paramType; - if (!isSupportedType(paramType)) { + if (!typeHelper.isSupportedType(paramType)) { diagnostics.error(location, "Non-static JSBody method {{m0}} is owned by non-JS class {{c1}}", methodToProcess.getReference(), methodToProcess.getOwnerName()); } } - if (methodToProcess.getResultType() != ValueType.VOID && !isSupportedType(methodToProcess.getResultType())) { + if (methodToProcess.getResultType() != ValueType.VOID + && !typeHelper.isSupportedType(methodToProcess.getResultType())) { diagnostics.error(location, "JSBody method {{m0}} returns unsupported type {{t1}}", methodToProcess.getReference(), methodToProcess.getResultType()); } @@ -579,8 +580,9 @@ class JavascriptNativeProcessor { } else { expr = rootNode; } - JavaInvocationValidator javaValidator = new JavaInvocationValidator(classSource, diagnostics); - javaValidator.validate(location, expr); + JavaInvocationProcessor javaInvocationProcessor = new JavaInvocationProcessor(typeHelper, + classSource, diagnostics); + javaInvocationProcessor.validate(location, expr); repository.emitters.put(proxyMethod, new JSBodyAstEmitter(isStatic, expr, parameterNames)); } repository.methodMap.put(methodToProcess.getReference(), proxyMethod); @@ -1078,7 +1080,7 @@ class JavascriptNativeProcessor { } private boolean isProperGetter(MethodDescriptor desc) { - if (desc.parameterCount() > 0 || !isSupportedType(desc.getResultType())) { + if (desc.parameterCount() > 0 || !typeHelper.isSupportedType(desc.getResultType())) { return false; } if (desc.getResultType().equals(ValueType.BOOLEAN)) { @@ -1090,7 +1092,7 @@ class JavascriptNativeProcessor { } private boolean isProperSetter(MethodDescriptor desc) { - if (desc.parameterCount() != 1 || !isSupportedType(desc.parameterType(0)) + if (desc.parameterCount() != 1 || !typeHelper.isSupportedType(desc.parameterType(0)) || desc.getResultType() != ValueType.VOID) { return false; } @@ -1106,13 +1108,13 @@ class JavascriptNativeProcessor { } private boolean isProperGetIndexer(MethodDescriptor desc) { - return desc.parameterCount() == 1 && isSupportedType(desc.parameterType(0)) - && isSupportedType(desc.getResultType()); + return desc.parameterCount() == 1 && typeHelper.isSupportedType(desc.parameterType(0)) + && typeHelper.isSupportedType(desc.getResultType()); } private boolean isProperSetIndexer(MethodDescriptor desc) { - return desc.parameterCount() == 2 && isSupportedType(desc.parameterType(0)) - && isSupportedType(desc.parameterType(0)) && desc.getResultType() == ValueType.VOID; + return desc.parameterCount() == 2 && typeHelper.isSupportedType(desc.parameterType(0)) + && typeHelper.isSupportedType(desc.parameterType(0)) && desc.getResultType() == ValueType.VOID; } private String cutPrefix(String name, int prefixLength) { @@ -1125,25 +1127,4 @@ class JavascriptNativeProcessor { } return Character.toLowerCase(name.charAt(prefixLength)) + name.substring(prefixLength + 1); } - - private boolean isSupportedType(ValueType type) { - if (type == ValueType.VOID) { - return false; - } - if (type instanceof ValueType.Primitive) { - switch (((ValueType.Primitive) type).getKind()) { - case LONG: - return false; - default: - return true; - } - } else if (type instanceof ValueType.Array) { - return isSupportedType(((ValueType.Array) type).getItemType()); - } else if (type instanceof ValueType.Object) { - String typeName = ((ValueType.Object) type).getClassName(); - return typeName.equals("java.lang.String") || nativeRepos.isJavaScriptClass(typeName); - } else { - return false; - } - } } diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSODependencyListener.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java similarity index 98% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSODependencyListener.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java index 253540b1c..826794fac 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSODependencyListener.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.util.HashMap; import java.util.HashSet; @@ -38,7 +38,7 @@ import org.teavm.model.MethodReader; * * @author Alexey Andreev */ -class JSODependencyListener extends AbstractDependencyListener { +class JSDependencyListener extends AbstractDependencyListener { private Map exposedClasses = new HashMap<>(); private ClassReaderSource classSource; private DependencyAgent agent; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSNativeGenerator.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSNativeGenerator.java similarity index 99% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSNativeGenerator.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSNativeGenerator.java index 44d64c0a0..685a12f00 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSNativeGenerator.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSNativeGenerator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.io.IOException; import org.teavm.codegen.SourceWriter; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSOPlugin.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSOPlugin.java similarity index 84% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSOPlugin.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSOPlugin.java index c23a98465..d01e1c8bc 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSOPlugin.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSOPlugin.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import org.teavm.vm.spi.TeaVMHost; import org.teavm.vm.spi.TeaVMPlugin; @@ -28,8 +28,8 @@ public class JSOPlugin implements TeaVMPlugin { JSBodyRepository repository = new JSBodyRepository(); host.registerService(JSBodyRepository.class, repository); host.add(new JSObjectClassTransformer(repository)); - JSODependencyListener dependencyListener = new JSODependencyListener(); - JSOAliasRenderer aliasRenderer = new JSOAliasRenderer(dependencyListener); + JSDependencyListener dependencyListener = new JSDependencyListener(); + JSAliasRenderer aliasRenderer = new JSAliasRenderer(dependencyListener); host.add(dependencyListener); host.add(aliasRenderer); } diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSObjectClassTransformer.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java similarity index 93% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSObjectClassTransformer.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java index b6ba5e1a2..323bc3e54 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSObjectClassTransformer.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import org.teavm.diagnostics.Diagnostics; import org.teavm.model.ClassHolder; @@ -27,7 +27,7 @@ import org.teavm.model.MethodReference; * @author Alexey Andreev */ public class JSObjectClassTransformer implements ClassHolderTransformer { - private JavascriptNativeProcessor processor; + private JSClassProcessor processor; private JSBodyRepository repository; public JSObjectClassTransformer(JSBodyRepository repository) { @@ -37,7 +37,7 @@ public class JSObjectClassTransformer implements ClassHolderTransformer { @Override public void transformClass(ClassHolder cls, ClassReaderSource innerSource, Diagnostics diagnostics) { if (processor == null || processor.getClassSource() != innerSource) { - processor = new JavascriptNativeProcessor(innerSource); + processor = new JSClassProcessor(innerSource); } processor.setDiagnostics(diagnostics); processor.processClass(cls); diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSParser.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSParser.java similarity index 97% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSParser.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSParser.java index 362cb9221..ade564f57 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JSParser.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSParser.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.ErrorReporter; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/NativeJavascriptClassRepository.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSTypeHelper.java similarity index 76% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/NativeJavascriptClassRepository.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSTypeHelper.java index 52f15a137..f15a09aa8 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/NativeJavascriptClassRepository.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JSTypeHelper.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.util.HashMap; import java.util.Map; @@ -21,17 +21,18 @@ import org.teavm.jso.JSObject; import org.teavm.model.ClassReader; import org.teavm.model.ClassReaderSource; import org.teavm.model.ElementModifier; +import org.teavm.model.ValueType; /** * * @author Alexey Andreev */ -class NativeJavascriptClassRepository { +class JSTypeHelper { private ClassReaderSource classSource; private Map knownJavaScriptClasses = new HashMap<>(); private Map knownJavaScriptImplementations = new HashMap<>(); - public NativeJavascriptClassRepository(ClassReaderSource classSource) { + public JSTypeHelper(ClassReaderSource classSource) { this.classSource = classSource; knownJavaScriptClasses.put(JSObject.class.getName(), true); } @@ -82,4 +83,25 @@ class NativeJavascriptClassRepository { } return cls.getInterfaces().stream().anyMatch(iface -> isJavaScriptClass(iface)); } + + public boolean isSupportedType(ValueType type) { + if (type == ValueType.VOID) { + return false; + } + if (type instanceof ValueType.Primitive) { + switch (((ValueType.Primitive) type).getKind()) { + case LONG: + return false; + default: + return true; + } + } else if (type instanceof ValueType.Array) { + return isSupportedType(((ValueType.Array) type).getItemType()); + } else if (type instanceof ValueType.Object) { + String typeName = ((ValueType.Object) type).getClassName(); + return typeName.equals("java.lang.String") || isJavaScriptClass(typeName); + } else { + return false; + } + } } diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JavaInvocationValidator.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JavaInvocationProcessor.java similarity index 95% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JavaInvocationValidator.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/JavaInvocationProcessor.java index a0ab73e96..a469f5dc8 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/JavaInvocationValidator.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/JavaInvocationProcessor.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import org.mozilla.javascript.Token; import org.mozilla.javascript.ast.AstNode; @@ -34,12 +34,14 @@ import org.teavm.model.MethodReference; * * @author Alexey Andreev */ -class JavaInvocationValidator implements NodeVisitor { +class JavaInvocationProcessor implements NodeVisitor { private ClassReaderSource classSource; + private JSTypeHelper typeHelper; private Diagnostics diagnostics; private CallLocation location; - public JavaInvocationValidator(ClassReaderSource classSource, Diagnostics diagnostics) { + public JavaInvocationProcessor(JSTypeHelper typeHelper, ClassReaderSource classSource, Diagnostics diagnostics) { + this.typeHelper = typeHelper; this.classSource = classSource; this.diagnostics = diagnostics; } diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/NameEmitter.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/NameEmitter.java similarity index 96% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/NameEmitter.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/NameEmitter.java index 8e5206a89..45f759b0e 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/NameEmitter.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/NameEmitter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import java.io.IOException; diff --git a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/TeaVMErrorReporter.java b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/TeaVMErrorReporter.java similarity index 98% rename from teavm-jso-impl/src/main/java/org/teavm/jso/plugin/TeaVMErrorReporter.java rename to teavm-jso-impl/src/main/java/org/teavm/jso/impl/TeaVMErrorReporter.java index 4bd2b816a..0251b8d2c 100644 --- a/teavm-jso-impl/src/main/java/org/teavm/jso/plugin/TeaVMErrorReporter.java +++ b/teavm-jso-impl/src/main/java/org/teavm/jso/impl/TeaVMErrorReporter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.jso.plugin; +package org.teavm.jso.impl; import org.mozilla.javascript.ErrorReporter; import org.mozilla.javascript.EvaluatorException; diff --git a/teavm-jso-impl/src/main/resources/META-INF/services/org.teavm.vm.spi.TeaVMPlugin b/teavm-jso-impl/src/main/resources/META-INF/services/org.teavm.vm.spi.TeaVMPlugin index c0f1b934e..16e195758 100644 --- a/teavm-jso-impl/src/main/resources/META-INF/services/org.teavm.vm.spi.TeaVMPlugin +++ b/teavm-jso-impl/src/main/resources/META-INF/services/org.teavm.vm.spi.TeaVMPlugin @@ -1 +1 @@ -org.teavm.jso.plugin.JSOPlugin \ No newline at end of file +org.teavm.jso.impl.JSOPlugin \ No newline at end of file diff --git a/teavm-jso-impl/src/test/java/org/teavm/jso/plugin/AstWriterTest.java b/teavm-jso-impl/src/test/java/org/teavm/jso/plugin/AstWriterTest.java index 22b786acd..3ebc273d1 100644 --- a/teavm-jso-impl/src/test/java/org/teavm/jso/plugin/AstWriterTest.java +++ b/teavm-jso-impl/src/test/java/org/teavm/jso/plugin/AstWriterTest.java @@ -25,6 +25,8 @@ import org.mozilla.javascript.Context; import org.mozilla.javascript.ast.AstRoot; import org.teavm.codegen.SourceWriter; import org.teavm.codegen.SourceWriterBuilder; +import org.teavm.jso.impl.AstWriter; +import org.teavm.jso.impl.JSParser; /** *