@Override public void expand() { List<Expression> args = new ArrayList<>(); args.add(inferredName); args.add(inferredType); args.addAll(AstUtil.getArgumentList(methodCallExpr)); ArgumentListExpression argsExpr = new ArgumentListExpression(args); AstUtil.copySourcePosition(methodCallExpr.getArguments(), argsExpr); methodCallExpr.setArguments(argsExpr); methodCallExpr.setMethod(new ConstantExpression(methodName + "Impl")); }
private boolean handleImplicitCallOnMethodParam(MethodCallExpression expr) { if (!expr.isImplicitThis()) return false; String methodName = expr.getMethodAsString(); List<Parameter> params = Arrays.asList(resources.getCurrentMethod().getAst().getParameters()); for (Parameter param : params) { if (param.getName().equals(methodName)) { expr.setMethod(new ConstantExpression("call")); expr.setObjectExpression(new VariableExpression(methodName)); return true; } } return false; }
private boolean handleOldCall(MethodCallExpression expr) { if (!currSpecialMethodCall.isOldCall(expr)) return false; if (!(block instanceof ThenBlock)) { resources.getErrorReporter().error(expr, "old() is only allowed in 'then' blocks"); return true; } expr.setMethod(new ConstantExpression(expr.getMethodAsString() + "Impl")); List<Expression> args = AstUtil.getArgumentList(expr); VariableExpression oldValue = resources.captureOldValue(args.get(0)); args.set(0, oldValue); if (currClosure != null) { oldValue.setClosureSharedVariable(true); currClosure.getVariableScope().putReferencedLocalVariable(oldValue); } return true; }
@Override public void visitMethodCallExpression(MethodCallExpression expr) { expr.setObjectExpression(replaceExpr(expr.getObjectExpression())); expr.setMethod(replaceExpr(expr.getMethod())); expr.setArguments(replaceExpr(expr.getArguments())); }
@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; }
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); }
public void visitMethodCallExpression(MethodCallExpression ex){ if(isTagCall(ex)){ //System.out.println("FOUND TAG CALL "+ex+" and rewriting "); List<Expression> args = ((TupleExpression)ex.getArguments()).getExpressions(); List<Expression> newArgs= new ArrayList<>(); newArgs.add(new ConstantExpression(ex.getMethodAsString())); newArgs.addAll(args); //Automatically add a closure so that scope is available to the tag if(newArgs.size()==0 || !(newArgs.get(newArgs.size()-1) instanceof ClosureExpression)){ newArgs.add(new ClosureExpression(new Parameter[0], new EmptyStatement())); } ex.setArguments(new TupleExpression(newArgs)); ex.setMethod(new ConstantExpression(TAG)); } super.visitMethodCallExpression(ex); } }
public void visitMethodCallExpression(MethodCallExpression ex){ if(isTagCall(ex)){ //System.out.println("FOUND TAG CALL "+ex+" and rewriting "); List<Expression> args = ((TupleExpression)ex.getArguments()).getExpressions(); List<Expression> newArgs= new ArrayList<>(); newArgs.add(new ConstantExpression(ex.getMethodAsString())); newArgs.addAll(args); //Automatically add a closure so that scope is available to the tag if(newArgs.size()==0 || !(newArgs.get(newArgs.size()-1) instanceof ClosureExpression)){ newArgs.add(new ClosureExpression(new Parameter[0], new EmptyStatement())); } ex.setArguments(new TupleExpression(newArgs)); ex.setMethod(new ConstantExpression(TAG)); } super.visitMethodCallExpression(ex); } }
private void transformVariableExpression(MethodCallExpression call, int index) { ArgumentListExpression args = (ArgumentListExpression) call.getArguments(); VariableExpression arg = (VariableExpression) args.getExpression(index); if (!isDynamicVar(arg)) { return; } // Matches: task args?, <identifier>, args? or task(args?, <identifier>, args?) // Map to: task(args?, '<identifier>', args?) String taskName = arg.getText(); call.setMethod(new ConstantExpression("task")); args.getExpressions().set(index, new ConstantExpression(taskName)); }
@Override public void visitMethodCallExpression(MethodCallExpression expr) { expr.setObjectExpression(replaceExpr(expr.getObjectExpression())); expr.setMethod(replaceExpr(expr.getMethod())); expr.setArguments(replaceExpr(expr.getArguments())); }
target.setMethod(new ConstantExpression("task")); ArgumentListExpression args = (ArgumentListExpression) target.getArguments(); args.getExpressions().clear();
@Override public Expression transform(Expression exp) { if ( exp instanceof MethodCallExpression) { MethodCallExpression me = (MethodCallExpression)exp; Class jeClazz = gtJavaExtensionMethodResolver.findClassWithMethod(me.getMethodAsString()); if (jeClazz != null) { ClassExpression ce = new ClassExpression( new ClassNode(GTJavaExtensionsInvoker.class)); ArgumentListExpression newArgs = new ArgumentListExpression(); ArgumentListExpression args = (ArgumentListExpression)me.getArguments(); newArgs.getExpressions().add(new ClassExpression( new ClassNode(jeClazz))); newArgs.getExpressions().add(new ConstantExpression(me.getMethodAsString())); newArgs.getExpressions().add(me.getObjectExpression()); newArgs.getExpressions().add( new ArrayExpression( new ClassNode(Object.class), args.getExpressions())); me.setMethod( new ConstantExpression("invoke")); me.setArguments(newArgs); me.setObjectExpression(ce); return exp.transformExpression(this); } } return super.transform(exp); } }
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); call.setMethod(CALL); } } super.visitMethodCallExpression(call); }
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); call.setMethod(CALL); } } super.visitMethodCallExpression(call); }
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); call.setMethod(CALL); } } super.visitMethodCallExpression(call); }
private void transformBinaryExpression(MethodCallExpression call, BinaryExpression expression) { // Matches: task <expression> <operator> <expression> if (expression.getLeftExpression() instanceof VariableExpression || expression.getLeftExpression() instanceof GStringExpression || expression .getLeftExpression() instanceof ConstantExpression) { // Matches: task <identifier> <operator> <expression> | task <string> <operator> <expression> // Map to: passThrough(task('<identifier>') <operator> <expression>) | passThrough(task(<string>) <operator> <expression>) call.setMethod(new ConstantExpression("passThrough")); Expression argument; if (expression.getLeftExpression() instanceof VariableExpression) { argument = new ConstantExpression(expression.getLeftExpression().getText()); } else { argument = expression.getLeftExpression(); } expression.setLeftExpression(new MethodCallExpression(call.getObjectExpression(), "task", argument)); } else if (expression.getLeftExpression() instanceof MethodCallExpression) { // Matches: task <method-call> <operator> <expression> MethodCallExpression transformedCall = new MethodCallExpression(call.getObjectExpression(), "task", new ArgumentListExpression()); boolean transformed = maybeTransformNestedMethodCall((MethodCallExpression) expression.getLeftExpression(), transformedCall); if (transformed) { // Matches: task <identifier> <arg-list> <operator> <expression> // Map to: passThrough(task('<identifier>', <arg-list>) <operator> <expression>) call.setMethod(new ConstantExpression("passThrough")); expression.setLeftExpression(transformedCall); } } }
/** * 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) { if (isBuildInvocation(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); } else { // continue normal tree walking call.getObjectExpression().visit(this); call.getMethod().visit(this); call.getArguments().visit(this); } }
call.setMethod(new ConstantExpression(MACRO_STUB_METHOD_NAME));
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.setMethod(method); } } super.visitMethodCallExpression(call); }
if (AstUtils.isDomainClass(currentClassNode)) { visitMethodCall(this.currentClassNode, arguments); call.setMethod(WHERE_LAZY);