Merge branch 'master' into diagnostics

This commit is contained in:
Alexey Andreev 2014-12-11 18:54:25 +04:00
commit 316850bbb5
22 changed files with 156 additions and 22 deletions

View File

@ -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:

View File

@ -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) {

View File

@ -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 {
}

View File

@ -432,7 +432,6 @@ abstract class TAbstractCharClass extends TSpecialToken {
chCl.lowHighSurrogates.set(0, SURROGATE_CARDINALITY);
}
chCl.mayContainSupplCodepoints = mayContainSupplCodepoints;
;
return chCl;
}
}

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -6,10 +6,7 @@ Bundle-Version: 0.3.0.qualifer
Bundle-Vendor: Alexey Andreev <konsoletyper@gmail.com>
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,

View File

@ -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,\

View File

@ -58,6 +58,16 @@
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>${jetty.version}</version>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>

View File

@ -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;

View File

@ -101,6 +101,9 @@
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
<sourceFilesCopied>true</sourceFilesCopied>
<additionalScripts>
</additionalScripts>
</configuration>
</execution>
</executions>

View File

@ -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);

View File

@ -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();

View File

@ -0,0 +1,11 @@
package org.teavm.html4j.test;
import java.util.Calendar;
/**
*
* @author Alexey Andreev
*/
public interface Callback {
void exec(Calendar input);
}

View File

@ -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);
}

View File

@ -34,10 +34,51 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>${project.version}</version>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-javascript-tests</id>
<goals>
<goal>build-test-javascript</goal>
</goals>
<phase>process-test-classes</phase>
<configuration>
<minifying>false</minifying>
<properties>
<java.util.Locale.available>en, en_US, en_GB, ru, ru_RU</java.util.Locale.available>
</properties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -58,7 +58,7 @@
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.6.1</version>
<version>2.7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
@ -100,7 +100,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.6.1</version>
<version>2.7.0</version>
<executions>
<execution>
<goals>