mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Remove some generator in favor of JSO
This commit is contained in:
parent
c1389dec25
commit
2ca32a514b
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<TDouble> {
|
|||
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) {
|
||||
|
|
|
@ -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<TFloat> {
|
|||
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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<TDate> {
|
||||
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<TDate> {
|
|||
|
||||
@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<TDate> {
|
|||
|
||||
@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<TDate> {
|
|||
|
||||
@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<TDate> {
|
|||
|
||||
@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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
167
teavm-jso/src/main/java/org/teavm/jso/core/JSDate.java
Normal file
167
teavm-jso/src/main/java/org/teavm/jso/core/JSDate.java
Normal file
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user