private Term buildInvokeTerm(final Type activeType, final Tree invokeNode)
{
String methodName = invokeNode.getChild(0).getText();
int parameterCount = invokeNode.getChildCount() - 1;
Class activeClass = GenericsUtils.asClass(activeType);
final Method method = findMethod(activeClass, methodName, parameterCount);
if (method.getReturnType().equals(void.class))
throw new RuntimeException(String.format("Method %s.%s() returns void.", activeClass.getName(),
methodName));
Type returnType = GenericsUtils.extractActualType(activeType, method);
return new Term(returnType, toUniqueId(method), InternalCommonsUtils.toAnnotationProvider(method), new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
invokeMethod(builder, method, invokeNode, 1);
Type genericType = GenericsUtils.extractActualType(activeType, method);
castToGenericType(builder, method.getReturnType(), genericType);
}
}
);
}