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


Java MethodCallExpression.setSpreadSafe方法代码示例

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


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

示例1: tryMacroMethod

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
/**
 * Attempts to call given macroMethod
 * @param call MethodCallExpression before the transformation
 * @param macroMethod a macro method candidate
 * @param macroArguments arguments to pass to
 * @return true if call succeeded and current call was transformed
 */
private boolean tryMacroMethod(MethodCallExpression call, ExtensionMethodNode macroMethod, Object[] macroArguments) {
    Expression result = (Expression) InvokerHelper.invokeStaticMethod(
        macroMethod.getExtensionMethodNode().getDeclaringClass().getTypeClass(),
        macroMethod.getName(),
        macroArguments
    );

    if (result == null) {
        // Allow macro methods to return null as an indicator that they didn't match a method call
        return false;
    }

    call.setObjectExpression(MACRO_STUB_INSTANCE);
    call.setMethod(new ConstantExpression(MACRO_STUB_METHOD_NAME));

    // TODO check that we reset everything here
    call.setSpreadSafe(false);
    call.setSafe(false);
    call.setImplicitThis(false);
    call.setArguments(result);
    call.setGenericsTypes(new GenericsType[0]);

    return true;
}
 
开发者ID:apache,项目名称:groovy,代码行数:32,代码来源:MacroCallTransformingVisitor.java

