Fix generation of meta method when its discriminator class denotes array type

This commit is contained in:
Alexey Andreev 2017-02-12 00:23:53 +03:00
parent 19e8e06446
commit edb3d2ff48
3 changed files with 13 additions and 2 deletions

View File

@ -107,7 +107,7 @@ public class MetaprogrammingDependencyListener extends AbstractDependencyListene
ValueType type = usageEntry.getKey(); ValueType type = usageEntry.getKey();
String typeName = type instanceof ValueType.Object String typeName = type instanceof ValueType.Object
? ((ValueType.Object) type).getClassName() ? ((ValueType.Object) type).getClassName()
: type.toString(); : type.toString().replace('/', '.');
choice.option(typeName, () -> { choice.option(typeName, () -> {
MethodReference implMethod = usageEntry.getValue(); MethodReference implMethod = usageEntry.getValue();
ValueEmitter[] castParamVars = new ValueEmitter[paramVars.length]; ValueEmitter[] castParamVars = new ValueEmitter[paramVars.length];

View File

@ -94,7 +94,6 @@ public class MethodDescriber {
int classParamIndex = -1; int classParamIndex = -1;
for (int i = 0; i < method.parameterCount(); ++i) { for (int i = 0; i < method.parameterCount(); ++i) {
ValueType proxyParam = meta.parameterType(i + paramOffset); ValueType proxyParam = meta.parameterType(i + paramOffset);
ValueType param = method.parameterType(i);
if (proxyParam.isObject(ReflectClass.class)) { if (proxyParam.isObject(ReflectClass.class)) {
if (classParamIndex == -1) { if (classParamIndex == -1) {
classParamIndex = i; classParamIndex = i;

View File

@ -414,6 +414,18 @@ public class MetaprogrammingTest {
private static int counter = 0; private static int counter = 0;
@Test
public void arrayTypeSelected() {
assertEquals(String[].class, createInstance(String.class, 1).getClass());
assertEquals(String[][].class, createInstance(String[].class, 1).getClass());
}
@Meta
private static native Object createInstance(Class<?> cls, int size);
private static void createInstance(ReflectClass<?> cls, Value<Integer> size) {
exit(() -> cls.createArray(size.get()));
}
static class Context { static class Context {
public int a; public int a;
public int b; public int b;