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")); }
@Override public void visitMethodCallExpression(MethodCallExpression expr) { TextPosition anchor = TextPosition.startOf(expr.getMethod()); List<ExpressionInfo> children = new ArrayList<>(); if (!expr.isImplicitThis()) children.add(convert(expr.getObjectExpression())); children.add(convert(expr.getMethod())); children.add(convert(expr.getArguments())); result = new ExpressionInfo( TextRegion.of(expr), anchor, expr.getMethodAsString(), children); }
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; }
private void setMethodName() { Expression methodNameExpr = ((MethodCallExpression) call).getMethod(); String constraint = selectNameConstraint(methodNameExpr, InteractionBuilder.ADD_EQUAL_METHOD_NAME, InteractionBuilder.ADD_REGEX_METHOD_NAME); call(constraint, methodNameExpr); }
@Override public void visitMethodCallExpression(MethodCallExpression expr) { // at runtime, condition AST is only parsed up to phase conversion, // and hence looks differently in cases where groovyc inserts ".call" // in phase semantic analysis; we need to compensate for that // (in other cases, ".call" is only inserted after transform has // run, and hence we don't need to compensate) boolean objectExprSeenAsMethodNameAtRuntime = !expr.isImplicitThis() && expr.getObjectExpression() instanceof VariableExpression && "call".equals(expr.getMethodAsString()) && (!AstUtil.hasPlausibleSourcePosition(expr.getMethod()) // before GROOVY-4344 fix || (expr.getMethod().getColumnNumber() == expr.getObjectExpression().getColumnNumber())); // after GROOVY-4344 fix MethodCallExpression conversion = new MethodCallExpression( expr.isImplicitThis() ? expr.getObjectExpression() : convert(expr.getObjectExpression()), objectExprSeenAsMethodNameAtRuntime ? expr.getMethod() : convert(expr.getMethod()), convert(expr.getArguments())); conversion.setSafe(expr.isSafe()); conversion.setSpreadSafe(expr.isSpreadSafe()); conversion.setSourcePosition(expr); result = record(conversion); }
private void rewriteArgumentList(MethodCallExpression call, ClassExpression objectExpression) { if (SpockRuntime.class.getName().equals(objectExpression.getType().getName())) { String methodName = call.getMethod().getText(); if (REWRITE_METHOD_ARGS.contains(methodName)) { List<Expression> arguments = new ArrayList<>(((ArgumentListExpression)call.getArguments()).getExpressions()); Expression expression = arguments.get(0); if (expression instanceof VariableExpression && isErrorCollectorExpression(((VariableExpression)expression))) { arguments.set(0, errorCollectorExpression()); } expression = arguments.get(1); if (expression instanceof VariableExpression && isValueRecorderExpression(((VariableExpression)expression))) { arguments.set(1, valueRecorderExpression()); } call.setArguments(new ArgumentListExpression(arguments)); } } }
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); }
private Statement rewriteMethodCondition(MethodCallExpression condition, Expression message, boolean explicit) { MethodCallExpression rewritten; int lastVariableNum; final Expression converted = convert(condition); rewritten = (MethodCallExpression) unrecord(converted); lastVariableNum = extractVariableNumber(converted); List<Expression> args = new ArrayList<>(); args.add(rewritten.getObjectExpression()); args.add(rewritten.getMethod()); args.add(AstUtil.toArgumentArray(AstUtil.getArgumentList(rewritten), resources)); // rewriting has produced N/A's that haven't been realized yet, so do that now args.add(realizeNas(new ConstantExpression(rewritten.isSafe()))); args.add(new ConstantExpression(explicit)); args.add(new ConstantExpression(lastVariableNum)); return surroundWithTryCatch( condition, message, rewriteToSpockRuntimeCall( resources.getAstNodeCache().SpockRuntime_VerifyMethodCondition, condition, message, args)); }
public void visitMethodCallExpression(MethodCallExpression call) { call.getObjectExpression().visit(this); call.getMethod().visit(this); call.getArguments().visit(this); }
@Override public void visitMethodCallExpression(final MethodCallExpression call) { boolean old = inBuilderMethod; inBuilderMethod = false; if (call.isImplicitThis() && call.getArguments() instanceof TupleExpression) { List<Expression> expressions = ((TupleExpression) call.getArguments()).getExpressions(); if (!expressions.isEmpty()) { Expression lastArg = expressions.get(expressions.size() - 1); if (lastArg instanceof ClosureExpression) { call.getObjectExpression().visit(this); call.getMethod().visit(this); for (Expression expression : expressions) { inBuilderMethod = (expression == lastArg); expression.visit(this); } } } } else { super.visitMethodCallExpression(call); } inBuilderMethod = old; }
@Override public void visitMethodCallExpression(MethodCallExpression expr) { expr.setObjectExpression(replaceExpr(expr.getObjectExpression())); expr.setMethod(replaceExpr(expr.getMethod())); expr.setArguments(replaceExpr(expr.getArguments())); }
private Expression transformMethodCallOnThis(final MethodCallExpression call) { Expression method = call.getMethod(); Expression arguments = call.getArguments(); if (method instanceof ConstantExpression) { String methodName = method.getText(); List<MethodNode> methods = traitClass.getMethods(methodName); for (MethodNode methodNode : methods) { if (methodName.equals(methodNode.getName()) && methodNode.isPrivate()) { if (inClosure) { return transformPrivateMethodCallOnThisInClosure(call, arguments, methodName); } return transformPrivateMethodCallOnThis(call, arguments, methodName); } } } if (inClosure) { return transformMethodCallOnThisInClosure(call); } return transformMethodCallOnThisFallBack(call, method, arguments); }
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); }
/** * Attempts to find AstBuilder 'from code' invocations. When found, converts them into calls * to the 'from string' approach. * * @param call the method call expression that may or may not be an AstBuilder 'from code' invocation. */ public void visitMethodCallExpression(MethodCallExpression call) { boolean shouldContinueWalking = true; if (isBuildInvocation(call)) { shouldContinueWalking = handleTargetMethodCallExpression(call); } if(shouldContinueWalking) { // continue normal tree walking call.getObjectExpression().visit(this); call.getMethod().visit(this); call.getArguments().visit(this); } }
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; }
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() ); } }
transform(exp.getMethod()), newArgs );
return transformed; Expression method = transform(mce.getMethod()); Expression object = transform(mce.getObjectExpression()); MethodCallExpression transformed = callX(object, method, args);