mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Makes all current metadata provider tests passing
This commit is contained in:
parent
c6e7b30bed
commit
6992c81e8d
|
@ -32,7 +32,7 @@ public class MetadataGeneratorTest {
|
|||
}
|
||||
|
||||
@MetadataProvider(TestResourceGenerator.class)
|
||||
private native TestResource getInt();
|
||||
private native int getInt();
|
||||
|
||||
@Test
|
||||
public void intExposed() {
|
||||
|
|
|
@ -132,7 +132,7 @@ public class Decompiler {
|
|||
continue;
|
||||
}
|
||||
if (method.getAnnotations().get(InjectedBy.class.getName()) != null ||
|
||||
methodsToPass.contains(method)) {
|
||||
methodsToPass.contains(method.getReference())) {
|
||||
continue;
|
||||
}
|
||||
MethodNode methodNode = decompile(method);
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.platform.plugin;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import org.teavm.codegen.SourceWriter;
|
||||
import org.teavm.platform.metadata.Resource;
|
||||
import org.teavm.platform.metadata.ResourceArray;
|
||||
import org.teavm.platform.metadata.ResourceMap;
|
||||
|
@ -73,11 +74,22 @@ class BuildTimeResourceProxyBuilder {
|
|||
" that is not an interface");
|
||||
}
|
||||
scanIface(rootIface);
|
||||
Method writeMethod;
|
||||
try {
|
||||
writeMethod = ResourceWriter.class.getMethod("write", SourceWriter.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new AssertionError("Method must exist", e);
|
||||
}
|
||||
String[] properties = new String[propertyIndexes.size()];
|
||||
for (Map.Entry<String, Integer> entry : propertyIndexes.entrySet()) {
|
||||
properties[entry.getValue()] = entry.getKey();
|
||||
}
|
||||
methods.put(writeMethod, new BuildTimeResourceWriterMethod(properties));
|
||||
return new BuildTimeResourceProxyFactory(methods, initialData);
|
||||
}
|
||||
|
||||
private void scanIface(Class<?> iface) {
|
||||
if (iface.isAnnotationPresent(Resource.class)) {
|
||||
if (!iface.isAnnotationPresent(Resource.class)) {
|
||||
throw new IllegalArgumentException("Error creating a new resource of type " + iface.getName() +
|
||||
". This type is not marked with the " + Resource.class.getName() + " annotation");
|
||||
}
|
||||
|
@ -170,7 +182,7 @@ class BuildTimeResourceProxyBuilder {
|
|||
}
|
||||
|
||||
private void scanSetter(Method method) {
|
||||
String propertyName = extractPropertyName(method.getName().substring(2));
|
||||
String propertyName = extractPropertyName(method.getName().substring(3));
|
||||
if (propertyName == null || !method.getReturnType().equals(void.class) ||
|
||||
method.getParameterTypes().length != 1) {
|
||||
throwInvalidMethod(method);
|
||||
|
|
|
@ -33,43 +33,43 @@ class ResourceAccessorGenerator implements Injector {
|
|||
switch (methodRef.getName()) {
|
||||
case "get":
|
||||
if (methodRef.getDescriptor().parameterType(1) == ValueType.INTEGER) {
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().append('[');
|
||||
context.writeExpr(context.getArgument(2));
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.getWriter().append(']');
|
||||
} else {
|
||||
context.writeExpr(context.getArgument(1));
|
||||
writePropertyAccessor(context, context.getArgument(2));
|
||||
context.writeExpr(context.getArgument(0));
|
||||
writePropertyAccessor(context, context.getArgument(1));
|
||||
}
|
||||
break;
|
||||
case "put":
|
||||
context.getWriter().append('(');
|
||||
if (methodRef.getDescriptor().parameterType(1) == ValueType.INTEGER) {
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().append('[');
|
||||
context.writeExpr(context.getArgument(2));
|
||||
} else {
|
||||
context.writeExpr(context.getArgument(1));
|
||||
writePropertyAccessor(context, context.getArgument(2));
|
||||
} else {
|
||||
context.writeExpr(context.getArgument(0));
|
||||
writePropertyAccessor(context, context.getArgument(1));
|
||||
}
|
||||
context.getWriter().append(']').ws().append('=').ws();
|
||||
context.writeExpr(context.getArgument(3));
|
||||
context.writeExpr(context.getArgument(2));
|
||||
context.getWriter().append(')');
|
||||
break;
|
||||
case "add":
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().append(".push(");
|
||||
context.writeExpr(context.getArgument(2));
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.getWriter().append(')');
|
||||
break;
|
||||
case "has":
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().append(".hasOwnProperty(");
|
||||
writeStringExpr(context, context.getArgument(2));
|
||||
writeStringExpr(context, context.getArgument(1));
|
||||
context.getWriter().append(')');
|
||||
break;
|
||||
case "size":
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().append(".length");
|
||||
break;
|
||||
case "castToInt":
|
||||
|
@ -84,7 +84,7 @@ class ResourceAccessorGenerator implements Injector {
|
|||
case "castFromBoolean":
|
||||
case "castFromFloat":
|
||||
case "castFromDouble":
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.writeExpr(context.getArgument(0));
|
||||
break;
|
||||
case "castToIntWrapper":
|
||||
castToWrapper(context, Integer.class, int.class);
|
||||
|
@ -124,29 +124,37 @@ class ResourceAccessorGenerator implements Injector {
|
|||
break;
|
||||
case "castToString":
|
||||
context.getWriter().append("$rt_str(");
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().append(")");
|
||||
break;
|
||||
case "castFromString":
|
||||
context.getWriter().append("$rt_ustr(");
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().append(")");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void castToWrapper(InjectorContext context, Class<?> wrapper, Class<?> primitive) throws IOException {
|
||||
context.getWriter().append('(');
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().ws().append("==").ws().append("null").ws().append('?').ws().append("null")
|
||||
.ws().append(':').ws();
|
||||
context.getWriter().appendMethodBody(new MethodReference(wrapper, "valueOf", primitive, wrapper)).append('(');
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.getWriter().append(')');
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().append("))");
|
||||
}
|
||||
|
||||
private void castFromWrapper(InjectorContext context, Class<?> wrapper, Class<?> primitive) throws IOException {
|
||||
context.getWriter().append('(');
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().ws().append("==").ws().append("null").ws().append('?').ws().append("null")
|
||||
.ws().append(':').ws();
|
||||
String primitiveName = primitive.getName();
|
||||
context.getWriter().appendMethodBody(new MethodReference(wrapper, primitiveName + "Value", primitive))
|
||||
.append('(');
|
||||
context.writeExpr(context.getArgument(1));
|
||||
context.getWriter().append(')');
|
||||
context.writeExpr(context.getArgument(0));
|
||||
context.getWriter().append("))");
|
||||
}
|
||||
|
||||
private void writePropertyAccessor(InjectorContext context, Expr property) throws IOException {
|
||||
|
|
|
@ -224,7 +224,7 @@ class ResourceTransformer implements ClassHolderTransformer {
|
|||
|
||||
private String getPropertyName(String name) {
|
||||
if (name.length() == 1) {
|
||||
return name;
|
||||
return name.toLowerCase();
|
||||
}
|
||||
if (Character.isUpperCase(name.charAt(1))) {
|
||||
return name;
|
||||
|
|
|
@ -22,6 +22,6 @@ import org.teavm.codegen.SourceWriter;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
interface ResourceWriter {
|
||||
public interface ResourceWriter {
|
||||
void write(SourceWriter writer) throws IOException;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user