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


Java MethodCallExpression.setImplicitThis方法代码示例

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


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

示例3: buildMemoizeClosureCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static MethodCallExpression buildMemoizeClosureCallExpression(MethodNode privateMethod,
                                                               int protectedCacheSize, int maxCacheSize) {
    Parameter[] srcParams = privateMethod.getParameters();
    Parameter[] newParams = cloneParams(srcParams);
    List<Expression> argList = new ArrayList<Expression>(newParams.length);
    for (int i = 0; i < srcParams.length; i++) {
        argList.add(varX(newParams[i]));
    }

    ClosureExpression expression = new ClosureExpression(
            newParams,
            stmt(callThisX(privateMethod.getName(), args(argList)))
    );
    MethodCallExpression mce;
    if (protectedCacheSize == 0 && maxCacheSize == 0) {
        mce = callX(expression, MEMOIZE_METHOD_NAME);
    } else if (protectedCacheSize == 0) {
        mce = callX(expression, MEMOIZE_AT_MOST_METHOD_NAME, args(constX(maxCacheSize)));
    } else if (maxCacheSize == 0) {
        mce = callX(expression, MEMOIZE_AT_LEAST_METHOD_NAME, args(constX(protectedCacheSize)));
    } else {
        mce = callX(expression, MEMOIZE_BETWEEN_METHOD_NAME, args(constX(protectedCacheSize), constX(maxCacheSize)));
    }
    mce.setImplicitThis(false);
    return mce;
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:MemoizedASTTransformation.java

示例4: visitMethodCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
public void visitMethodCallExpression(MethodCallExpression call) {
    if (call.isImplicitThis() && call.getMethod() instanceof ConstantExpression) {
        ConstantExpression methodNameConstant = (ConstantExpression) call.getMethod();
        Object value = methodNameConstant.getText();

        if (!(value instanceof String)) {
            throw new GroovyBugError("tried to make a method call with a non-String constant method name.");
        }

        String methodName = (String) value;
        Variable v = checkVariableNameForDeclaration(methodName, call);
        if (v != null && !(v instanceof DynamicVariable)) {
            checkVariableContextAccess(v, call);
        }

        if (v instanceof VariableExpression || v instanceof Parameter) {
            VariableExpression object = new VariableExpression(v);
            object.setSourcePosition(methodNameConstant);
            call.setObjectExpression(object);
            ConstantExpression method = new ConstantExpression("call");
            method.setSourcePosition(methodNameConstant); // important for GROOVY-4344
            call.setImplicitThis(false);
            call.setMethod(method);
        }

    }
    super.visitMethodCallExpression(call);
}
 
开发者ID:apache,项目名称:groovy,代码行数:29,代码来源:VariableScopeVisitor.java

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

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

示例7: createNewLine

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Statement createNewLine(final ASTNode node) {
    MethodCallExpression mce = new MethodCallExpression(
            new VariableExpression("this"),
            "newLine",
            ArgumentListExpression.EMPTY_ARGUMENTS
    );
    mce.setImplicitThis(true);
    mce.setSourcePosition(node);
    ExpressionStatement stmt = new ExpressionStatement(mce);
    stmt.setSourcePosition(node);
    return stmt;
}
 
开发者ID:apache,项目名称:groovy,代码行数:13,代码来源:AutoNewLineTransformer.java

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

示例9: createWriteExternal

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static void createWriteExternal(ClassNode cNode, List<String> excludes, List<FieldNode> list) {
    final BlockStatement body = new BlockStatement();
    Parameter out = param(OBJECTOUTPUT_TYPE, "out");
    for (FieldNode fNode : list) {
        if (excludes != null && excludes.contains(fNode.getName())) continue;
        if ((fNode.getModifiers() & ACC_TRANSIENT) != 0) continue;
        MethodCallExpression writeObject = callX(varX(out), "write" + suffixForField(fNode), varX(fNode));
        writeObject.setImplicitThis(false);
        body.addStatement(stmt(writeObject));
    }
    ClassNode[] exceptions = {make(IOException.class)};
    cNode.addMethod("writeExternal", ACC_PUBLIC, ClassHelper.VOID_TYPE, params(out), exceptions, body);
}
 
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:ExternalizeMethodsASTTransformation.java

示例10: createAddSuppressedStatement

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private ExpressionStatement createAddSuppressedStatement(String primaryExcName, String suppressedExcName) {
    MethodCallExpression addSuppressedMethodCallExpression =
            new MethodCallExpression(
                    new VariableExpression(primaryExcName),
                    "addSuppressed",
                    new ArgumentListExpression(Collections.singletonList(new VariableExpression(suppressedExcName))));
    addSuppressedMethodCallExpression.setImplicitThis(false);
    addSuppressedMethodCallExpression.setSafe(true);

    return new ExpressionStatement(addSuppressedMethodCallExpression);
}
 
开发者ID:apache,项目名称:groovy,代码行数:12,代码来源:TryWithResourcesASTTransformation.java

示例11: createCallMethodCallExpression

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private MethodCallExpression createCallMethodCallExpression(Expression baseExpr, Expression argumentsExpr, boolean implicitThis) {
    MethodCallExpression methodCallExpression =
            new MethodCallExpression(baseExpr, CALL_STR, argumentsExpr);

    methodCallExpression.setImplicitThis(implicitThis);

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

示例12: createReadExternal

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static void createReadExternal(ClassNode cNode, List<String> excludes, List<FieldNode> list) {
    final BlockStatement body = new BlockStatement();
    Parameter oin = param(OBJECTINPUT_TYPE, "oin");
    for (FieldNode fNode : list) {
        if (excludes != null && excludes.contains(fNode.getName())) continue;
        if ((fNode.getModifiers() & ACC_TRANSIENT) != 0) continue;
        String suffix = suffixForField(fNode);
        MethodCallExpression readObject = callX(varX(oin), "read" + suffix);
        readObject.setImplicitThis(false);
        body.addStatement(assignS(varX(fNode), suffix.equals("Object") ? castX(GenericsUtils.nonGeneric(fNode.getType()), readObject) : readObject));
    }
    cNode.addMethod("readExternal", ACC_PUBLIC, ClassHelper.VOID_TYPE, params(oin), ClassNode.EMPTY_ARRAY, body);
}
 
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:ExternalizeMethodsASTTransformation.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: createFieldHelperCall

import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression createFieldHelperCall(Expression exp, ClassNode weavedType, String propName) {
    String method = Traits.helperGetterName(new FieldNode(propName, 0, ClassHelper.OBJECT_TYPE, weavedType, null));
    MethodCallExpression mce = new MethodCallExpression(
            createFieldHelperReceiver(),
            method,
            ArgumentListExpression.EMPTY_ARGUMENTS
    );
    mce.setSourcePosition(exp);
    mce.setImplicitThis(false);
    return mce;
}
 
开发者ID:apache,项目名称:groovy,代码行数:12,代码来源:TraitReceiverTransformer.java

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


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