From 2ca32a514b64cd740ad7ba91ed3012668aca1993 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 28 Sep 2015 00:24:10 +0300 Subject: [PATCH] Remove some generator in favor of JSO --- .../java/lang/DoubleNativeGenerator.java | 61 ------- .../java/lang/FloatNativeGenerator.java | 61 ------- .../org/teavm/classlib/java/lang/TDouble.java | 9 +- .../org/teavm/classlib/java/lang/TFloat.java | 8 +- .../java/util/DateNativeGenerator.java | 127 ------------- .../java/util/RandomNativeGenerator.java | 33 ---- .../org/teavm/classlib/java/util/TDate.java | 123 ++++--------- .../org/teavm/classlib/java/util/TRandom.java | 4 +- .../util/logging/LoggerNativeGenerator.java | 36 ---- .../classlib/java/util/logging/TLogger.java | 29 ++- .../main/java/org/teavm/jso/core/JSDate.java | 167 ++++++++++++++++++ 11 files changed, 231 insertions(+), 427 deletions(-) delete mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/lang/DoubleNativeGenerator.java delete mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/lang/FloatNativeGenerator.java delete mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/DateNativeGenerator.java delete mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/RandomNativeGenerator.java delete mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/logging/LoggerNativeGenerator.java create mode 100644 teavm-jso/src/main/java/org/teavm/jso/core/JSDate.java diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/DoubleNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/DoubleNativeGenerator.java deleted file mode 100644 index db26c4338..000000000 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/DoubleNativeGenerator.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2013 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; - -import java.io.IOException; -import org.teavm.codegen.SourceWriter; -import org.teavm.javascript.spi.Generator; -import org.teavm.javascript.spi.GeneratorContext; -import org.teavm.javascript.spi.Injector; -import org.teavm.javascript.spi.InjectorContext; -import org.teavm.model.MethodReference; - -/** - * - * @author Alexey Andreev - */ -public class DoubleNativeGenerator implements Generator, Injector { - @Override - public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { - switch (methodRef.getName()) { - case "isNaN": - generateIsNaN(context, writer); - break; - case "isInfinite": - generateIsInfinite(context, writer); - break; - } - } - - @Override - public void generate(InjectorContext context, MethodReference methodRef) throws IOException { - switch (methodRef.getName()) { - case "getNaN": - context.getWriter().append("NaN"); - break; - } - } - - private void generateIsNaN(GeneratorContext context, SourceWriter writer) throws IOException { - writer.append("return (isNaN(").append(context.getParameterName(1)).append(")").ws().append("?") - .ws().append("1").ws().append(":").ws().append("0").ws().append(");").softNewLine(); - } - - private void generateIsInfinite(GeneratorContext context, SourceWriter writer) throws IOException { - writer.append("return (isFinite(").append(context.getParameterName(1)).append(")").ws().append("?") - .ws().append("0").ws().append(":").ws().append("1").append(");").softNewLine(); - } -} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/FloatNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/FloatNativeGenerator.java deleted file mode 100644 index 1aca3eb1c..000000000 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/FloatNativeGenerator.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2013 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; - -import java.io.IOException; -import org.teavm.codegen.SourceWriter; -import org.teavm.javascript.spi.Generator; -import org.teavm.javascript.spi.GeneratorContext; -import org.teavm.javascript.spi.Injector; -import org.teavm.javascript.spi.InjectorContext; -import org.teavm.model.MethodReference; - -/** - * - * @author Alexey Andreev - */ -public class FloatNativeGenerator implements Generator, Injector { - @Override - public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { - switch (methodRef.getName()) { - case "isNaN": - generateIsNaN(context, writer); - break; - case "isInfinite": - generateIsInfinite(context, writer); - break; - } - } - - @Override - public void generate(InjectorContext context, MethodReference methodRef) throws IOException { - switch (methodRef.getName()) { - case "getNaN": - context.getWriter().append("NaN"); - break; - } - } - - private void generateIsNaN(GeneratorContext context, SourceWriter writer) throws IOException { - writer.append("return (isNaN(").append(context.getParameterName(1)).append(")").ws().append("?") - .ws().append("1").ws().append(":").ws().append("0").ws().append(");").softNewLine(); - } - - private void generateIsInfinite(GeneratorContext context, SourceWriter writer) throws IOException { - writer.append("return (isFinite(").append(context.getParameterName(1)).append(")").ws().append("?") - .ws().append("0").ws().append(":").ws().append("1").append(");").softNewLine(); - } -} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java index 00a822924..b4cc0ebce 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java @@ -15,8 +15,7 @@ */ package org.teavm.classlib.java.lang; -import org.teavm.javascript.spi.GeneratedBy; -import org.teavm.javascript.spi.InjectedBy; +import org.teavm.jso.JSBody; /** * @@ -224,13 +223,13 @@ public class TDouble extends TNumber implements TComparable { return isInfinite(value); } - @GeneratedBy(DoubleNativeGenerator.class) + @JSBody(params = "v", script = "return isNaN(v);") public static native boolean isNaN(double v); - @InjectedBy(DoubleNativeGenerator.class) + @JSBody(params = {}, script = "return NaN;") private static native double getNaN(); - @GeneratedBy(DoubleNativeGenerator.class) + @JSBody(params = "v", script = "return !isFinite(v);") public static native boolean isInfinite(double v); public static long doubleToRawLongBits(double value) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java index 571c66c77..c16e38eec 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java @@ -15,7 +15,7 @@ */ package org.teavm.classlib.java.lang; -import org.teavm.javascript.spi.GeneratedBy; +import org.teavm.jso.JSBody; /** * @@ -92,13 +92,13 @@ public class TFloat extends TNumber implements TComparable { return floatToIntBits(value); } - @GeneratedBy(FloatNativeGenerator.class) + @JSBody(params = "v", script = "return isNaN(v);") public static native boolean isNaN(float v); - @GeneratedBy(FloatNativeGenerator.class) + @JSBody(params = "v", script = "return !isFinite(v);") public static native boolean isInfinite(float v); - @GeneratedBy(FloatNativeGenerator.class) + @JSBody(params = {}, script = "return NaN;") private static native float getNaN(); public static float parseFloat(TString string) throws TNumberFormatException { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/DateNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/DateNativeGenerator.java deleted file mode 100644 index b8d5e4e7b..000000000 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/DateNativeGenerator.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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.util; - -import java.io.IOException; -import org.teavm.codegen.SourceWriter; -import org.teavm.dependency.DependencyAgent; -import org.teavm.dependency.DependencyPlugin; -import org.teavm.dependency.MethodDependency; -import org.teavm.javascript.spi.Generator; -import org.teavm.javascript.spi.GeneratorContext; -import org.teavm.model.CallLocation; -import org.teavm.model.MethodReference; - -/** - * - * @author Alexey Andreev - */ -public class DateNativeGenerator implements Generator, DependencyPlugin { - @Override - public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { - switch (methodRef.getName()) { - case "buildNumericTime": - generateBuildNumericTime(context, writer); - break; - case "parseNumericTime": - generateParseNumericTime(context, writer); - break; - case "buildNumericUTC": - generateBuildNumericUTC(context, writer); - break; - case "getFullYear": - case "getMonth": - case "getDate": - case "getDay": - case "getHours": - case "getMinutes": - case "getSeconds": - case "getTimezoneOffset": - generateGetMethod(context, writer, methodRef.getName()); - break; - case "setFullYear": - case "setMonth": - case "setDate": - case "setHours": - case "setMinutes": - case "setSeconds": - generateSetMethod(context, writer, methodRef.getName()); - break; - case "toString": - case "toGMTString": - generateToString(context, writer, methodRef.getName()); - break; - case "toLocaleFormat": - generateToLocaleFormat(context, writer); - break; - } - } - - @Override - public void methodAchieved(DependencyAgent agent, MethodDependency method, CallLocation location) { - switch (method.getMethod().getName()) { - case "toString": - case "toLocaleFormat": - case "toGMTString": - method.getResult().propagate(agent.getType("java.lang.String")); - break; - } - } - - private void generateBuildNumericTime(GeneratorContext context, SourceWriter writer) throws IOException { - writer.append("return new Date(").append(context.getParameterName(1)); - for (int i = 2; i <= 6; ++i) { - writer.append(',').ws().append(context.getParameterName(i)); - } - writer.append(").getTime();").softNewLine(); - } - - private void generateParseNumericTime(GeneratorContext context, SourceWriter writer) throws IOException { - writer.append("return Date.parse(").append(context.getParameterName(1)).append(");").softNewLine(); - } - - private void generateBuildNumericUTC(GeneratorContext context, SourceWriter writer) throws IOException { - writer.append("return Date.UTC(").append(context.getParameterName(1)); - for (int i = 2; i <= 6; ++i) { - writer.append(',').ws().append(context.getParameterName(i)); - } - writer.append(").getTime();").softNewLine(); - } - - private void generateGetMethod(GeneratorContext context, SourceWriter writer, String methodName) - throws IOException { - writer.append("return new Date(").append(context.getParameterName(1)).append(").").append(methodName) - .append("();").softNewLine(); - } - - private void generateSetMethod(GeneratorContext context, SourceWriter writer, String methodName) - throws IOException { - writer.append("var date = new Date(").append(context.getParameterName(1)).append(");").softNewLine(); - writer.append("return date.").append(methodName).append("(").append(context.getParameterName(2)).append(");") - .softNewLine(); - } - - private void generateToString(GeneratorContext context, SourceWriter writer, String method) throws IOException { - writer.append("return $rt_str(new Date(").append(context.getParameterName(1)).append(").").append(method) - .append("());").softNewLine(); - } - - private void generateToLocaleFormat(GeneratorContext context, SourceWriter writer) throws IOException { - writer.append("return $rt_str(new Date(").append(context.getParameterName(1)) - .append(").toLocaleFormat($rt_ustr(").append(context.getParameterName(2)).append(")));") - .softNewLine(); - } -} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/RandomNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/RandomNativeGenerator.java deleted file mode 100644 index b5942811b..000000000 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/RandomNativeGenerator.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.util; - -import java.io.IOException; -import org.teavm.codegen.SourceWriter; -import org.teavm.javascript.spi.Generator; -import org.teavm.javascript.spi.GeneratorContext; -import org.teavm.model.MethodReference; - -/** - * - * @author Alexey Andreev - */ -public class RandomNativeGenerator implements Generator { - @Override - public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { - writer.append("return Math.random();").softNewLine(); - } -} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TDate.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TDate.java index 50d32244b..528a51da5 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TDate.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TDate.java @@ -18,8 +18,7 @@ package org.teavm.classlib.java.util; import java.util.TimeZone; import org.teavm.classlib.java.lang.TComparable; import org.teavm.classlib.java.lang.TSystem; -import org.teavm.dependency.PluggableDependency; -import org.teavm.javascript.spi.GeneratedBy; +import org.teavm.jso.core.JSDate; /** * @@ -28,9 +27,6 @@ import org.teavm.javascript.spi.GeneratedBy; public class TDate implements TComparable { private long value; - @GeneratedBy(DateNativeGenerator.class) - private static native void initNativeDate(); - public TDate() { value = TSystem.currentTimeMillis(); } @@ -51,8 +47,8 @@ public class TDate implements TComparable { @Deprecated public TDate(int year, int month, int date, int hrs, int min, int sec) { - this((long) buildNumericTime(year, month, date, hrs, min, sec)); - setFullYear(value, year + 1900); + this((long) JSDate.create(year, month, date, hrs, min, sec).getTime()); + setYear(year); } public TDate(String s) { @@ -66,12 +62,12 @@ public class TDate implements TComparable { @Deprecated public static long UTC(int year, int month, int date, int hrs, int min, int sec) { - return (long) buildNumericUTC(year, month, date, hrs, min, sec); + return (long) JSDate.UTC(year, month, date, hrs, min, sec); } @Deprecated public static long parse(String s) { - double value = parseNumericTime(s); + double value = JSDate.parse(s).getTime(); if (Double.isNaN(value)) { throw new IllegalArgumentException("Can't parse date: " + s); } @@ -80,67 +76,79 @@ public class TDate implements TComparable { @Deprecated public int getYear() { - return getFullYear(value) - 1900; + return JSDate.create(value).getFullYear() - 1900; } @Deprecated public void setYear(int year) { - this.value = (long) setFullYear(value, year + 1900); + JSDate date = JSDate.create(value); + date.setFullYear(year + 1900); + this.value = (long) date.getTime(); } @Deprecated public int getMonth() { - return getMonth(value); + return JSDate.create(value).getMonth(); } @Deprecated public void setMonth(int month) { - this.value = (long) setMonth(value, month); + JSDate date = JSDate.create(value); + date.setMonth(month); + this.value = (long) date.getTime(); } @Deprecated public int getDate() { - return getDate(value); + return JSDate.create(value).getDate(); } @Deprecated public void setDate(int date) { - this.value = (long) setDate(value, date); + JSDate d = JSDate.create(value); + d.setDate(date); + this.value = (long) d.getTime(); } @Deprecated public int getDay() { - return getDay(value); + return JSDate.create(value).getDay(); } @Deprecated public int getHours() { - return getHours(value); + return JSDate.create(value).getHours(); } @Deprecated public void setHours(int hours) { - this.value = (long) setHours(value, hours); + JSDate date = JSDate.create(value); + date.setHours(hours); + this.value = (long) date.getTime(); } @Deprecated public int getMinutes() { - return getMinutes(value); + return JSDate.create(value).getMinutes(); } @Deprecated public void setMinutes(int minutes) { - this.value = (long) setMinutes(value, minutes); + JSDate date = JSDate.create(value); + date.setMinutes(minutes); + this.value = (long) date.getTime(); } @Deprecated public int getSeconds() { - return getSeconds(value); + return JSDate.create(value).getSeconds(); } @Deprecated public void setSeconds(int seconds) { - this.value = (long) setSeconds(value, seconds); + JSDate date = JSDate.create(value); + date.setSeconds(seconds); + this.value = (long) date.getTime(); } public long getTime() { @@ -180,86 +188,21 @@ public class TDate implements TComparable { @Override public String toString() { - return toString(value); + return JSDate.create(value).stringValue(); } @Deprecated public String toLocaleString() { - return toLocaleFormat(value, "%c"); + return JSDate.create(value).toLocaleFormat("%c"); } @Deprecated public String toGMTString() { - return toGMTString(value); + return JSDate.create(value).toUTCString(); } @Deprecated public int getTimezoneOffset() { - //return getTimezoneOffset(value); return -TimeZone.getDefault().getOffset(value) / (1000 * 60); } - - @GeneratedBy(DateNativeGenerator.class) - private static native int getFullYear(double date); - - @GeneratedBy(DateNativeGenerator.class) - private static native double setFullYear(double date, int year); - - @GeneratedBy(DateNativeGenerator.class) - private static native int getMonth(double date); - - @GeneratedBy(DateNativeGenerator.class) - private static native double setMonth(double date, int month); - - @GeneratedBy(DateNativeGenerator.class) - private static native int getDate(double date); - - @GeneratedBy(DateNativeGenerator.class) - private static native double setDate(double dateVal, int date); - - @GeneratedBy(DateNativeGenerator.class) - private static native int getDay(double date); - - @GeneratedBy(DateNativeGenerator.class) - private static native int getHours(double date); - - @GeneratedBy(DateNativeGenerator.class) - private static native double setHours(double date, int hours); - - @GeneratedBy(DateNativeGenerator.class) - private static native int getMinutes(double date); - - @GeneratedBy(DateNativeGenerator.class) - private static native double setMinutes(double date, int minutes); - - @GeneratedBy(DateNativeGenerator.class) - private static native int getSeconds(double date); - - @GeneratedBy(DateNativeGenerator.class) - private static native double setSeconds(double date, int seconds); - - @GeneratedBy(DateNativeGenerator.class) - private static native double buildNumericTime(int year, int month, int date, int hrs, int min, int sec); - - @GeneratedBy(DateNativeGenerator.class) - private static native double parseNumericTime(String dateString); - - @GeneratedBy(DateNativeGenerator.class) - private static native double buildNumericUTC(int year, int month, int date, int hrs, int min, int sec); - - @GeneratedBy(DateNativeGenerator.class) - @PluggableDependency(DateNativeGenerator.class) - private static native String toString(double value); - - @GeneratedBy(DateNativeGenerator.class) - @PluggableDependency(DateNativeGenerator.class) - private static native String toLocaleFormat(double value, String format); - - @GeneratedBy(DateNativeGenerator.class) - @PluggableDependency(DateNativeGenerator.class) - private static native String toGMTString(double value); - - @GeneratedBy(DateNativeGenerator.class) - @PluggableDependency(DateNativeGenerator.class) - static native int getTimezoneOffset(double value); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java index e0a59de83..0c1c56742 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java @@ -18,7 +18,7 @@ package org.teavm.classlib.java.util; import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.lang.TMath; import org.teavm.classlib.java.lang.TObject; -import org.teavm.javascript.spi.GeneratedBy; +import org.teavm.jso.JSBody; /** * @@ -68,6 +68,6 @@ public class TRandom extends TObject implements TSerializable { return random(); } - @GeneratedBy(RandomNativeGenerator.class) + @JSBody(params = {}, script = "return Math.random();") private static native double random(); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/logging/LoggerNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/logging/LoggerNativeGenerator.java deleted file mode 100644 index 83ebbae5d..000000000 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/logging/LoggerNativeGenerator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.util.logging; - -import java.io.IOException; -import org.teavm.codegen.SourceWriter; -import org.teavm.javascript.spi.Generator; -import org.teavm.javascript.spi.GeneratorContext; -import org.teavm.model.MethodReference; - -/** - * - * @author Alexey Andreev - */ -public class LoggerNativeGenerator implements Generator { - @Override - public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { - writer.append("if (console) {").indent().softNewLine(); - writer.append("console.").append(methodRef.getName()).append("($rt_ustr(").append(context.getParameterName(1)) - .append("));").softNewLine(); - writer.outdent().append("}").softNewLine(); - } -} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java index bf33555f2..2c2c4e6a4 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java @@ -15,10 +15,14 @@ */ package org.teavm.classlib.java.util.logging; -import org.teavm.classlib.java.lang.*; +import org.teavm.classlib.java.lang.TInteger; +import org.teavm.classlib.java.lang.TObject; +import org.teavm.classlib.java.lang.TString; +import org.teavm.classlib.java.lang.TStringBuilder; +import org.teavm.classlib.java.lang.TThrowable; import org.teavm.classlib.java.util.THashMap; import org.teavm.classlib.java.util.TMap; -import org.teavm.javascript.spi.GeneratedBy; +import org.teavm.jso.JSBody; /** * @@ -170,12 +174,21 @@ public class TLogger { this.parent = parent; } - @GeneratedBy(LoggerNativeGenerator.class) - public native void info(TString message); + @JSBody(params = "message", script = "" + + "if (console) {" + + "console.info(message);" + + "}") + public static native void info(TString message); - @GeneratedBy(LoggerNativeGenerator.class) - private native void warn(TString message); + @JSBody(params = "message", script = "" + + "if (console) {" + + "console.warn(message);" + + "}") + private static native void warn(TString message); - @GeneratedBy(LoggerNativeGenerator.class) - private native void error(TString message); + @JSBody(params = "message", script = "" + + "if (console) {" + + "console.error(message);" + + "}") + private static native void error(TString message); } diff --git a/teavm-jso/src/main/java/org/teavm/jso/core/JSDate.java b/teavm-jso/src/main/java/org/teavm/jso/core/JSDate.java new file mode 100644 index 000000000..db4b656d9 --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/core/JSDate.java @@ -0,0 +1,167 @@ +/* + * Copyright 2015 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.jso.core; + +import org.teavm.jso.JSBody; +import org.teavm.jso.JSMethod; +import org.teavm.jso.JSObject; + +/** + * + * @author Alexey Andreev + */ +public abstract class JSDate implements JSObject { + @JSBody(params = {}, script = "return new Date();") + public static native JSDate create(); + + @JSBody(params = "millis", script = "return new Date(millis);") + public static native JSDate create(double millis); + + @JSBody(params = { "year", "month" }, script = "return new Date(year, month);") + public static native JSDate create(int year, int month); + + @JSBody(params = { "year", "month", "day" }, script = "return new Date(year, month, day);") + public static native JSDate create(int year, int month, int day); + + @JSBody(params = { "year", "month", "day", "hour" }, script = "return new Date(year, month, day, hour);") + public static native JSDate create(int year, int month, int day, int hour); + + @JSBody(params = { "year", "month", "day", "hour", "minute" }, + script = "return new Date(year, month, day, hour, minute);") + public static native JSDate create(int year, int month, int day, int hour, int minute); + + @JSBody(params = { "year", "month", "day", "hour", "minute", "second" }, + script = "return new Date(year, month, day, hour, minute, second);") + public static native JSDate create(int year, int month, int day, int hour, int minute, int second); + + @JSBody(params = { "year", "month", "day", "hour", "minute", "second", "millisecond" }, + script = "return new Date(year, month, day, hour, minute, second, millisecond);") + public static native JSDate create(int year, int month, int day, int hour, int minute, int second, int millisecond); + + @JSBody(params = {}, script = "return Date.now();") + public static native double now(); + + @JSBody(params = "stringValue", script = "return Date.parse(stringValue);") + public static native JSDate parse(String stringValue); + + @JSBody(params = { "year", "month" }, script = "return Date.UTC(year, month);") + public static native double UTC(int year, int month); + + @JSBody(params = { "year", "month", "day" }, script = "return Date.UTC(year, month, day);") + public static native double UTC(int year, int month, int day); + + @JSBody(params = { "year", "month", "day", "hour" }, script = "return Date.UTC(year, month, day, hour);") + public static native double UTC(int year, int month, int day, int hour); + + @JSBody(params = { "year", "month", "day", "hour", "minute" }, + script = "return Date.UTC(year, month, day, hour, minute);") + public static native double UTC(int year, int month, int day, int hour, int minute); + + @JSBody(params = { "year", "month", "day", "hour", "minute", "second" }, + script = "return Date.UTC(year, month, day, hour, minute, second);") + public static native double UTC(int year, int month, int day, int hour, int minute, int second); + + @JSBody(params = { "year", "month", "day", "hour", "minute", "second", "millisecond" }, + script = "return Date.UTC(year, month, day, hour, minute, second, millisecond);") + public static native double UTC(int year, int month, int day, int hour, int minute, int second, int millisecond); + + public abstract int getDate(); + + public abstract int getDay(); + + public abstract int getFullYear(); + + public abstract int getHours(); + + public abstract int getMilliseconds(); + + public abstract int getMinutes(); + + public abstract int getMonth(); + + public abstract int getSeconds(); + + public abstract double getTime(); + + public abstract int getTimezoneOffset(); + + public abstract int getUTCDate(); + + public abstract int getUTCDay(); + + public abstract int getUTCFullYear(); + + public abstract int getUTCHours(); + + public abstract int getUTCMilliseconds(); + + public abstract int getUTCMinutes(); + + public abstract int getUTCMonth(); + + public abstract int getUTCSeconds(); + + public abstract void setDate(int date); + + public abstract void setFullYear(int fullYear); + + public abstract void setHours(int hours); + + public abstract void setMilliseconds(int milliseconds); + + public abstract void setMinutes(int minutes); + + public abstract void setMonth(int month); + + public abstract void setSeconds(int seconds); + + public abstract void setTime(double time); + + public abstract void setUTCDate(int date); + + public abstract void setUTCFullYear(int fullYear); + + public abstract void setUTCHours(int hours); + + public abstract void setUTCMilliseconds(int milliseconds); + + public abstract void setUTCMinutes(int minutes); + + public abstract void setUTCMonth(int month); + + public abstract void setUTCSeconds(int seconds); + + public abstract String toDateString(); + + public abstract String toISOString(); + + public abstract String toJSON(); + + public abstract String toLocaleDateString(); + + public abstract String toLocaleString(); + + public abstract String toLocaleTimeString(); + + @JSMethod("toString") + public abstract String stringValue(); + + public abstract String toTimeString(); + + public abstract String toUTCString(); + + public abstract String toLocaleFormat(String format); +}