Java Code Examples for org.codehaus.groovy.ast.expr.MethodCallExpression#getMethodTarget()

The following examples show how to use org.codehaus.groovy.ast.expr.MethodCallExpression#getMethodTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodCallExpressionTransformer.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Identifies a method call expression on {@link DefaultGroovyMethods#is(Object, Object)} and if recognized, transforms it into a {@link CompareIdentityExpression}.
 * @param call a method call to be transformed
 * @return null if the method call is not DGM#is, or {@link CompareIdentityExpression}
 */
private static Expression tryTransformIsToCompareIdentity(MethodCallExpression call) {
    if (call.isSafe()) return null;
    MethodNode methodTarget = call.getMethodTarget();
    if (methodTarget instanceof ExtensionMethodNode && "is".equals(methodTarget.getName()) && methodTarget.getParameters().length==1) {
        methodTarget = ((ExtensionMethodNode) methodTarget).getExtensionMethodNode();
        ClassNode owner = methodTarget.getDeclaringClass();
        if (DGM_CLASSNODE.equals(owner)) {
            Expression args = call.getArguments();
            if (args instanceof ArgumentListExpression) {
                ArgumentListExpression arguments = (ArgumentListExpression) args;
                List<Expression> exprs = arguments.getExpressions();
                if (exprs.size() == 1) {
                    CompareIdentityExpression cid = new CompareIdentityExpression(call.getObjectExpression(), exprs.get(0));
                    cid.setSourcePosition(call);
                    return cid;
                }
            }
        }
    }
    return null;
}
 
Example 2
Source File: MethodSignatureBuilder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MethodSignatureBuilder appendReturnType(MethodCallExpression methodCall) {
    builder.append(" : "); // NOI18N

    final MethodNode methodTarget = methodCall.getMethodTarget();
    if (methodTarget != null && methodTarget.getReturnType() != null) {
        builder.append(methodTarget.getReturnType().getNameWithoutPackage());
    } else {
        // We don't know exact return type - just show an Object for now
        builder.append("Object"); // NOI18N
    }
    return this;
}
 
Example 3
Source File: StaticCompilationVisitor.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethodCallExpression(final MethodCallExpression call) {
    super.visitMethodCallExpression(call);

    MethodNode target = call.getNodeMetaData(DIRECT_METHOD_CALL_TARGET);
    if (target != null) {
        call.setMethodTarget(target);
        memorizeInitialExpressions(target);
    }

    if (call.getMethodTarget() == null && call.getLineNumber() > 0) {
        addError("Target method for method call expression hasn't been set", call);
    }
}
 
Example 4
Source File: StaticTypesClosureWriter.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethodCallExpression(final MethodCallExpression call) {
    super.visitMethodCallExpression(call);
    MethodNode mn = call.getMethodTarget();
    if (mn == null) {
        call.setMethodTarget(doCallMethod);
    }
}