java.lang.System Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jtransc-rt Show documentation
Show all versions of jtransc-rt Show documentation
JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.
/*
* Copyright 2016 Carlos Ballesteros Velasco
*
* 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 java.lang;
import com.jtransc.JTranscSystem;
import com.jtransc.JTranscSystemProperties;
import com.jtransc.JTranscVersion;
import com.jtransc.annotation.JTranscMethodBody;
import com.jtransc.annotation.haxe.HaxeMethodBody;
import com.jtransc.annotation.haxe.HaxeMethodBodyPre;
import com.jtransc.io.JTranscConsolePrintStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@SuppressWarnings("ManualArrayCopy")
public class System {
static public final InputStream in = new InputStream() {
@Override
public int read() throws IOException {
throw new Error("Not implemented System.in.read()!");
}
};
static public final PrintStream out = new JTranscConsolePrintStream(false);
static public final PrintStream err = new JTranscConsolePrintStream(true);
native public static void setIn(InputStream in);
native public static void setOut(PrintStream out);
native public static void setErr(PrintStream err);
@JTranscMethodBody(target = "d", value = "return N.currentTimeMillis();")
public static long currentTimeMillis() {
return (long) JTranscSystem.fastTime();
}
@JTranscMethodBody(target = "d", value = "return N.nanoTime();")
public static long nanoTime() {
return JTranscSystem.nanoTime();
}
@HaxeMethodBody("N.arraycopy(p0, p1, p2, p3, p4);")
@JTranscMethodBody(target = "js", value = "N.arraycopy(p0, p1, p2, p3, p4);")
@JTranscMethodBody(target = "cpp", value = "JA_0::copy((JA_0*)p0, p1, (JA_0*)p2, p3, p4);")
@JTranscMethodBody(target = "d", value = "N.arraycopy(p0, p1, p2, p3, p4);")
@JTranscMethodBody(target = "cs", value = "N.arraycopy(p0, p1, p2, p3, p4);")
@JTranscMethodBody(target = "as3", value = "N.arraycopy(p0, p1, p2, p3, p4);")
@JTranscMethodBody(target = "dart", value = "N.arraycopy(p0, p1, p2, p3, p4);")
@JTranscMethodBody(target = "php", value = "N::arraycopy($p0, $p1, $p2, $p3, $p4);")
public static void arraycopy(Object src, int srcPos, Object dst, int dstPos, int length) {
boolean overlapping = (src == dst && dstPos > srcPos);
if (src instanceof boolean[])
arraycopy((boolean[]) src, srcPos, (boolean[]) dst, dstPos, length, overlapping);
else if (src instanceof byte[]) arraycopy((byte[]) src, srcPos, (byte[]) dst, dstPos, length, overlapping);
else if (src instanceof char[]) arraycopy((char[]) src, srcPos, (char[]) dst, dstPos, length, overlapping);
else if (src instanceof short[]) arraycopy((short[]) src, srcPos, (short[]) dst, dstPos, length, overlapping);
else if (src instanceof int[]) arraycopy((int[]) src, srcPos, (int[]) dst, dstPos, length, overlapping);
else if (src instanceof long[]) arraycopy((long[]) src, srcPos, (long[]) dst, dstPos, length, overlapping);
else if (src instanceof float[]) arraycopy((float[]) src, srcPos, (float[]) dst, dstPos, length, overlapping);
else if (src instanceof double[])
arraycopy((double[]) src, srcPos, (double[]) dst, dstPos, length, overlapping);
else arraycopy((Object[]) src, srcPos, (Object[]) dst, dstPos, length, overlapping);
}
static private void arraycopy(boolean[] src, int srcPos, boolean[] dst, int dstPos, int length, boolean overlapping) {
if (overlapping) {
int n = length;
while (--n >= 0) dst[dstPos + n] = src[srcPos + n];
} else {
for (int n = 0; n < length; n++) dst[dstPos + n] = src[srcPos + n];
}
}
static private void arraycopy(byte[] src, int srcPos, byte[] dst, int dstPos, int length, boolean overlapping) {
if (overlapping) {
int n = length;
while (--n >= 0) dst[dstPos + n] = src[srcPos + n];
} else {
for (int n = 0; n < length; n++) dst[dstPos + n] = src[srcPos + n];
}
}
static private void arraycopy(char[] src, int srcPos, char[] dst, int dstPos, int length, boolean overlapping) {
if (overlapping) {
int n = length;
while (--n >= 0) dst[dstPos + n] = src[srcPos + n];
} else {
for (int n = 0; n < length; n++) dst[dstPos + n] = src[srcPos + n];
}
}
static private void arraycopy(short[] src, int srcPos, short[] dst, int dstPos, int length, boolean overlapping) {
if (overlapping) {
int n = length;
while (--n >= 0) dst[dstPos + n] = src[srcPos + n];
} else {
for (int n = 0; n < length; n++) dst[dstPos + n] = src[srcPos + n];
}
}
static private void arraycopy(int[] src, int srcPos, int[] dst, int dstPos, int length, boolean overlapping) {
if (overlapping) {
int n = length;
while (--n >= 0) dst[dstPos + n] = src[srcPos + n];
} else {
for (int n = 0; n < length; n++) dst[dstPos + n] = src[srcPos + n];
}
}
static private void arraycopy(long[] src, int srcPos, long[] dst, int dstPos, int length, boolean overlapping) {
if (overlapping) {
int n = length;
while (--n >= 0) dst[dstPos + n] = src[srcPos + n];
} else {
for (int n = 0; n < length; n++) dst[dstPos + n] = src[srcPos + n];
}
}
static private void arraycopy(float[] src, int srcPos, float[] dst, int dstPos, int length, boolean overlapping) {
if (overlapping) {
int n = length;
while (--n >= 0) dst[dstPos + n] = src[srcPos + n];
} else {
for (int n = 0; n < length; n++) dst[dstPos + n] = src[srcPos + n];
}
}
static private void arraycopy(double[] src, int srcPos, double[] dst, int dstPos, int length, boolean overlapping) {
if (overlapping) {
int n = length;
while (--n >= 0) dst[dstPos + n] = src[srcPos + n];
} else {
for (int n = 0; n < length; n++) dst[dstPos + n] = src[srcPos + n];
}
}
static private void arraycopy(Object[] src, int srcPos, Object[] dst, int dstPos, int length, boolean overlapping) {
if (overlapping) {
int n = length;
while (--n >= 0) dst[dstPos + n] = src[srcPos + n];
} else {
for (int n = 0; n < length; n++) dst[dstPos + n] = src[srcPos + n];
}
}
public static int identityHashCode(Object x) {
return SystemInt.identityHashCode(x);
}
public static Properties getProperties() {
return getProps();
}
public static void setProperties(Properties props) {
Properties myprops = getProps();
for (Map.Entry