Ejemplo n.º 1
0
  private void findFields(
      char[] token, boolean canCompleteEmptyToken, List<IField> fields, int kind, List names) {
    if (fields == null || fields.size() == 0) return;

    int length = token.length;
    // String tok = new String(token);
    if (canCompleteEmptyToken || length > 0) {
      for (int i = 0; i < fields.size(); i++) {
        IField field = fields.get(i);
        String qname = (String) names.get(i);
        String name = qname;
        if (DEBUG) {
          System.out.println("Completion:" + qname); // $NON-NLS-1$
        }
        if (length <= name.length() && CharOperation.prefixEquals(token, name, false)) {
          int relevance = computeBaseRelevance();
          relevance += computeRelevanceForInterestingProposal();
          relevance += computeRelevanceForCaseMatching(token, name);
          relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no

          // accept result
          this.noProposal = false;
          if (!this.requestor.isIgnored(kind)) {
            CompletionProposal proposal = this.createProposal(kind, this.actualCompletionPosition);
            proposal.setModelElement(field);
            proposal.setName(name);
            proposal.setCompletion(qname);
            proposal.setRelevance(relevance);
            accept(proposal);
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  protected void findMethods(
      char[] token, boolean canCompleteEmptyToken, List<IMethod> methods, int kind) {
    if (methods == null || methods.size() == 0) return;

    int length = token.length;
    String tok = new String(token);
    if (canCompleteEmptyToken || length > 0) {
      for (int i = 0; i < methods.size(); i++) {
        IMethod method = methods.get(i);
        String qname = processMethodName(method, tok);
        String name = qname;
        if (DEBUG) {
          System.out.println("Completion:" + qname); // $NON-NLS-1$
        }
        if (length <= name.length() && CharOperation.prefixEquals(token, name, false)) {
          int relevance = computeBaseRelevance();
          relevance += computeRelevanceForInterestingProposal();
          relevance += computeRelevanceForCaseMatching(token, name);
          relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no

          // accept result
          this.noProposal = false;
          if (!this.requestor.isIgnored(kind)) {
            CompletionProposal proposal = this.createProposal(kind, this.actualCompletionPosition);
            // proposal.setSignature(getSignature(typeBinding));
            // proposal.setPackageName(q);
            // proposal.setTypeName(displayName);
            proposal.setModelElement(method);
            try {
              proposal.setFlags(method.getFlags());
            } catch (ModelException e1) {
              if (DLTKCore.DEBUG) {
                e1.printStackTrace();
              }
            }
            String[] arguments = null;

            try {
              arguments = method.getParameterNames();
            } catch (ModelException e) {
              if (DLTKCore.DEBUG) {
                e.printStackTrace();
              }
            }
            if (arguments != null && arguments.length > 0) {
              proposal.setParameterNames(arguments);
            }

            proposal.setName(name);
            proposal.setCompletion(name);
            // proposal.setFlags(Flags.AccDefault);
            proposal.setRelevance(relevance);
            accept(proposal);
          }
        }
      }
    }
  }
Ejemplo n.º 3
0
  protected void findLocalMethods(
      char[] token, boolean canCompleteEmptyToken, List methods, List methodNames) {
    if (methods == null || methods.size() == 0) return;

    int length = token.length;
    if (canCompleteEmptyToken || length > 0) {
      for (int i = 0; i < methods.size(); i++) {
        MethodDeclaration method = (MethodDeclaration) methods.get(i);
        String name = ((String) (methodNames.get(i)));
        if (length <= name.length() && CharOperation.prefixEquals(token, name, false)) {
          int relevance = computeBaseRelevance();
          relevance += computeRelevanceForInterestingProposal();
          relevance += computeRelevanceForCaseMatching(token, name);
          relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no

          // accept result
          this.noProposal = false;
          if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
            CompletionProposal proposal =
                this.createProposal(CompletionProposal.METHOD_REF, this.actualCompletionPosition);
            // proposal.setSignature(getSignature(typeBinding));
            // proposal.setPackageName(q);
            // proposal.setTypeName(displayName);
            List arguments = method.getArguments();
            if (arguments != null && arguments.size() > 0) {
              String[] args = new String[arguments.size()];
              for (int j = 0; j < arguments.size(); ++j) {
                args[j] = ((Argument) arguments.get(j)).getName();
              }
              proposal.setParameterNames(args);
            }

            proposal.setName(name);
            proposal.setCompletion(name);
            // proposal.setFlags(Flags.AccDefault);
            proposal.setRelevance(relevance);
            accept(proposal);
          }
        }
      }
    }
  }
Ejemplo n.º 4
0
  protected void findElements(
      char[] token,
      String[] choices,
      boolean canCompleteEmptyToken,
      boolean provideDollar,
      int kind) {
    if (choices == null || choices.length == 0) return;

    int length = token.length;
    if (canCompleteEmptyToken || length > 0) {
      for (int i = 0; i < choices.length; i++) {
        String co = choices[i];
        if (!provideDollar && co.length() > 1 && co.charAt(0) == '$') {
          co = co.substring(1);
        }
        if (length <= co.length() && CharOperation.prefixEquals(token, co, false)) {
          int relevance = computeBaseRelevance();
          relevance += computeRelevanceForInterestingProposal();
          relevance += computeRelevanceForCaseMatching(token, co);
          relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no

          // accept result
          this.noProposal = false;

          if (!this.requestor.isIgnored(kind)) {
            CompletionProposal proposal = this.createProposal(kind, this.actualCompletionPosition);
            // proposal.setSignature(getSignature(typeBinding));
            // proposal.setPackageName(q);
            // proposal.setTypeName(displayName);
            proposal.setName(co);
            proposal.setCompletion(co);

            // proposal.setFlags(Flags.AccDefault);
            proposal.setRelevance(relevance);
            accept(proposal);
          }
        }
      }
    }
  }
Ejemplo n.º 5
0
  public void findTypes(char[] token, boolean canCompleteEmptyToken, List<IType> types) {
    if (types == null || types.size() == 0) return;

    int length = token.length;
    String tok = new String(token);
    if (canCompleteEmptyToken || length > 0) {
      for (int i = 0; i < types.size(); i++) {
        IType type = types.get(i);
        String qname = processTypeName(type, tok);
        String name = qname;
        if (DEBUG) {
          System.out.println("Completion:" + qname); // $NON-NLS-1$
        }
        if (length <= name.length() && CharOperation.prefixEquals(token, name, false)) {
          int relevance = computeBaseRelevance();
          relevance += computeRelevanceForInterestingProposal();
          relevance += computeRelevanceForCaseMatching(token, name);
          relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no

          // accept result
          this.noProposal = false;
          if (!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {

            CompletionProposal proposal =
                this.createProposal(CompletionProposal.TYPE_REF, this.actualCompletionPosition);
            // proposal.setSignature(getSignature(typeBinding));
            // proposal.setPackageName(q);
            // proposal.setTypeName(displayName);
            proposal.setModelElement(type);
            proposal.setName(name);
            proposal.setCompletion(name);
            // proposal.setFlags(Flags.AccDefault);
            proposal.setRelevance(relevance);
            accept(proposal);
          }
        }
      }
    }
  }
Ejemplo n.º 6
0
  public void findKeywords(char[] keyword, String[] choices, boolean canCompleteEmptyToken) {
    if (choices == null || choices.length == 0) return;

    int length = keyword.length;
    if (canCompleteEmptyToken || length > 0) {
      for (int i = 0; i < choices.length; i++) {
        if (length <= choices[i].length()
            && CharOperation.prefixEquals(keyword, choices[i], false)) {
          int relevance = computeBaseRelevance();

          relevance += computeRelevanceForInterestingProposal();
          relevance += computeRelevanceForCaseMatching(keyword, choices[i]);
          relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no
          /*
           * access restriction for keywords
           */

          // if (CharOperation.equals(choices[i], Keywords.TRUE)
          // || CharOperation.equals(choices[i], Keywords.FALSE)) {
          // relevance +=
          // computeRelevanceForExpectingType(TypeBinding.BOOLEAN);
          // relevance += computeRelevanceForQualification(false);
          // }
          this.noProposal = false;
          if (!this.requestor.isIgnored(CompletionProposal.KEYWORD)) {
            CompletionProposal proposal =
                this.createProposal(CompletionProposal.KEYWORD, this.actualCompletionPosition);
            proposal.setName(choices[i]);
            proposal.setCompletion(choices[i]);
            proposal.setRelevance(relevance);
            accept(proposal);
          }
        }
      }
    }
  }