示例2: createMethodCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private MethodCallExpression createMethodCallExpression(PropertyExpression propertyExpression, Expression arguments) {
    MethodCallExpression methodCallExpression =
            new MethodCallExpression(
                    propertyExpression.getObjectExpression(),
                    propertyExpression.getProperty(),
                    arguments
            );

    methodCallExpression.setImplicitThis(false);
    methodCallExpression.setSafe(propertyExpression.isSafe());
    methodCallExpression.setSpreadSafe(propertyExpression.isSpreadSafe());

    // method call obj*.m(): "safe"(false) and "spreadSafe"(true)
    // property access obj*.p: "safe"(true) and "spreadSafe"(true)
    // so we have to reset safe here.
    if (propertyExpression.isSpreadSafe()) {
        methodCallExpression.setSafe(false);
    }

    // if the generics types meta data is not empty, it is a generic method call, e.g. obj.<Integer>a(1, 2)
    methodCallExpression.setGenericsTypes(
            propertyExpression.getNodeMetaData(PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES));

    return methodCallExpression;
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:AstBuilder.java

示例3: transformMethodCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
protected Expression transformMethodCallExpression(MethodCallExpression mce) {
    Expression args = transform(mce.getArguments());
    Expression method = transform(mce.getMethod());
    Expression object = transform(mce.getObjectExpression());

    resolveGenericsTypes(mce.getGenericsTypes());
    
    MethodCallExpression result = new MethodCallExpression(object, method, args);
    result.setSafe(mce.isSafe());
    result.setImplicitThis(mce.isImplicitThis());
    result.setSpreadSafe(mce.isSpreadSafe());
    result.setSourcePosition(mce);
    result.setGenericsTypes(mce.getGenericsTypes());
    result.setMethodTarget(mce.getMethodTarget());
    return result;
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:ResolveVisitor.java

示例4: transformToMopSuperCall

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

示例5: handleTargetMethodCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
protected boolean handleTargetMethodCallExpression(MethodCallExpression call) {
    ClosureExpression closureExpression = getClosureArgument(call);
    List<Expression> otherArgs = getNonClosureArguments(call);
    String source = convertClosureToSource(closureExpression);

    // parameter order is build(CompilePhase, boolean, String)
    otherArgs.add(new ConstantExpression(source));
    call.setArguments(new ArgumentListExpression(otherArgs));
    call.setMethod(new ConstantExpression("buildFromBlock"));
    call.setSpreadSafe(false);
    call.setSafe(false);
    call.setImplicitThis(false);
    
    return false;
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:AstBuilderTransformation.java

示例6: 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

示例7: visitConstructorCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
public void visitConstructorCallExpression(final ConstructorCallExpression call) {
    ClassNode type = call.getType();
    if (type instanceof InnerClassNode) {
        if (((InnerClassNode) type).isAnonymous() &&
                MACROCLASS_TYPE.getNameWithoutPackage().equals(type.getSuperClass().getNameWithoutPackage())) {
            try {
                String source = convertInnerClassToSource(type);

                MethodCallExpression macroCall = callX(
                        propX(classX(ClassHelper.makeWithoutCaching(MacroBuilder.class, false)), "INSTANCE"),
                        MACRO_METHOD,
                        args(
                                constX(source),
                                MacroGroovyMethods.buildSubstitutions(sourceUnit, type),
                                classX(ClassHelper.make(ClassNode.class))
                        )
                );

                macroCall.setSpreadSafe(false);
                macroCall.setSafe(false);
                macroCall.setImplicitThis(false);
                call.putNodeMetaData(MacroTransformation.class, macroCall);
                List<ClassNode> classes = sourceUnit.getAST().getClasses();
                for (Iterator<ClassNode> iterator = classes.iterator(); iterator.hasNext(); ) {
                    final ClassNode aClass = iterator.next();
                    if (aClass == type || type == aClass.getOuterClass()) {
                        iterator.remove();
                    }
                }
            } catch (Exception e) {
                // FIXME
                e.printStackTrace();
            }
            return;
        }
    }
    super.visitConstructorCallExpression(call);

}
 
开发者ID:apache,项目名称:groovy,代码行数:41,代码来源:MacroClassTransformation.java

示例8: 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

示例9: transformSuperMethodCall

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformSuperMethodCall(final MethodCallExpression call) {
    String method = call.getMethodAsString();
    if (method == null) {
        throwSuperError(call);
    }

    Expression arguments = transform(call.getArguments());
    ArgumentListExpression superCallArgs = new ArgumentListExpression();
    if (arguments instanceof ArgumentListExpression) {
        ArgumentListExpression list = (ArgumentListExpression) arguments;
        for (Expression expression : list) {
            superCallArgs.addExpression(expression);
        }
    } else {
        superCallArgs.addExpression(arguments);
    }
    MethodCallExpression transformed = new MethodCallExpression(
            weaved,
            Traits.getSuperTraitMethodName(traitClass, method),
            superCallArgs
    );
    transformed.setSourcePosition(call);
    transformed.setSafe(call.isSafe());
    transformed.setSpreadSafe(call.isSpreadSafe());
    transformed.setImplicitThis(false);
    return transformed;
}
 
开发者ID:apache,项目名称:groovy,代码行数:28,代码来源:TraitReceiverTransformer.java

示例10: transformMethodCallOnThisFallBack

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCallOnThisFallBack(final MethodCallExpression call,
                                                     final Expression method, final Expression arguments) {
    MethodCallExpression transformed = new MethodCallExpression(
            weaved,
            method,
            transform(arguments)
    );
    transformed.setSourcePosition(call);
    transformed.setSafe(call.isSafe());
    transformed.setSpreadSafe(call.isSpreadSafe());
    transformed.setImplicitThis(false);
    return transformed;
}
 
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:TraitReceiverTransformer.java

示例11: transformMethodCallOnThisInClosure

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCallOnThisInClosure(final MethodCallExpression call) {
    MethodCallExpression transformed = new MethodCallExpression(
            (Expression) call.getReceiver(),
            call.getMethod(),
            transform(call.getArguments())
    );
    transformed.setSourcePosition(call);
    transformed.setSafe(call.isSafe());
    transformed.setSpreadSafe(call.isSpreadSafe());
    transformed.setImplicitThis(call.isImplicitThis());
    return transformed;
}
 
开发者ID:apache,项目名称:groovy,代码行数:13,代码来源:TraitReceiverTransformer.java

示例12: transformPrivateMethodCallOnThis

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformPrivateMethodCallOnThis(final MethodCallExpression call,
                                                    final Expression arguments, final String methodName) {
    ArgumentListExpression newArgs = createArgumentList(arguments);
    MethodCallExpression transformed = new MethodCallExpression(
            new VariableExpression("this"),
            methodName,
            newArgs
    );
    transformed.setSourcePosition(call);
    transformed.setSafe(call.isSafe());
    transformed.setSpreadSafe(call.isSpreadSafe());
    transformed.setImplicitThis(true);
    return transformed;
}
 
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:TraitReceiverTransformer.java

示例13: transformPrivateMethodCallOnThisInClosure

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformPrivateMethodCallOnThisInClosure(final MethodCallExpression call,
                                                             final Expression arguments, final String methodName) {
    ArgumentListExpression newArgs = createArgumentList(arguments);
    MethodCallExpression transformed = new MethodCallExpression(
            new ClassExpression(traitHelperClass),
            methodName,
            newArgs
    );
    transformed.setSourcePosition(call);
    transformed.setSafe(call.isSafe());
    transformed.setSpreadSafe(call.isSpreadSafe());
    transformed.setImplicitThis(true);
    return transformed;
}
 
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:TraitReceiverTransformer.java

示例14: 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


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