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; }