Ejemplo n.º 1
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);
        }
      }
    }
  }
  private void reduceTypes(BasicContext context, Set typeSet) {
    IEvaluatedType type;
    Set superClassSet = new HashSet();
    for (Iterator iter = typeSet.iterator(); iter.hasNext(); ) {
      type = (IEvaluatedType) iter.next();
      collectSuperClasses(
          context.getSourceModule().getScriptProject(), type.getTypeName(), superClassSet);
    }

    if (!superClassSet.isEmpty()) {
      for (Iterator iter = typeSet.iterator(); iter.hasNext(); ) {
        type = (IEvaluatedType) iter.next();
        if (superClassSet.contains(type.getTypeName())) {
          iter.remove();
        }
      }
    }
  }