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); } } } }
private void selectionOnVariable(ModuleDeclaration parsedUnit, VariableReference e) { String name = e.getName(); if (name.startsWith("@")) { // $NON-NLS-1$ IField[] fields = RubyModelUtils.findFields(mixinModel, sourceModule, parsedUnit, name, e.sourceStart()); addArrayToCollection(fields, selectionElements); } else { /* * local vars (legacy, saved for speed reasons: we don't need to use * mixin model for local vars) */ ASTNode parentScope = null; for (int i = wayToNode.length; --i >= 0; ) { final ASTNode node = wayToNode[i]; if (node instanceof MethodDeclaration || node instanceof TypeDeclaration || node instanceof ModuleDeclaration || node instanceof RubyForStatement2) { parentScope = node; break; } } if (parentScope != null) { RubyAssignment[] assignments = RubyTypeInferencingUtils.findLocalVariableAssignments(parentScope, e, name); if (assignments.length > 0) { final ASTNode left = assignments[0].getLeft(); selectionElements.add(createLocalVariable(name, left.sourceStart(), left.sourceEnd())); } else { selectionElements.add(createLocalVariable(name, e.sourceStart(), e.sourceEnd())); } } } }