} else if (a2.isStructure()) { // Parameterized method
methodName = ((StructureTerm) a2).name();
arity = ((StructureTerm) a2).arity();
methods = clazz.getDeclaredMethods();
if (methods.length == 0) {
throw new ExistenceException(this, 2, "method", a2, "");
}
pArgs = ((StructureTerm) a2).args();
jArgs = new Object[arity];
for (int i = 0; i < arity; i++) {
pArgs[i] = pArgs[i].dereference();
if (!pArgs[i].isJavaObject()) {
pArgs[i] = new JavaObjectTerm(pArgs[i]);
}
jArgs[i] = pArgs[i].toJava();
}
for (Method method : methods) {
if (method.getName().equals(methodName)
&& checkParameterTypes(method.getParameterTypes(),
pArgs)) {
try {
m = method;
m.setAccessible(true);
value = m.invoke(instance, jArgs);
break; // Succeeds to invoke the method
} catch (Exception e) {
m = null; // Back to loop
}
}
}
if (m == null) {
throw new ExistenceException(this, 2, "method", a2, "");
}
} else {
throw new IllegalTypeException(this, 2, "callable", a2);
}
if (value == null) {