if (methodName.equals(field.getName())) {
try {
field.setAccessible(true);
return field.get(instance);
} catch (IllegalArgumentException e) {
throw new LajaException("Could not access field '" + methodName + "': " + e.getMessage());
} catch (IllegalAccessException e) {
throw new LajaException("Could not access field '" + methodName + "': " + e.getMessage());
}
}
}
if (clazz.isArray() && methodName.equals("length")) {
return Array.getLength(instance);
}
}
String message = "Could not find method " + methodName + "(";
String separator = "";
if (arguments.length > 0) {
for (int i=0; i<arguments.length; i++) {
message += separator + parameterTypes[i];
separator = ", ";
}
}
message += ") in class " + clazz.getCanonicalName() + ".";
throw new LajaException(message);
}
try {
if (methodTypelist.isVararg()) {
Object[] varargArguments = new Object[methodTypelist.getVarargStartIndex() + 1];
for (int i=0; i<methodTypelist.getVarargStartIndex(); i++) {
varargArguments[i] = arguments[i];
}
int varargLength = arguments.length - methodTypelist.getVarargStartIndex();
Object varargs = Array.newInstance(methodTypelist.getVarargType(), varargLength);
System.arraycopy(arguments, methodTypelist.getVarargStartIndex(), varargs, 0, varargLength);
varargArguments[methodTypelist.getVarargStartIndex()] = varargs;
return methodTypelist.getMethod().invoke(instance, varargArguments);
} else {
return methodTypelist.getMethod().invoke(instance, arguments);
}
} catch (IllegalArgumentException e) {
return new LajaException(e);
} catch (IllegalAccessException e) {
return new LajaException(e);
} catch (InvocationTargetException e) {
return new LajaException(e);
}
}