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);
  }
 @Override
 public void visitMethodCallExpression(final MethodCallExpression call) {
   super.visitMethodCallExpression(call);
   MethodNode mn = call.getMethodTarget();
   if (mn == null) {
     call.setMethodTarget(doCallMethod);
   }
 }
 public void visitMethodCallExpression(MethodCallExpression mce) {
   super.visitMethodCallExpression(mce);
   Expression aexp = mce.getArguments();
   if (aexp instanceof TupleExpression) {
     TupleExpression arguments = (TupleExpression) aexp;
     for (Expression e : arguments.getExpressions()) {
       checkForInvalidDeclaration(e);
     }
   } else {
     checkForInvalidDeclaration(aexp);
   }
 }
Exemplo n.º 4
0
 @Override
 public void visitMethodCallExpression(MethodCallExpression call) {
   String name =
       call.getMethodAsString(); // Could be null (for 'funny' calls where target name is dynamic)
   SearchingCodeVisitor.MethodCallAction action = getMethodCallAction(name);
   if (action != null) {
     Assert.isLegal(action.methodName.equals(name));
     if (!isVisited(call)) {
       action.doit(this, call);
     }
   }
   super.visitMethodCallExpression(call);
 }
    @Override
    public void visitMethodCallExpression(MethodCallExpression expression) {
      // LOG.debug "Transforming expression '${expression}':"

      if (expression.getLineNumber() >= 0 && expression.getLineNumber() < lineNumbers.length) {
        // LOG.debug "   start from ${expression.lineNumber} to ${lineNumbers[expression.lineNumber
        // - 1]}"
        expression.setLineNumber(lineNumbers[expression.getLineNumber() - 1]);
      }

      if (expression.getLastLineNumber() > 0
          && expression.getLastLineNumber() < lineNumbers.length) {
        // LOG.debug "   end from ${expression.lastLineNumber} to
        // ${lineNumbers[expression.lastLineNumber - 1]}"
        expression.setLastLineNumber(lineNumbers[expression.getLastLineNumber() - 1]);
      }
      super.visitMethodCallExpression(expression);
    }
Exemplo n.º 6
0
 @Override
 public void visitMethodCallExpression(final MethodCallExpression call) {
   pushContext(call);
   super.visitMethodCallExpression(call);
   popContext();
 }