Exemplo n.º 1
0
  public boolean visit(CallExpression call) throws Exception {
    FieldDeclaration constantDecl = ASTUtils.getConstantDeclaration(call);
    if (constantDecl != null) {
      // In case we are entering a nested element
      if (!declarations.empty() && declarations.peek() instanceof MethodDeclaration) {
        deferredDeclarations.add(constantDecl);
        return visitGeneral(call);
      }

      visit((FieldDeclaration) constantDecl);

    } else {
      int argsCount = 0;
      CallArgumentsList args = call.getArgs();
      if (args != null && args.getChilds() != null) {
        argsCount = args.getChilds().size();
      }

      modifyReference(
          call,
          new ReferenceInfo(
              IModelElement.METHOD,
              call.sourceStart(),
              call.sourceEnd() - call.sourceStart(),
              call.getName(),
              Integer.toString(argsCount),
              null));
    }

    return visitGeneral(call);
  }
  public boolean visit(CallExpression call) throws Exception {
    final FieldDeclaration constantDecl = ASTUtils.getConstantDeclaration(call);
    if (constantDecl != null) {
      // In case we are entering a nested element
      if (!declarations.empty() && declarations.peek() instanceof MethodDeclaration) {
        deferredDeclarations.add(constantDecl);
        return false;
      }

      visit(constantDecl);

    } else {
      int argsCount = 0;
      final CallArgumentsList args = call.getArgs();
      if (args != null && args.getChilds() != null) {
        argsCount = args.getChilds().size();
      }
      fRequestor.acceptMethodReference(
          call.getName(),
          argsCount,
          call.getCallName().sourceStart(),
          call.getCallName().sourceEnd());
    }
    return true;
  }
Exemplo n.º 3
0
  private void selectOnMethod(ModuleDeclaration parsedUnit, CallExpression parentCall) {
    String methodName = parentCall.getName();
    ASTNode receiver = parentCall.getReceiver();

    final List<IModelElement> availableMethods = new ArrayList<IModelElement>();

    if (receiver == null) {
      IEvaluatedType type =
          RubyTypeInferencingUtils.determineSelfClass(
              mixinModel, sourceModule, parsedUnit, parentCall.sourceStart());
      if ((type != null) && "Object".equals(type.getTypeName())) { // $NON-NLS-1$
        ExpressionTypeGoal goal =
            new ExpressionTypeGoal(new BasicContext(sourceModule, parsedUnit), parsedUnit);
        IEvaluatedType type2 = inferencer.evaluateType(goal, 2000);
        if (type2 != null) {
          type = type2;
        }
      }
      IMethod[] m =
          RubyModelUtils.searchClassMethodsExact(
              mixinModel, sourceModule, parsedUnit, type, methodName);
      addArrayToCollection(m, availableMethods);
    } else {
      ExpressionTypeGoal goal =
          new ExpressionTypeGoal(new BasicContext(sourceModule, parsedUnit), receiver);
      IEvaluatedType type = inferencer.evaluateType(goal, 5000);
      IMethod[] m =
          RubyModelUtils.searchClassMethodsExact(
              mixinModel, sourceModule, parsedUnit, type, methodName);
      addArrayToCollection(m, availableMethods);
      if (receiver instanceof VariableReference) {
        IMethod[] availableMethods2 =
            RubyModelUtils.getSingletonMethods(
                mixinModel, (VariableReference) receiver, parsedUnit, sourceModule, methodName);
        addArrayToCollection(availableMethods2, availableMethods);
      }
    }

    if (availableMethods.isEmpty()) {
      searchMethodDeclarations(sourceModule.getScriptProject(), methodName, availableMethods);
    }

    if (!availableMethods.isEmpty()) {
      for (int i = 0, size = availableMethods.size(); i < size; ++i) {
        final IMethod m = (IMethod) availableMethods.get(i);
        if (methodName.equals(methodName)) {
          selectionElements.add(m);
        }
      }
    }
  }
 @Override
 public boolean visitGeneral(ASTNode node) throws Exception {
   if (!ACTIVE) {
     return true;
   }
   if (node instanceof RubyRegexpExpression || node instanceof RubyDRegexpExpression) {
     handleRegexp(node);
   } else if (node instanceof RubySymbolReference) {
     requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_SYMBOL);
   } else if (node instanceof VariableReference) {
     handleVariableReference((VariableReference) node);
   } else if (node instanceof RubyDVarExpression) {
     requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_LOCAL_VARIABLE);
   } else if (node instanceof RubyDAssgnExpression) {
     ASTNode var = ((RubyDAssgnExpression) node).getLeft();
     requestor.addPosition(var.sourceStart(), var.sourceEnd(), HL_LOCAL_VARIABLE);
   } else if (node instanceof StringLiteral) {
     if (isStringLiteralNeeded(node)) {
       requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_STRING);
     }
   } else if (node instanceof NumericLiteral
       || node instanceof FloatNumericLiteral
       || node instanceof BigNumericLiteral) {
     requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_NUMBER);
   } else if (node instanceof RubyEvaluatableStringExpression) {
     handleEvaluatableExpression(node);
   } else if (node instanceof CallExpression) {
     final CallExpression call = (CallExpression) node;
     if (!(RubySyntaxUtils.isRubyOperator(call.getName())
         || call.getReceiver() == null && RubyCodeScanner.isPseudoKeyword(call.getName()))) {
       final SimpleReference callName = call.getCallName();
       if (callName.sourceStart() >= 0 && callName.sourceEnd() > callName.sourceStart()) {
         requestor.addPosition(callName.sourceStart(), callName.sourceEnd(), HL_DEFAULT);
       }
     }
   } else if (node instanceof Declaration) {
     final Declaration declaration = (Declaration) node;
     requestor.addPosition(declaration.getNameStart(), declaration.getNameEnd(), HL_DEFAULT);
   } else if (node instanceof RubyConstantDeclaration) {
     final RubyConstantDeclaration declaration = (RubyConstantDeclaration) node;
     final SimpleReference name = declaration.getName();
     requestor.addPosition(name.sourceStart(), name.sourceEnd(), HL_CONST);
   }
   stack.push(node);
   return true;
 }
 @Override
 protected RubyAstVisitor<?> enterCallExpression(CallExpression node) {
   if (name.equalsIgnoreCase(node.getName()) && (needReceiver == (node.getReceiver() != null)))
     possibleCalls.add(node);
   return this;
 }