Fix slf4j support. Add PrintStream.println(double)

This commit is contained in:
konsoletyper 2015-03-16 21:55:37 +03:00
parent 6964c7190d
commit e7db80fe2b
2 changed files with 26 additions and 0 deletions

View File

@ -166,6 +166,11 @@ public class TPrintStream extends TFilterOutputStream {
printSB(); printSB();
} }
public void println(double d) {
sb.append(d).append('\n');
printSB();
}
public void print(TString s) { public void print(TString s) {
sb.append(s); sb.append(s);
printSB(); printSB();

View File

@ -17,6 +17,7 @@ package org.teavm.extras.slf4j;
import org.slf4j.ILoggerFactory; import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.helpers.SubstituteLoggerFactory;
import org.teavm.diagnostics.Diagnostics; import org.teavm.diagnostics.Diagnostics;
import org.teavm.model.*; import org.teavm.model.*;
import org.teavm.model.instructions.*; import org.teavm.model.instructions.*;
@ -34,6 +35,7 @@ public class LoggerFactoryTransformer implements ClassHolderTransformer {
addCacheField(cls); addCacheField(cls);
modifyClinit(cls); modifyClinit(cls);
replaceGetFactory(cls); replaceGetFactory(cls);
cls.removeField(cls.getField("TEMP_FACTORY"));
} }
private void addCacheField(ClassHolder cls) { private void addCacheField(ClassHolder cls) {
@ -61,6 +63,25 @@ public class LoggerFactoryTransformer implements ClassHolderTransformer {
put.setValue(factoryVar); put.setValue(factoryVar);
put.setField(new FieldReference(LoggerFactory.class.getName(), "loggerFactoryCache")); put.setField(new FieldReference(LoggerFactory.class.getName(), "loggerFactoryCache"));
clinitBlock.getInstructions().add(2, put); clinitBlock.getInstructions().add(2, put);
Program program = clinit.getProgram();
for (int i = 0; i < program.basicBlockCount(); ++i) {
BasicBlock block = program.basicBlockAt(i);
for (int j = 0; j < block.getInstructions().size(); ++j) {
Instruction insn = block.getInstructions().get(j);
if (insn instanceof InvokeInstruction) {
InvokeInstruction invoke = (InvokeInstruction)insn;
if (invoke.getMethod().getClassName().equals(SubstituteLoggerFactory.class.getName())) {
block.getInstructions().set(j, new EmptyInstruction());
}
} else if (insn instanceof PutFieldInstruction) {
PutFieldInstruction putField = (PutFieldInstruction)insn;
if (putField.getField().getFieldName().equals("TEMP_FACTORY")) {
block.getInstructions().set(j, new EmptyInstruction());
}
}
}
}
} }
private void replaceGetFactory(ClassHolder cls) { private void replaceGetFactory(ClassHolder cls) {