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)
|
@MetadataProvider(TestResourceGenerator.class)
|
||||||
private native TestResource getInt();
|
private native int getInt();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void intExposed() {
|
public void intExposed() {
|
||||||
|
|
|
@ -132,7 +132,7 @@ public class Decompiler {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (method.getAnnotations().get(InjectedBy.class.getName()) != null ||
|
if (method.getAnnotations().get(InjectedBy.class.getName()) != null ||
|
||||||
methodsToPass.contains(method)) {
|
methodsToPass.contains(method.getReference())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
MethodNode methodNode = decompile(method);
|
MethodNode methodNode = decompile(method);
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.platform.plugin;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import org.teavm.codegen.SourceWriter;
|
||||||
import org.teavm.platform.metadata.Resource;
|
import org.teavm.platform.metadata.Resource;
|
||||||
import org.teavm.platform.metadata.ResourceArray;
|
import org.teavm.platform.metadata.ResourceArray;
|
||||||
import org.teavm.platform.metadata.ResourceMap;
|
import org.teavm.platform.metadata.ResourceMap;
|
||||||
|
@ -73,11 +74,22 @@ class BuildTimeResourceProxyBuilder {
|
||||||
" that is not an interface");
|
" that is not an interface");
|
||||||
}
|
}
|
||||||
scanIface(rootIface);
|
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);
|
return new BuildTimeResourceProxyFactory(methods, initialData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanIface(Class<?> iface) {
|
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() +
|
throw new IllegalArgumentException("Error creating a new resource of type " + iface.getName() +
|
||||||
". This type is not marked with the " + Resource.class.getName() + " annotation");
|
". This type is not marked with the " + Resource.class.getName() + " annotation");
|
||||||
}
|
}
|
||||||
|
@ -170,7 +182,7 @@ class BuildTimeResourceProxyBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanSetter(Method method) {
|
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) ||
|
if (propertyName == null || !method.getReturnType().equals(void.class) ||
|
||||||
method.getParameterTypes().length != 1) {
|
method.getParameterTypes().length != 1) {
|
||||||
throwInvalidMethod(method);
|
throwInvalidMethod(method);
|
||||||
|
|
|
@ -33,43 +33,43 @@ class ResourceAccessorGenerator implements Injector {
|
||||||
switch (methodRef.getName()) {
|
switch (methodRef.getName()) {
|
||||||
case "get":
|
case "get":
|
||||||
if (methodRef.getDescriptor().parameterType(1) == ValueType.INTEGER) {
|
if (methodRef.getDescriptor().parameterType(1) == ValueType.INTEGER) {
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(0));
|
||||||
context.getWriter().append('[');
|
context.getWriter().append('[');
|
||||||
context.writeExpr(context.getArgument(2));
|
context.writeExpr(context.getArgument(1));
|
||||||
context.getWriter().append(']');
|
context.getWriter().append(']');
|
||||||
} else {
|
} else {
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(0));
|
||||||
writePropertyAccessor(context, context.getArgument(2));
|
writePropertyAccessor(context, context.getArgument(1));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "put":
|
case "put":
|
||||||
context.getWriter().append('(');
|
context.getWriter().append('(');
|
||||||
if (methodRef.getDescriptor().parameterType(1) == ValueType.INTEGER) {
|
if (methodRef.getDescriptor().parameterType(1) == ValueType.INTEGER) {
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(0));
|
||||||
context.getWriter().append('[');
|
context.getWriter().append('[');
|
||||||
context.writeExpr(context.getArgument(2));
|
|
||||||
} else {
|
|
||||||
context.writeExpr(context.getArgument(1));
|
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.getWriter().append(']').ws().append('=').ws();
|
||||||
context.writeExpr(context.getArgument(3));
|
|
||||||
context.getWriter().append(')');
|
|
||||||
break;
|
|
||||||
case "add":
|
|
||||||
context.writeExpr(context.getArgument(1));
|
|
||||||
context.getWriter().append(".push(");
|
|
||||||
context.writeExpr(context.getArgument(2));
|
context.writeExpr(context.getArgument(2));
|
||||||
context.getWriter().append(')');
|
context.getWriter().append(')');
|
||||||
break;
|
break;
|
||||||
case "has":
|
case "add":
|
||||||
|
context.writeExpr(context.getArgument(0));
|
||||||
|
context.getWriter().append(".push(");
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(1));
|
||||||
|
context.getWriter().append(')');
|
||||||
|
break;
|
||||||
|
case "has":
|
||||||
|
context.writeExpr(context.getArgument(0));
|
||||||
context.getWriter().append(".hasOwnProperty(");
|
context.getWriter().append(".hasOwnProperty(");
|
||||||
writeStringExpr(context, context.getArgument(2));
|
writeStringExpr(context, context.getArgument(1));
|
||||||
context.getWriter().append(')');
|
context.getWriter().append(')');
|
||||||
break;
|
break;
|
||||||
case "size":
|
case "size":
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(0));
|
||||||
context.getWriter().append(".length");
|
context.getWriter().append(".length");
|
||||||
break;
|
break;
|
||||||
case "castToInt":
|
case "castToInt":
|
||||||
|
@ -84,7 +84,7 @@ class ResourceAccessorGenerator implements Injector {
|
||||||
case "castFromBoolean":
|
case "castFromBoolean":
|
||||||
case "castFromFloat":
|
case "castFromFloat":
|
||||||
case "castFromDouble":
|
case "castFromDouble":
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(0));
|
||||||
break;
|
break;
|
||||||
case "castToIntWrapper":
|
case "castToIntWrapper":
|
||||||
castToWrapper(context, Integer.class, int.class);
|
castToWrapper(context, Integer.class, int.class);
|
||||||
|
@ -124,29 +124,37 @@ class ResourceAccessorGenerator implements Injector {
|
||||||
break;
|
break;
|
||||||
case "castToString":
|
case "castToString":
|
||||||
context.getWriter().append("$rt_str(");
|
context.getWriter().append("$rt_str(");
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(0));
|
||||||
context.getWriter().append(")");
|
context.getWriter().append(")");
|
||||||
break;
|
break;
|
||||||
case "castFromString":
|
case "castFromString":
|
||||||
context.getWriter().append("$rt_ustr(");
|
context.getWriter().append("$rt_ustr(");
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(0));
|
||||||
context.getWriter().append(")");
|
context.getWriter().append(")");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void castToWrapper(InjectorContext context, Class<?> wrapper, Class<?> primitive) throws IOException {
|
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.getWriter().appendMethodBody(new MethodReference(wrapper, "valueOf", primitive, wrapper)).append('(');
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(0));
|
||||||
context.getWriter().append(')');
|
context.getWriter().append("))");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void castFromWrapper(InjectorContext context, Class<?> wrapper, Class<?> primitive) throws IOException {
|
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();
|
String primitiveName = primitive.getName();
|
||||||
context.getWriter().appendMethodBody(new MethodReference(wrapper, primitiveName + "Value", primitive))
|
context.getWriter().appendMethodBody(new MethodReference(wrapper, primitiveName + "Value", primitive))
|
||||||
.append('(');
|
.append('(');
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(0));
|
||||||
context.getWriter().append(')');
|
context.getWriter().append("))");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writePropertyAccessor(InjectorContext context, Expr property) throws IOException {
|
private void writePropertyAccessor(InjectorContext context, Expr property) throws IOException {
|
||||||
|
|
|
@ -224,7 +224,7 @@ class ResourceTransformer implements ClassHolderTransformer {
|
||||||
|
|
||||||
private String getPropertyName(String name) {
|
private String getPropertyName(String name) {
|
||||||
if (name.length() == 1) {
|
if (name.length() == 1) {
|
||||||
return name;
|
return name.toLowerCase();
|
||||||
}
|
}
|
||||||
if (Character.isUpperCase(name.charAt(1))) {
|
if (Character.isUpperCase(name.charAt(1))) {
|
||||||
return name;
|
return name;
|
||||||
|
|
|
@ -22,6 +22,6 @@ import org.teavm.codegen.SourceWriter;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
interface ResourceWriter {
|
public interface ResourceWriter {
|
||||||
void write(SourceWriter writer) throws IOException;
|
void write(SourceWriter writer) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user