diff --git a/README.md b/README.md index a56f09025..8e7c9ae2b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ TeaVM What is TeaVM? -------------- -TeaVM is an ahead-of-time translator from Java bytecode to JVM. +TeaVM is an ahead-of-time translator from Java bytecode to JavaScript. It can be compared with GWT, however TeaVM does not require source code of your application and all required libraries. You can use TeaVM for building applications for the browser, due to the following features: diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java index 72314d460..9c81a0eb3 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java @@ -693,7 +693,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ } public TAbstractStringBuilder delete(int start, int end) { - if (start > end || start >= length) { + if (start > end || start > length) { throw new TStringIndexOutOfBoundsException(); } if (start == end) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java index 0dc35c53d..4904efa9b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java @@ -80,7 +80,6 @@ public class TObject { public final void wait0(long timeout, int nanos) throws TInterruptedException { } - @SuppressWarnings("unused") @Rename("wait") public final void wait0() throws TInterruptedException { } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractCharClass.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractCharClass.java index 2d47eeadc..eb5fced0f 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractCharClass.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractCharClass.java @@ -432,7 +432,6 @@ abstract class TAbstractCharClass extends TSpecialToken { chCl.lowHighSurrogates.set(0, SURROGATE_CARDINALITY); } chCl.mayContainSupplCodepoints = mayContainSupplCodepoints; - ; return chCl; } } diff --git a/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java b/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java index 2aa07ca1c..df50934c8 100644 --- a/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java +++ b/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java @@ -310,6 +310,13 @@ public class StringBuilderTest { assertEquals('9', sb.charAt(7)); } + @Test + public void deletesNothing() { + StringBuilder sb = new StringBuilder(); + sb.delete(0, 0); + assertEquals(0, sb.length()); + } + @Test public void replacesRangeWithSequenceOfSameLength() { StringBuilder sb = new StringBuilder(); diff --git a/teavm-core/src/main/java/org/teavm/parsing/JarFileResourceProvider.java b/teavm-core/src/main/java/org/teavm/parsing/JarFileResourceProvider.java index da43d073a..e26c34930 100644 --- a/teavm-core/src/main/java/org/teavm/parsing/JarFileResourceProvider.java +++ b/teavm-core/src/main/java/org/teavm/parsing/JarFileResourceProvider.java @@ -52,7 +52,6 @@ public class JarFileResourceProvider implements ResourceProvider { @Override public InputStream openResource(String name) { try { - @SuppressWarnings("resource") JarInputStream input = new JarInputStream(new FileInputStream(file)); while (true) { ZipEntry entry = input.getNextEntry(); diff --git a/teavm-core/src/main/java/org/teavm/tooling/DirectorySourceFileProvider.java b/teavm-core/src/main/java/org/teavm/tooling/DirectorySourceFileProvider.java index 51cdd74f2..21841bed8 100644 --- a/teavm-core/src/main/java/org/teavm/tooling/DirectorySourceFileProvider.java +++ b/teavm-core/src/main/java/org/teavm/tooling/DirectorySourceFileProvider.java @@ -40,7 +40,6 @@ public class DirectorySourceFileProvider implements SourceFileProvider { } @Override - @SuppressWarnings("resource") public InputStream openSourceFile(String fullPath) throws IOException { File file = new File(baseDirectory, fullPath); return file.exists() ? new FileInputStream(file) : null; diff --git a/teavm-eclipse/teavm-eclipse-core-plugin/META-INF/MANIFEST.MF b/teavm-eclipse/teavm-eclipse-core-plugin/META-INF/MANIFEST.MF index dba35773e..01d49b2b0 100644 --- a/teavm-eclipse/teavm-eclipse-core-plugin/META-INF/MANIFEST.MF +++ b/teavm-eclipse/teavm-eclipse-core-plugin/META-INF/MANIFEST.MF @@ -6,10 +6,7 @@ Bundle-Version: 0.3.0.qualifer Bundle-Vendor: Alexey Andreev Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ClassPath: ., - lib/asm-5.0.1.jar, - lib/asm-commons-5.0.1.jar, - lib/asm-debug-all-4.2.jar, - lib/asm-tree-5.0.1.jar, + lib/asm-debug-all-4.0.3.jar, lib/cdi-api-1.2.jar, lib/commons-io-2.4.jar, lib/jackson-core-asl-1.9.13.jar, diff --git a/teavm-eclipse/teavm-eclipse-core-plugin/build.properties b/teavm-eclipse/teavm-eclipse-core-plugin/build.properties index 253bf8f08..eb59b3b09 100644 --- a/teavm-eclipse/teavm-eclipse-core-plugin/build.properties +++ b/teavm-eclipse/teavm-eclipse-core-plugin/build.properties @@ -3,10 +3,7 @@ output.. = target/ bin.includes = META-INF/,\ .,\ lib/,\ - lib/asm-5.0.1.jar,\ - lib/asm-commons-5.0.1.jar,\ - lib/asm-debug-all-4.2.jar,\ - lib/asm-tree-5.0.1.jar,\ + lib/asm-debug-all-5.0.3.jar,\ lib/cdi-api-1.2.jar,\ lib/commons-io-2.4.jar,\ lib/jackson-core-asl-1.9.13.jar,\ diff --git a/teavm-eclipse/teavm-eclipse-core-plugin/dep-pom.xml b/teavm-eclipse/teavm-eclipse-core-plugin/dep-pom.xml index 7d15d8482..cf2e3b38d 100644 --- a/teavm-eclipse/teavm-eclipse-core-plugin/dep-pom.xml +++ b/teavm-eclipse/teavm-eclipse-core-plugin/dep-pom.xml @@ -58,6 +58,16 @@ org.eclipse.jetty.websocket javax-websocket-server-impl ${jetty.version} + + + org.ow2.asm + asm + + + org.ow2.asm + asm-common + + ch.qos.logback diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java index cfb3076c5..220d4ed0f 100644 --- a/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java @@ -1,8 +1,6 @@ package org.teavm.eclipse.m2e; import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; import java.util.*; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecution; diff --git a/teavm-html4j/pom.xml b/teavm-html4j/pom.xml index 64f1472d9..78f588056 100644 --- a/teavm-html4j/pom.xml +++ b/teavm-html4j/pom.xml @@ -101,6 +101,9 @@ true true true + + + diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java index 50fb1e828..12e1222b0 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java @@ -106,9 +106,10 @@ public class JavaScriptBodyGenerator implements Generator { if (i > 0) { sb.append(", "); } + ValueType paramType = simplifyParamType(reader.parameterType(i)); sb.append(naming.getFullNameFor(JavaScriptConvGenerator.fromJsMethod)).append("(p").append(i) .append(", ") - .append(Renderer.typeToClsString(naming, reader.parameterType(i))).append(")"); + .append(Renderer.typeToClsString(naming, paramType)).append(")"); } sb.append(")); })("); if (ident != null) { @@ -116,6 +117,16 @@ public class JavaScriptBodyGenerator implements Generator { } return sb.toString(); } + private ValueType simplifyParamType(ValueType type) { + if (type instanceof ValueType.Object) { + return ValueType.object("java.lang.Object"); + } else if (type instanceof ValueType.Array) { + ValueType.Array array = (ValueType.Array)type; + return ValueType.arrayOf(simplifyParamType(array.getItemType())); + } else { + return type; + } + } private MethodReader findMethod(String clsName, MethodDescriptor desc) { while (clsName != null) { ClassReader cls = classSource.get(clsName); diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptResourceInterceptor.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptResourceInterceptor.java index 561bba643..ad4bd0f32 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptResourceInterceptor.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptResourceInterceptor.java @@ -49,7 +49,6 @@ public class JavaScriptResourceInterceptor extends AbstractRendererListener { throw new RenderingException("Error processing JavaScriptResource annotation on class " + className + ". Resource not found: " + resourceName); } - @SuppressWarnings("resource") StringWriter writer = new StringWriter(); IOUtils.copy(input, writer); writer.close(); diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/Callback.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/Callback.java new file mode 100644 index 000000000..0b58916e2 --- /dev/null +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/Callback.java @@ -0,0 +1,11 @@ +package org.teavm.html4j.test; + +import java.util.Calendar; + +/** + * + * @author Alexey Andreev + */ +public interface Callback { + void exec(Calendar input); +} diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java index a3dce3b5d..6374dd80f 100644 --- a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java @@ -16,6 +16,7 @@ package org.teavm.html4j.test; import static org.junit.Assert.assertEquals; +import java.util.Calendar; import net.java.html.js.JavaScriptBody; import org.junit.Test; @@ -60,6 +61,18 @@ public class JavaScriptBodyTest { assertEquals(23, invokeStaticCallback(new AImpl())); } + @Test + public void unusedArgumentIgnored() { + final int[] array = new int[1]; + invokeCallback(new Callback() { + @Override + public void exec(Calendar input) { + array[0] = 23; + } + }); + assertEquals(23, array[0]); + } + private static class AImpl implements A { @Override public int foo() { return 23; @@ -95,4 +108,8 @@ public class JavaScriptBodyTest { "@org.teavm.html4j.test.JavaScriptBodyTest::staticCallback(" + "Lorg/teavm/html4j/test/A;)(a)", javacall = true) private native int invokeStaticCallback(A a); + + @JavaScriptBody(args = "callback", body = "callback.@org.teavm.html4j.test.Callback::exec(" + + "Ljava/util/Calendar;)(null)", javacall = true) + private native void invokeCallback(Callback callback); } diff --git a/teavm-jso/pom.xml b/teavm-jso/pom.xml index 5e7e7a986..a42c91397 100644 --- a/teavm-jso/pom.xml +++ b/teavm-jso/pom.xml @@ -34,10 +34,51 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs ${project.version} true + + junit + junit + test + + + org.teavm + teavm-maven-plugin + ${project.version} + + + org.teavm + teavm-classlib + ${project.version} + + + + + generate-javascript-tests + + build-test-javascript + + process-test-classes + + false + + en, en_US, en_GB, ru, ru_RU + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ** + + + org.apache.maven.plugins maven-checkstyle-plugin diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java b/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java index 2e049a44c..9720fb7a6 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java @@ -74,10 +74,10 @@ public class JSNativeGenerator implements Injector, DependencyPlugin { writer.append(')'); break; case "instantiate": - writer.append("(new "); + writer.append("(new ("); context.writeExpr(context.getArgument(0)); renderProperty(context.getArgument(1), context); - writer.append('('); + writer.append(")("); for (int i = 2; i < context.argumentCount(); ++i) { if (i > 2) { writer.append(',').ws(); diff --git a/teavm-jso/src/test/java/org/teavm/jso/test/JSOTest.java b/teavm-jso/src/test/java/org/teavm/jso/test/JSOTest.java new file mode 100644 index 000000000..7627d393a --- /dev/null +++ b/teavm-jso/src/test/java/org/teavm/jso/test/JSOTest.java @@ -0,0 +1,21 @@ +package org.teavm.jso.test; + +import static org.junit.Assert.*; +import org.junit.Test; +import org.teavm.jso.JS; + +/** + * + * @author Alexey Andreev + */ +public class JSOTest { + @Test + public void complexConstructorParenthesized() { + RegExp regexp = getWindow().createRegExp("."); + assertEquals(".", regexp.getSource()); + } + + private static Window getWindow() { + return (Window)JS.getGlobal(); + } +} diff --git a/teavm-jso/src/test/java/org/teavm/jso/test/RegExp.java b/teavm-jso/src/test/java/org/teavm/jso/test/RegExp.java new file mode 100644 index 000000000..4ce204f9e --- /dev/null +++ b/teavm-jso/src/test/java/org/teavm/jso/test/RegExp.java @@ -0,0 +1,13 @@ +package org.teavm.jso.test; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface RegExp extends JSObject { + @JSProperty + String getSource(); +} diff --git a/teavm-jso/src/test/java/org/teavm/jso/test/Window.java b/teavm-jso/src/test/java/org/teavm/jso/test/Window.java new file mode 100644 index 000000000..04d3bb6a1 --- /dev/null +++ b/teavm-jso/src/test/java/org/teavm/jso/test/Window.java @@ -0,0 +1,13 @@ +package org.teavm.jso.test; + +import org.teavm.jso.JSConstructor; +import org.teavm.jso.JSObject; + +/** + * + * @author Alexey Andreev + */ +public interface Window extends JSObject { + @JSConstructor("RegExp") + RegExp createRegExp(String regex); +} diff --git a/teavm-samples/teavm-samples-benchmark/pom.xml b/teavm-samples/teavm-samples-benchmark/pom.xml index 4afc765b3..711bcca06 100644 --- a/teavm-samples/teavm-samples-benchmark/pom.xml +++ b/teavm-samples/teavm-samples-benchmark/pom.xml @@ -58,7 +58,7 @@ com.google.gwt gwt-user - 2.6.1 + 2.7.0 provided @@ -100,7 +100,7 @@ org.codehaus.mojo gwt-maven-plugin - 2.6.1 + 2.7.0