From 8dada3b28ccfe2d13fbb9e746d111b5bf46dc583 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Tue, 2 Sep 2014 12:11:13 +0400 Subject: [PATCH] Adds support of some methods required by latest html4j. See https://github.com/konsoletyper/teavm/issues/6 --- pom.xml | 2 +- .../teavm/classlib/java/io/TEOFException.java | 34 ++++++++++++++++ .../org/teavm/classlib/java/lang/TClass.java | 8 ++++ .../org/teavm/classlib/java/lang/TThread.java | 4 ++ .../classlib/java/lang/ref/TReference.java | 39 +++++++++++++++++++ .../java/lang/ref/TWeakReference.java | 38 ++++++++++++++++++ .../teavm/html4j/JavaScriptBodyGenerator.java | 2 +- 7 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/io/TEOFException.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ref/TReference.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ref/TWeakReference.java diff --git a/pom.xml b/pom.xml index c5ac77314..2ba3992ec 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ UTF-8 https://oss.sonatype.org/content/repositories/snapshots/ - 0.7.5 + 0.9 9.2.1.v20140609 1.7.7 diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TEOFException.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TEOFException.java new file mode 100644 index 000000000..ccdc2e43c --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TEOFException.java @@ -0,0 +1,34 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.io; + +import org.teavm.classlib.java.lang.TString; + +/** + * + * @author Alexey Andreev + */ +public class TEOFException extends TIOException { + private static final long serialVersionUID = 3045477060413545010L; + + public TEOFException() { + super(); + } + + public TEOFException(TString message) { + super(message); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java index 04d7f76d9..bf2c6ba35 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java @@ -163,4 +163,12 @@ public class TClass extends TObject { @GeneratedBy(ClassNativeGenerator.class) @PluggableDependency(ClassNativeGenerator.class) public native TClass getDeclaringClass(); + + @SuppressWarnings("unchecked") + public TClass asSubclass(TClass clazz) { + if (!clazz.isAssignableFrom(this)) { + throw new TClassCastException(); + } + return (TClass)this; + } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java index 165d25c75..d718e70cc 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java @@ -77,4 +77,8 @@ public class TThread extends TObject implements TRunnable { public long getId() { return 1; } + + public static boolean holdsLock(@SuppressWarnings("unused") TObject obj) { + return true; + } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ref/TReference.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ref/TReference.java new file mode 100644 index 000000000..ba740d223 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ref/TReference.java @@ -0,0 +1,39 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.lang.ref; + +import org.teavm.classlib.java.lang.TObject; + +/** + * + * @author Alexey Andreev + */ +public abstract class TReference extends TObject { + public T get() { + return null; + } + + public void clear() { + } + + public boolean isEnqueued() { + return false; + } + + public boolean enqueue() { + return false; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ref/TWeakReference.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ref/TWeakReference.java new file mode 100644 index 000000000..d91c55dd6 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ref/TWeakReference.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.lang.ref; + +/** + * + * @author Alexey Andreev + */ +public class TWeakReference extends TReference { + private T value; + + public TWeakReference(T value) { + this.value = value; + } + + @Override + public T get() { + return value; + } + + @Override + public void clear() { + value = null; + } +} 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 2ab8c14d2..917acaafc 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java @@ -105,7 +105,7 @@ public class JavaScriptBodyGenerator implements Generator { .append(Renderer.typeToClsString(naming, reader.parameterType(i))).append(")"); } sb.append(")); })("); - sb.append(ident == null ? "null, " : ident); + sb.append(ident == null ? "null" : ident); return sb.toString(); } private MethodReader findMethod(String clsName, MethodDescriptor desc) {