use of org.codehaus.groovy.macro.runtime.MacroContext in project groovy by apache.
the class MacroCallTransformingVisitor method visitMethodCallExpression.
@Override
public void visitMethodCallExpression(MethodCallExpression call) {
super.visitMethodCallExpression(call);
final List<Expression> callArguments;
if (call.getArguments() instanceof TupleExpression) {
callArguments = ((TupleExpression) call.getArguments()).getExpressions();
} else {
callArguments = Collections.singletonList(call.getArguments());
}
List<MethodNode> macroMethods = findMacroMethods(call.getMethodAsString(), callArguments);
if (macroMethods.isEmpty()) {
// Early return to avoid macro context and arguments creation
return;
}
MacroContext macroContext = new MacroContext(unit, sourceUnit, call);
Object[] macroArguments = new Object[callArguments.size() + 1];
macroArguments[0] = macroContext;
System.arraycopy(callArguments.toArray(), 0, macroArguments, 1, callArguments.size());
for (MethodNode macroMethodNode : macroMethods) {
if (!(macroMethodNode instanceof ExtensionMethodNode)) {
throw new IllegalStateException(macroMethodNode + " is not an instance of ExtensionMethodNode");
}
if (tryMacroMethod(call, (ExtensionMethodNode) macroMethodNode, macroArguments)) {
break;
}
}
}
Aggregations