private Statement makeMethodBody( ClassNode classNode, MethodSignature methodSignature, Parameter[] parameters) { String invokeMethod = methodSignature.isStatic() ? "invokeStatic" : "invokeInstance"; Expression[] args = new Expression[parameters.length + 2]; args[0] = methodSignature.isStatic() ? new ClassExpression(classNode) : VariableExpression.THIS_EXPRESSION; args[1] = new ConstantExpression(methodSignature.getMethodName()); int i = 2; for (Parameter parameter : parameters) { args[i++] = new VariableExpression(parameter.getName()); } return returns(call(getDomainHandlerMethod(classNode), invokeMethod, args(args))); }
protected void injectMethod(ClassNode classNode, MethodSignature methodSignature) { Parameter[] parameters = makeParameters(methodSignature.getParameterTypes()); int modifiers = Modifier.PUBLIC; if (methodSignature.isStatic()) modifiers |= Modifier.STATIC; String returnTypeClassName = methodSignature.getReturnType().getName(); ClassNode returnType = GRIFFON_DOMAIN_CLASSNAME.equals(returnTypeClassName) ? classNode : ClassHelper.makeWithoutCaching(methodSignature.getReturnType()); classNode.addMethod( new MethodNode( methodSignature.getMethodName(), modifiers, returnType, parameters, ClassNode.EMPTY_ARRAY, makeMethodBody(classNode, methodSignature, parameters))); }