mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
Beginning to implement PrintWriter.
This commit is contained in:
parent
6eb145e1d0
commit
79e2eca91d
|
@ -0,0 +1,13 @@
|
|||
package org.teavm.classlib.impl.charset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public abstract class Charset {
|
||||
public abstract int encode(int[] buffer, int offset, int length, byte[] dest, int destOffset, int destLength);
|
||||
|
||||
public abstract int decode(byte[] buffer, int offset, int length, int[] dest, int destOffset, int destLength);
|
||||
|
||||
public static native Charset get(String name);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.teavm.classlib.impl.charset;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface CharsetName {
|
||||
String value();
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.teavm.classlib.impl.charset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
@CharsetName("UTF-16")
|
||||
public class UTF16Charset {
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package org.teavm.classlib.impl.charset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
@CharsetName("UTF-8")
|
||||
public class UTF8Charset extends Charset {
|
||||
@Override
|
||||
public int encode(int[] buffer, int offset, int length, byte[] dest, int destOffset, int destLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int decode(byte[] buffer, int offset, int length, int[] dest, int destOffset, int destLength) {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -351,4 +351,17 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
|
|||
// TODO: implement
|
||||
throw new TUnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
|
||||
if (srcBegin > srcEnd) {
|
||||
throw new TIndexOutOfBoundsException(TString.wrap("Index out of bounds"));
|
||||
}
|
||||
while (srcBegin < srcEnd) {
|
||||
dst[dstBegin++] = buffer[srcBegin++];
|
||||
}
|
||||
}
|
||||
|
||||
public void setLength(int newLength) {
|
||||
length = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package org.teavm.classlib.java.lang;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public interface TAutoCloseable {
|
||||
void close() throws TException;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.teavm.classlib.java.lang.io;
|
||||
|
||||
import org.teavm.classlib.java.lang.TAutoCloseable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public interface TCloseable extends TAutoCloseable {
|
||||
@Override
|
||||
void close() throws TIOException;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package org.teavm.classlib.java.lang.io;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class TFilterOutputStream extends TOutputStream {
|
||||
protected TOutputStream out;
|
||||
|
||||
public TFilterOutputStream(TOutputStream out) {
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws TIOException {
|
||||
out.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws TIOException {
|
||||
try {
|
||||
out.flush();
|
||||
} catch (TIOException e) {
|
||||
// do nothing
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws TIOException {
|
||||
out.flush();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.teavm.classlib.java.lang.io;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public interface TFlushable {
|
||||
void flush() throws TIOException;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.teavm.classlib.java.lang.io;
|
||||
|
||||
import org.teavm.classlib.java.lang.TException;
|
||||
import org.teavm.classlib.java.lang.TString;
|
||||
import org.teavm.classlib.java.lang.TThrowable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class TIOException extends TException {
|
||||
private static final long serialVersionUID = 3626109154700059455L;
|
||||
|
||||
public TIOException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TIOException(TString message, TThrowable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public TIOException(TString message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TIOException(TThrowable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.teavm.classlib.java.lang.io;
|
||||
|
||||
import org.teavm.classlib.java.lang.TObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public abstract class TOutputStream extends TObject implements TCloseable, TFlushable {
|
||||
public abstract void write(int b) throws TIOException;
|
||||
|
||||
public void write(byte[] b) throws TIOException {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws TIOException {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
write(b[off++]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws TIOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws TIOException {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package org.teavm.classlib.java.lang.io;
|
||||
|
||||
import org.teavm.classlib.java.lang.TStringBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class TPrintStream extends TFilterOutputStream {
|
||||
private boolean autoFlush;
|
||||
private boolean errorState;
|
||||
private TStringBuilder sb = new TStringBuilder();
|
||||
private char[] buffer = new char[32];
|
||||
|
||||
public TPrintStream(TOutputStream out, boolean autoFlush) {
|
||||
super(out);
|
||||
this.autoFlush = autoFlush;
|
||||
}
|
||||
|
||||
public TPrintStream(TOutputStream out) {
|
||||
this(out, false);
|
||||
}
|
||||
|
||||
public boolean checkError() {
|
||||
flush();
|
||||
return errorState;
|
||||
}
|
||||
|
||||
protected void setError() {
|
||||
errorState = true;
|
||||
}
|
||||
|
||||
protected void clearError() {
|
||||
errorState = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) {
|
||||
if (!check()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
out.write(b);
|
||||
} catch (TIOException e) {
|
||||
errorState = true;
|
||||
}
|
||||
if (autoFlush && !errorState) {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) {
|
||||
if (!check()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
out.write(b, off, len);
|
||||
} catch (TIOException e) {
|
||||
errorState = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws TIOException {
|
||||
if (!checkError()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
out.close();
|
||||
} catch (TIOException e) {
|
||||
errorState = true;
|
||||
} finally {
|
||||
out = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws TIOException {
|
||||
if (!check()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
out.flush();
|
||||
} catch (TIOException e) {
|
||||
errorState = true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean check() {
|
||||
if (out == null) {
|
||||
errorState = true;
|
||||
}
|
||||
return !errorState;
|
||||
}
|
||||
|
||||
public void print(char[] s) {
|
||||
|
||||
}
|
||||
|
||||
public void print(int i) {
|
||||
sb.append(i);
|
||||
printSB();
|
||||
}
|
||||
|
||||
private void printSB() {
|
||||
char[] buffer = sb.length() > this.buffer.length ? new char[sb.length()] : this.buffer;
|
||||
sb.getChars(0, sb.length(), buffer, 0);
|
||||
print(buffer);
|
||||
sb.setLength(0);
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ import org.junit.Test;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class ClassTests {
|
||||
public class ClassTest {
|
||||
@Test
|
||||
public void classNameEvaluated() {
|
||||
assertEquals("java.lang.Object", Object.class.getName());
|
|
@ -7,7 +7,7 @@ import org.junit.Test;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class ObjectTests {
|
||||
public class ObjectTest {
|
||||
@Test
|
||||
public void objectCreated() {
|
||||
Object a = new Object();
|
|
@ -7,7 +7,7 @@ import org.junit.Test;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class StringBuilderTests {
|
||||
public class StringBuilderTest {
|
||||
@Test
|
||||
public void integerAppended() {
|
||||
StringBuilder sb = new StringBuilder();
|
|
@ -7,7 +7,7 @@ import org.junit.Test;
|
|||
*
|
||||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||
*/
|
||||
public class StringTests {
|
||||
public class StringTest {
|
||||
@Test
|
||||
public void charsExtracted() {
|
||||
String str = "123";
|
|
@ -7,7 +7,7 @@ import org.junit.Test;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class SystemTests {
|
||||
public class SystemTest {
|
||||
@Test
|
||||
public void copiesArray() {
|
||||
Object a = new Object();
|
|
@ -7,7 +7,7 @@ import org.junit.Test;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class VMTests {
|
||||
public class VMTest {
|
||||
@Test
|
||||
public void multiArrayCreated() {
|
||||
int[][] array = new int[2][3];
|
|
@ -129,10 +129,14 @@ public class BuildJavascriptJUnitMojo extends AbstractMojo {
|
|||
}
|
||||
allTestsWriter.write("], function() {}); }");
|
||||
}
|
||||
int methodsGenerated = 0;
|
||||
log.info("Generating test files");
|
||||
for (MethodReference method : testMethods) {
|
||||
log.info("Building test for " + method);
|
||||
log.debug("Building test for " + method);
|
||||
decompileClassesForTest(classLoader, method, fileNames.get(method));
|
||||
++methodsGenerated;
|
||||
}
|
||||
log.info("Test files successfully generated for " + methodsGenerated + " method(s)");
|
||||
} catch (IOException e) {
|
||||
throw new MojoFailureException("IO error occured generating JavaScript files", e);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,9 @@ import org.apache.maven.plugins.annotations.Mojo;
|
|||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.teavm.javascript.JavascriptBuilder;
|
||||
import org.teavm.model.MethodDescriptor;
|
||||
import org.teavm.model.MethodReference;
|
||||
import org.teavm.model.ValueType;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -36,6 +39,9 @@ public class BuildJavascriptMojo extends AbstractMojo {
|
|||
@Parameter
|
||||
private boolean minifiying = true;
|
||||
|
||||
@Parameter
|
||||
private String mainClass;
|
||||
|
||||
public void setProject(MavenProject project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
@ -60,6 +66,10 @@ public class BuildJavascriptMojo extends AbstractMojo {
|
|||
log.info("Building JavaScript file");
|
||||
JavascriptBuilder builder = new JavascriptBuilder(classLoader);
|
||||
builder.setMinifying(minifiying);
|
||||
MethodDescriptor mainMethodDesc = new MethodDescriptor("main", ValueType.arrayOf(
|
||||
ValueType.object("java.lang.String")), ValueType.VOID);
|
||||
builder.entryPoint("main", new MethodReference(mainClass, mainMethodDesc))
|
||||
.withValue(1, "java.lang.String");
|
||||
builder.build(targetFile);
|
||||
log.info("JavaScript file successfully built");
|
||||
} catch (RuntimeException e) {
|
||||
|
|
0
teavm-maven-plugin/src/test/java/.gitignore
vendored
Normal file
0
teavm-maven-plugin/src/test/java/.gitignore
vendored
Normal file
0
teavm-maven-plugin/src/test/resources/.gitignore
vendored
Normal file
0
teavm-maven-plugin/src/test/resources/.gitignore
vendored
Normal file
Loading…
Reference in New Issue
Block a user