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

The following examples show how to use org.codehaus.groovy.ast.expr.MethodCallExpression#getNodeMetaData() . 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
private static MethodCallExpression transformToMopSuperCall(final ClassNode superCallReceiver, final MethodCallExpression expr) {
    MethodNode mn = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
    String mopName = MopWriter.getMopMethodName(mn, false);
    MethodNode direct = new MethodNode(
            mopName,
            ACC_PUBLIC | ACC_SYNTHETIC,
            mn.getReturnType(),
            mn.getParameters(),
            mn.getExceptions(),
            EmptyStatement.INSTANCE
    );
    direct.setDeclaringClass(superCallReceiver);
    MethodCallExpression result = new MethodCallExpression(
            new VariableExpression("this"),
            mopName,
            expr.getArguments()
    );
    result.setImplicitThis(true);
    result.setSpreadSafe(false);
    result.setSafe(false);
    result.setSourcePosition(expr);
    result.setMethodTarget(direct);
    return result;
}
 
Example 2
Source File: MethodCallExpressionTransformer.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static boolean isCallOnClosure(final MethodCallExpression expr) {
    MethodNode target = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
    return expr.isImplicitThis()
            && !"call".equals(expr.getMethodAsString())
            && (target == StaticTypeCheckingVisitor.CLOSURE_CALL_VARGS
                || target == StaticTypeCheckingVisitor.CLOSURE_CALL_NO_ARG
                || target == StaticTypeCheckingVisitor.CLOSURE_CALL_ONE_ARG);
}
 
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: OptimizingStatementWriter.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethodCallExpression(final MethodCallExpression expression) {
    if (expression.getNodeMetaData(StatementMeta.class) != null) return;
    super.visitMethodCallExpression(expression);

    if (AsmClassGenerator.isThisExpression(expression.getObjectExpression())) {
        setMethodTarget(expression, expression.getMethodAsString(), expression.getArguments(), true);
    }
}
 
Example 5
Source File: TraitTypeCheckingExtension.java    From groovy with Apache License 2.0 4 votes vote down vote up
@Override
public List<MethodNode> handleMissingMethod(final ClassNode receiver, final String name, final ArgumentListExpression argumentList, final ClassNode[] argumentTypes, final MethodCall call) {
    String[] decomposed = Traits.decomposeSuperCallName(name);
    if (decomposed != null) {
        return convertToDynamicCall(call, receiver, decomposed, argumentTypes);
    }
    if (call instanceof MethodCallExpression) {
        MethodCallExpression mce = (MethodCallExpression) call;
        if (mce.getReceiver() instanceof VariableExpression) {
            VariableExpression var = (VariableExpression) mce.getReceiver();

            // GROOVY-7322
            // static method call in trait?
            ClassNode type = null;
            if (isStaticTraitReceiver(receiver, var)) {
                type = receiver.getGenericsTypes()[0].getType();
            } else if (isThisTraitReceiver(var)) {
                type = receiver;
            }
            if (Traits.isTrait(type) && !(type instanceof UnionTypeClassNode)) {
                List<ClassNode> candidates = new ArrayList<ClassNode>();
                candidates.add(type);
                while (!candidates.isEmpty()) {
                    ClassNode next = candidates.remove(0);
                    ClassNode helper = Traits.findHelper(next);
                    Parameter[] params = new Parameter[argumentTypes.length + 1];
                    params[0] = new Parameter(ClassHelper.CLASS_Type.getPlainNodeReference(), "staticSelf");
                    for (int i = 1; i < params.length; i++) {
                        params[i] = new Parameter(argumentTypes[i-1], "p" + i);
                    }
                    MethodNode method = helper.getDeclaredMethod(name, params);
                    if (method != null) {
                        return Collections.singletonList(makeDynamic(call, method.getReturnType()));
                    }
                    // GROOVY-8272 support inherited static methods
                    candidates.addAll(Arrays.asList(next.getInterfaces()));
                }
            }
        }

        ClassNode dynamic = mce.getNodeMetaData(TraitASTTransformation.DO_DYNAMIC);
        if (dynamic!=null) {
            return Collections.singletonList(makeDynamic(call, dynamic));
        }
    }
    return NOTFOUND;
}