public static boolean isInvocationWithImplicitThis(Expression invocation) { if (invocation instanceof PropertyExpression) { return ((PropertyExpression) invocation).isImplicitThis(); } if (invocation instanceof MethodCallExpression) { return ((MethodCallExpression) invocation).isImplicitThis(); } return false; }
@Override public void visitMethodCallExpression(MethodCallExpression node) { if (node.isImplicitThis()) { doVisitMethodCall(node); } super.visitMethodCallExpression(node); }
private static boolean isCallOnClosure(final MethodCallExpression expr) { MethodNode target = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); return expr.isImplicitThis() && !"call".equals(expr.getMethodAsString()) && (target == StaticTypeCheckingVisitor.CLOSURE_CALL_VARGS || target == StaticTypeCheckingVisitor.CLOSURE_CALL_NO_ARG || target == StaticTypeCheckingVisitor.CLOSURE_CALL_ONE_ARG); }
public void visitMethodCallExpression(MethodCallExpression methodCall) { if (defaultScriptMethods.contains(methodCall.getMethodAsString())) { visited = true; isImplicitThis = methodCall.isImplicitThis(); } }
private boolean isStaticInvocation(MethodCallExpression call) { if (!AsmClassGenerator.isThisExpression(call.getObjectExpression())) return false; if (controller.isStaticMethod()) return true; return controller.isStaticContext() && !call.isImplicitThis(); }
@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); }
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; }
@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; }
private boolean isClosureCall(MethodCallExpression call) { // are we a local variable? // it should not be an explicitly "this" qualified method call // and the current class should have a possible method ClassNode classNode = controller.getClassNode(); String methodName = call.getMethodAsString(); if (methodName==null) return false; if (!call.isImplicitThis()) return false; if (!AsmClassGenerator.isThisExpression(call.getObjectExpression())) return false; FieldNode field = classNode.getDeclaredField(methodName); if (field == null) return false; if (isStaticInvocation(call) && !field.isStatic()) return false; Expression arguments = call.getArguments(); return ! classNode.hasPossibleMethod(methodName, arguments); }
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 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) { exp.getArguments() ); reformatted.setImplicitThis(exp.isImplicitThis()); reformatted.setSafe(exp.isSafe()); reformatted.setSpreadSafe(exp.isSpreadSafe());
@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); }
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); }
if (object instanceof VariableExpression) { VariableExpression ve = (VariableExpression) object; isExplicitThisOrSuper = !mce.isImplicitThis() && (ve.isThisExpression() || ve.isSuperExpression()); isExplicitSuper = ve.isSuperExpression(); if (mce.isImplicitThis() || isExplicitThisOrSuper) { if (mce.isImplicitThis()) { if (null == currentClass.tryFindPossibleMethod(mce.getMethodAsString(), args)) { return smce; if (!inClosure && inInnerClass && inSpecialConstructorCall && mce.isImplicitThis() && !foundInstanceMethod) { if (currentClass.getOuterClass().hasPossibleMethod(methodName, args)) { object = new PropertyExpression(new ClassExpression(currentClass.getOuterClass()), new ConstantExpression("this")); if (mce.isImplicitThis() && lookForPossibleStaticMethod && hasPossibleStaticMethod(currentClass, methodName, args, true)) { StaticMethodCallExpression result = new StaticMethodCallExpression(currentClass, methodName, args); result.setSourcePosition(mce); result.setImplicitThis(mce.isImplicitThis()); result.setSpreadSafe(mce.isSpreadSafe()); result.setMethodTarget(mce.getMethodTarget());
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 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() ); } }
boolean candidate = false; if (objectExpression instanceof MethodCallExpression) { candidate = ((MethodCallExpression)objectExpression).isImplicitThis();
MethodCallExpression call = (MethodCallExpression) exp; Expression obj = call.getObjectExpression(); if (call.isImplicitThis() || "this".equals(obj.getText())) { return transformMethodCallOnThis(call); } else if ("super".equals(obj.getText())) {
Expression object = transform(mce.getObjectExpression()); MethodCallExpression transformed = callX(object, method, args); transformed.setImplicitThis(mce.isImplicitThis()); transformed.setSafe(mce.isSafe()); transformed.setSourcePosition(mce);
newMCE.setMethodTarget(methodTarget); newMCE.setSafe(false); newMCE.setImplicitThis(origMCE.isImplicitThis()); newMCE.setSourcePosition(origMCE); newMCE.visit(controller.getAcg());