mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Fix bug in support for resources
This commit is contained in:
parent
c2f90d3cfc
commit
ada2bf9c58
|
@ -25,4 +25,8 @@ final class StringAmplifier {
|
|||
@PluggableDependency(StringAmplifierDependencyPlugin.class)
|
||||
@Unmanaged
|
||||
static native String amplify(String string);
|
||||
|
||||
@PluggableDependency(StringAmplifierDependencyPlugin.class)
|
||||
@Unmanaged
|
||||
static native String[] amplifyArray(String[] strings);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,11 @@ import org.teavm.dependency.MethodDependency;
|
|||
public class StringAmplifierDependencyPlugin implements DependencyPlugin {
|
||||
@Override
|
||||
public void methodReached(DependencyAgent agent, MethodDependency method) {
|
||||
if (method.getMethod().getName().equals("amplify")) {
|
||||
method.getResult().propagate(agent.getType("java.lang.String"));
|
||||
} else {
|
||||
method.getResult().propagate(agent.getType("[Ljava/lang/String;"));
|
||||
method.getResult().getArrayItem().propagate(agent.getType("java.lang.String"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.teavm.model.Variable;
|
|||
import org.teavm.model.instructions.InvocationType;
|
||||
import org.teavm.model.instructions.InvokeInstruction;
|
||||
import org.teavm.platform.metadata.Resource;
|
||||
import org.teavm.platform.metadata.ResourceMap;
|
||||
|
||||
public class StringAmplifierTransformer implements ClassHolderTransformer {
|
||||
@Override
|
||||
|
@ -54,7 +55,21 @@ public class StringAmplifierTransformer implements ClassHolderTransformer {
|
|||
MethodReference method = invoke.getMethod();
|
||||
String owningClass = method.getClassName();
|
||||
if (hierarchy.isSuperType(Resource.class.getName(), owningClass, false)) {
|
||||
if (method.getReturnType().isObject(String.class)) {
|
||||
if (method.getClassName().equals(ResourceMap.class.getName())) {
|
||||
if (method.getName().equals("keys")) {
|
||||
Variable var = program.createVariable();
|
||||
InvokeInstruction amplifyInstruction = new InvokeInstruction();
|
||||
amplifyInstruction.setMethod(new MethodReference(StringAmplifier.class, "amplifyArray",
|
||||
String[].class, String[].class));
|
||||
amplifyInstruction.setType(InvocationType.SPECIAL);
|
||||
amplifyInstruction.setArguments(var);
|
||||
amplifyInstruction.setReceiver(invoke.getReceiver());
|
||||
amplifyInstruction.setLocation(invoke.getLocation());
|
||||
|
||||
invoke.setReceiver(var);
|
||||
invoke.insertNext(amplifyInstruction);
|
||||
}
|
||||
} else if (method.getReturnType().isObject(String.class)) {
|
||||
Variable var = program.createVariable();
|
||||
InvokeInstruction amplifyInstruction = new InvokeInstruction();
|
||||
amplifyInstruction.setMethod(new MethodReference(StringAmplifier.class, "amplify",
|
||||
|
|
Loading…
Reference in New Issue
Block a user