当前位置: 首页>>代码示例>>Java>>正文


Java MethodCallExpression.getObjectExpression方法代码示例

本文整理汇总了Java中org.codehaus.groovy.ast.expr.MethodCallExpression.getObjectExpression方法的典型用法代码示例。如果您正苦于以下问题:Java MethodCallExpression.getObjectExpression方法的具体用法?Java MethodCallExpression.getObjectExpression怎么用?Java MethodCallExpression.getObjectExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.groovy.ast.expr.MethodCallExpression的用法示例。


在下文中一共展示了MethodCallExpression.getObjectExpression方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tryTransformIsToCompareIdentity

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:MethodCallExpressionTransformer.java

示例2: makeInvokeMethodCall

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private void makeInvokeMethodCall(MethodCallExpression call, boolean useSuper, MethodCallerMultiAdapter adapter) {
    // receiver
    // we operate on GroovyObject if possible
    Expression objectExpression = call.getObjectExpression();
    // message name
    Expression messageName = new CastExpression(ClassHelper.STRING_TYPE, call.getMethod());
    if (useSuper) {
        ClassNode classNode = controller.isInClosure() ? controller.getOutermostClass() : controller.getClassNode(); // GROOVY-4035 
        ClassNode superClass = classNode.getSuperClass();
        makeCall(call, new ClassExpression(superClass),
                objectExpression, messageName,
                call.getArguments(), adapter,
                call.isSafe(), call.isSpreadSafe(),
                false
        );
    } else {
        makeCall(call, objectExpression, messageName,
                call.getArguments(), adapter,
                call.isSafe(), call.isSpreadSafe(),
                call.isImplicitThis()
        );
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:InvocationWriter.java

示例3: tryTransformInclude

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression tryTransformInclude(final MethodCallExpression exp) {
    Expression arguments = exp.getArguments();
    if (arguments instanceof TupleExpression) {
        List<Expression> expressions = ((TupleExpression) arguments).getExpressions();
        if (expressions.size() == 1 && expressions.get(0) instanceof MapExpression) {
            MapExpression map = (MapExpression) expressions.get(0);
            List<MapEntryExpression> entries = map.getMapEntryExpressions();
            if (entries.size() == 1) {
                MapEntryExpression mapEntry = entries.get(0);
                Expression keyExpression = mapEntry.getKeyExpression();
                try {
                    IncludeType includeType = IncludeType.valueOf(keyExpression.getText().toLowerCase());
                    MethodCallExpression call = new MethodCallExpression(
                            exp.getObjectExpression(),
                            includeType.getMethodName(),
                            new ArgumentListExpression(
                                    mapEntry.getValueExpression()
                            )
                    );
                    call.setImplicitThis(true);
                    call.setSafe(exp.isSafe());
                    call.setSpreadSafe(exp.isSpreadSafe());
                    call.setSourcePosition(exp);
                    return call;
                } catch (IllegalArgumentException e) {
                    // not a valid import type, do not modify the code
                }
            }

        }
    }
    return super.transform(exp);
}
 
开发者ID:apache,项目名称:groovy,代码行数:34,代码来源:MarkupBuilderCodeTransformer.java

示例4: visitMethodCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(MethodCallExpression mce) {
    if (inSpecialConstructorCall && !isInnerClass(currentMethod.getDeclaringClass())) {
        Expression objectExpression = mce.getObjectExpression();
        if (objectExpression instanceof VariableExpression) {
            VariableExpression ve = (VariableExpression) objectExpression;
            if (ve.isThisExpression()) {
                addError("Can't access instance method '" + mce.getMethodAsString() + "' before the class is constructed", mce);
                return;
            }
        }
    }
    super.visitMethodCallExpression(mce);
}
 
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:StaticVerifier.java

示例5: visitMethodCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
public void visitMethodCallExpression(final MethodCallExpression call) {
    assertExpressionAuthorized(call);
    Expression receiver = call.getObjectExpression();
    final String typeName = receiver.getType().getName();
    if (receiversWhiteList != null && !receiversWhiteList.contains(typeName)) {
        throw new SecurityException("Method calls not allowed on [" + typeName + "]");
    } else if (receiversBlackList != null && receiversBlackList.contains(typeName)) {
        throw new SecurityException("Method calls not allowed on [" + typeName + "]");
    }
    receiver.visit(this);
    final Expression method = call.getMethod();
    checkConstantTypeIfNotMethodNameOrProperty(method);
    call.getArguments().visit(this);
}
 
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:SecureASTCustomizer.java

示例6: transformMethodCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCallExpression(final MethodCallExpression exp) {
    if (isTraitSuperPropertyExpression(exp.getObjectExpression())) {
        Expression objectExpression = exp.getObjectExpression();
        ClassNode traitReceiver = ((PropertyExpression) objectExpression).getObjectExpression().getType();

        if (traitReceiver != null) {
            // (SomeTrait.super).foo() --> SomeTrait$Helper.foo(this)
            ClassExpression receiver = new ClassExpression(
                    getHelper(traitReceiver)
            );
            ArgumentListExpression newArgs = new ArgumentListExpression();
            Expression arguments = exp.getArguments();
            newArgs.addExpression(new VariableExpression("this"));
            if (arguments instanceof TupleExpression) {
                List<Expression> expressions = ((TupleExpression) arguments).getExpressions();
                for (Expression expression : expressions) {
                    newArgs.addExpression(transform(expression));
                }
            } else {
                newArgs.addExpression(transform(arguments));
            }
            MethodCallExpression result = new MethodCallExpression(
                    receiver,
                    transform(exp.getMethod()),
                    newArgs
            );
            result.setImplicitThis(false);
            result.setSpreadSafe(exp.isSpreadSafe());
            result.setSafe(exp.isSafe());
            result.setSourcePosition(exp);
            return result;
        }
    }
    return super.transform(exp);
}
 
开发者ID:apache,项目名称:groovy,代码行数:36,代码来源:SuperCallTraitTransformer.java

示例7: isBuildInvocation

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
/**
 * Looks for method calls on the AstBuilder class called build that take
 * a Closure as parameter. This is all needed b/c build is overloaded.
 *
 * @param call the method call expression, may not be null
 */
@Override
protected boolean isBuildInvocation(MethodCallExpression call) {
    if (call == null) throw new IllegalArgumentException("Null: call");

    // is method name correct?
    if (call.getMethod() instanceof ConstantExpression && "buildFromCode".equals(((ConstantExpression) call.getMethod()).getValue())) {

        // is method object correct type?
        if (call.getObjectExpression() != null && call.getObjectExpression().getType() != null) {
            String name = call.getObjectExpression().getType().getName();
            if (name != null && !"".equals(name) && factoryTargets.contains(name)) {

                // is one of the arguments a closure?
                if (call.getArguments() != null && call.getArguments() instanceof TupleExpression) {
                    if (((TupleExpression) call.getArguments()).getExpressions() != null) {
                        for (ASTNode node : ((TupleExpression) call.getArguments()).getExpressions()) {
                            if (node instanceof ClosureExpression) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:groovy,代码行数:34,代码来源:AstBuilderTransformation.java

示例8: visitMethodCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(MethodCallExpression expression) {
    if (expression.getNodeMetaData(StatementMeta.class)!=null) return;
    super.visitMethodCallExpression(expression);

    Expression object = expression.getObjectExpression();
    boolean setTarget = AsmClassGenerator.isThisExpression(object);
    if (!setTarget) {
        if (!(object instanceof ClassExpression)) return;
        setTarget = object.equals(node);
    }

    if (!setTarget) return;
    setMethodTarget(expression, expression.getMethodAsString(), expression.getArguments(), true);
}
 
开发者ID:apache,项目名称:groovy,代码行数:16,代码来源:OptimizingStatementWriter.java

示例9: usesSuper

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static boolean usesSuper(MethodCallExpression call) {
    Expression expression = call.getObjectExpression();
    if (expression instanceof VariableExpression) {
        VariableExpression varExp = (VariableExpression) expression;
        String variable = varExp.getName();
        return variable.equals("super");
    }
    return false;
}
 
开发者ID:apache,项目名称:groovy,代码行数:10,代码来源:InvocationWriter.java

示例10: transformMethodCall

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCall(final MethodCallExpression exp) {
    String name = exp.getMethodAsString();
    if (exp.isImplicitThis() && "include".equals(name)) {
        return tryTransformInclude(exp);
    } else if (exp.isImplicitThis() && name.startsWith(":")) {
        List<Expression> args;
        if (exp.getArguments() instanceof ArgumentListExpression) {
            args = ((ArgumentListExpression) exp.getArguments()).getExpressions();
        } else {
            args = Collections.singletonList(exp.getArguments());
        }
        Expression newArguments = transform(new ArgumentListExpression(new ConstantExpression(name.substring(1)), new ArrayExpression(ClassHelper.OBJECT_TYPE, args)));
        MethodCallExpression call = new MethodCallExpression(
                new VariableExpression("this"),
                "methodMissing",
                newArguments
        );
        call.setImplicitThis(true);
        call.setSafe(exp.isSafe());
        call.setSpreadSafe(exp.isSpreadSafe());
        call.setSourcePosition(exp);
        return call;
    } else if (name!=null && name.startsWith("$")) {
        MethodCallExpression reformatted = new MethodCallExpression(
                exp.getObjectExpression(),
                name.substring(1),
                exp.getArguments()
        );
        reformatted.setImplicitThis(exp.isImplicitThis());
        reformatted.setSafe(exp.isSafe());
        reformatted.setSpreadSafe(exp.isSpreadSafe());
        reformatted.setSourcePosition(exp);
        // wrap in a stringOf { ... } closure call
        ClosureExpression clos = new ClosureExpression(Parameter.EMPTY_ARRAY, new ExpressionStatement(reformatted));
        clos.setVariableScope(new VariableScope());
        MethodCallExpression stringOf = new MethodCallExpression(new VariableExpression("this"),
                "stringOf",
                clos);
        stringOf.setImplicitThis(true);
        stringOf.setSourcePosition(reformatted);
        return stringOf;
    }
    return super.transform(exp);
}
 
开发者ID:apache,项目名称:groovy,代码行数:45,代码来源:MarkupBuilderCodeTransformer.java

示例11: isNewifyCandidate

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private boolean isNewifyCandidate(MethodCallExpression mce) {
    return mce.getObjectExpression() == VariableExpression.THIS_EXPRESSION
            || (auto && isNewMethodStyle(mce));
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:NewifyASTTransformation.java

示例12: isNewMethodStyle

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static boolean isNewMethodStyle(MethodCallExpression mce) {
    final Expression obj = mce.getObjectExpression();
    final Expression meth = mce.getMethod();
    return (obj instanceof ClassExpression && meth instanceof ConstantExpression
            && ((ConstantExpression) meth).getValue().equals("new"));
}
 
开发者ID:apache,项目名称:groovy,代码行数:7,代码来源:NewifyASTTransformation.java

示例13: targetIsThis

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
public static boolean targetIsThis(MethodCallExpression call) {
    Expression target = call.getObjectExpression();
    return target instanceof VariableExpression && target.getText().equals("this");
}
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:5,代码来源:AstUtils.java


注:本文中的org.codehaus.groovy.ast.expr.MethodCallExpression.getObjectExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。