/**
  * Returns <code>true</code> if <code>proposal</code> is filtered, e.g. should not be proposed to
  * the user, <code>false</code> if it is valid.
  *
  * <p>Subclasses may extends this method. The default implementation filters proposals set to be
  * ignored via {@linkplain CompletionRequestor#setIgnored(int, boolean) setIgnored} and types set
  * to be ignored in the preferences.
  *
  * @param proposal the proposal to filter
  * @return <code>true</code> to filter <code>proposal</code>, <code>false</code> to let it pass
  */
 protected boolean isFiltered(CompletionProposal proposal) {
   if (isIgnored(proposal.getKind())) {
     return true;
   }
   char[] declaringType = getDeclaringType(proposal);
   return declaringType != null && TypeFilter.isFiltered(declaringType);
 }
 /**
  * Computes the relevance for a given <code>CompletionProposal</code>.
  *
  * <p>Subclasses may replace, but usually should not need to.
  *
  * @param proposal the proposal to compute the relevance for
  * @return the relevance for <code>proposal</code>
  */
 protected int computeRelevance(CompletionProposal proposal) {
   final int baseRelevance = proposal.getRelevance() * 16;
   switch (proposal.getKind()) {
     case CompletionProposal.LIBRARY_PREFIX:
       return baseRelevance + 0;
     case CompletionProposal.LABEL_REF:
       return baseRelevance + 1;
     case CompletionProposal.KEYWORD:
       return baseRelevance + 2;
     case CompletionProposal.TYPE_REF:
       //      case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
       //      case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
       return baseRelevance + 3;
     case CompletionProposal.METHOD_REF:
     case CompletionProposal.CONSTRUCTOR_INVOCATION:
     case CompletionProposal.METHOD_NAME_REFERENCE:
     case CompletionProposal.METHOD_DECLARATION:
       //      case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
       return baseRelevance + 4;
     case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
       return baseRelevance + 4 /* + 99 */;
     case CompletionProposal.FIELD_REF:
       return baseRelevance + 5;
     case CompletionProposal.LOCAL_VARIABLE_REF:
     case CompletionProposal.VARIABLE_DECLARATION:
       return baseRelevance + 6;
     case CompletionProposal.ARGUMENT_LIST:
       return baseRelevance + 7;
     default:
       return baseRelevance;
   }
 }
  /**
   * Tells whether required proposals are supported by this proposal.
   *
   * @return <code>true</code> if required proposals are supported by this proposal
   */
  protected boolean isSupportingRequiredProposals() {
    if (fInvocationContext == null) {
      return false;
    }

    ProposalInfo proposalInfo = getProposalInfo();
    if (!(proposalInfo instanceof MemberProposalInfo)) {
      return false;
    }

    CompletionProposal proposal = ((MemberProposalInfo) proposalInfo).fProposal;
    return proposal != null
        && (proposal.getKind() == CompletionProposal.METHOD_REF
            || proposal.getKind() == CompletionProposal.FIELD_REF
            || proposal.getKind() == CompletionProposal.TYPE_REF
            //          || proposal.getKind() ==
            // CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION
            || proposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION);
  }
 /**
  * Creates a new Dart completion proposal from a core proposal. This may involve computing the
  * display label and setting up some context.
  *
  * <p>This method is called for every proposal that will be displayed to the user, which may be
  * hundreds. Implementations should therefore defer as much work as possible: Labels should be
  * computed lazily to leverage virtual table usage, and any information only needed when
  * <em>applying</em> a proposal should not be computed yet.
  *
  * <p>Implementations may return <code>null</code> if a proposal should not be included in the
  * list presented to the user.
  *
  * <p>Subclasses may extend or replace this method.
  *
  * @param proposal the core completion proposal to create a UI proposal for
  * @return the created Dart completion proposal, or <code>null</code> if no proposal should be
  *     displayed
  */
 protected IDartCompletionProposal createDartCompletionProposal(CompletionProposal proposal) {
   switch (proposal.getKind()) {
     case CompletionProposal.KEYWORD:
       return createKeywordProposal(proposal);
     case CompletionProposal.LIBRARY_PREFIX:
       return createLibraryPrefixProposal(proposal);
     case CompletionProposal.TYPE_REF:
       return createTypeProposal(proposal);
       //      case CompletionProposal.JAVADOC_TYPE_REF:
       //        return createJavadocLinkTypeProposal(proposal);
     case CompletionProposal.FIELD_REF:
       //      case CompletionProposal.JAVADOC_FIELD_REF:
       //      case CompletionProposal.JAVADOC_VALUE_REF:
       return createFieldProposal(proposal);
       //      case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
       //        return createFieldWithCastedReceiverProposal(proposal);
     case CompletionProposal.ARGUMENT_LIST:
     case CompletionProposal.METHOD_REF:
     case CompletionProposal.CONSTRUCTOR_INVOCATION:
       //      case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
     case CompletionProposal.METHOD_NAME_REFERENCE:
       //      case CompletionProposal.JAVADOC_METHOD_REF:
       return createMethodReferenceProposal(proposal);
     case CompletionProposal.METHOD_DECLARATION:
       return createMethodDeclarationProposal(proposal);
       //      case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
       //        return createAnonymousTypeProposal(proposal, getInvocationContext());
       //      case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
       //        return createAnonymousTypeProposal(proposal, null);
     case CompletionProposal.LABEL_REF:
       return createLabelProposal(proposal);
     case CompletionProposal.LOCAL_VARIABLE_REF:
     case CompletionProposal.VARIABLE_DECLARATION:
       return createLocalVariableProposal(proposal);
     case CompletionProposal.TYPE_IMPORT:
       return createImportProposal(proposal);
     case CompletionProposal.OPTIONAL_ARGUMENT:
       return new OptionalArgumentCompletionProposal(proposal);
     case CompletionProposal.NAMED_ARGUMENT:
       return new NamedArgumentCompletionProposal(proposal);
       //      case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
       //        return createAnnotationAttributeReferenceProposal(proposal);
       //      case CompletionProposal.JAVADOC_BLOCK_TAG:
       //      case CompletionProposal.JAVADOC_PARAM_REF:
       //        return createJavadocSimpleProposal(proposal);
       //      case CompletionProposal.JAVADOC_INLINE_TAG:
       //        return createJavadocInlineTagProposal(proposal);
     case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
     default:
       return null;
   }
 }
  /**
   * {@inheritDoc}
   *
   * <p>Subclasses may replace, but usually should not need to. Consider replacing {@linkplain
   * #createDartCompletionProposal(CompletionProposal) createDartCompletionProposal} instead.
   */
  @Override
  public void accept(CompletionProposal proposal) {
    long start = DEBUG ? System.currentTimeMillis() : 0;
    try {
      if (isFiltered(proposal)) {
        return;
      }

      DartContentAssistInvocationContext ctxt = getInvocationContext();
      proposal.applyPartitionOffset(ctxt.getPartitionOffset());
      if (proposal.getKind() == CompletionProposal.POTENTIAL_METHOD_DECLARATION) {
        acceptPotentialMethodDeclaration(proposal);
      } else {
        IDartCompletionProposal dartProposal = createDartCompletionProposal(proposal);
        if (dartProposal != null) {
          fDartProposals.add(dartProposal);
          if (proposal.getKind() == CompletionProposal.KEYWORD) {
            fKeywords.add(dartProposal);
          }
        }
      }
    } catch (IllegalArgumentException e) {
      // all signature processing method may throw IAEs
      // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84657
      // don't abort, but log and show all the valid proposals
      DartToolsPlugin.log(
          new Status(
              IStatus.ERROR,
              DartToolsPlugin.getPluginId(),
              IStatus.OK,
              "Exception when processing proposal for: " + String.valueOf(proposal.getCompletion()),
              e)); //$NON-NLS-1$
    }

    if (DEBUG) {
      fUITime += System.currentTimeMillis() - start;
    }
  }
 /**
  * Returns the type signature of the declaring type of a <code>CompletionProposal</code>, or
  * <code>null</code> for proposals that do not have a declaring type. The return value is
  * <em>not</em> <code>null</code> for proposals of the following kinds:
  *
  * <ul>
  *   <li>METHOD_DECLARATION
  *   <li>METHOD_NAME_REFERENCE
  *   <li>METHOD_REF
  *   <li>ANNOTATION_ATTRIBUTE_REF
  *   <li>POTENTIAL_METHOD_DECLARATION
  *   <li>ANONYMOUS_CLASS_DECLARATION
  *   <li>FIELD_REF
  *   <li>PACKAGE_REF (returns the package, but no type)
  *   <li>TYPE_REF
  * </ul>
  *
  * @param proposal the completion proposal to get the declaring type for
  * @return the type signature of the declaring type, or <code>null</code> if there is none
  */
 protected final char[] getDeclaringType(CompletionProposal proposal) {
   switch (proposal.getKind()) {
     case CompletionProposal.METHOD_DECLARATION:
     case CompletionProposal.METHOD_NAME_REFERENCE:
       //      case CompletionProposal.JAVADOC_METHOD_REF:
     case CompletionProposal.METHOD_REF:
     case CompletionProposal.ARGUMENT_LIST:
     case CompletionProposal.CONSTRUCTOR_INVOCATION:
       //      case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
       //      case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
       //      case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
     case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
       //      case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
     case CompletionProposal.FIELD_REF:
       //      case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
       //      case CompletionProposal.JAVADOC_FIELD_REF:
       //      case CompletionProposal.JAVADOC_VALUE_REF:
       char[] declaration = proposal.getDeclarationSignature();
       // special methods may not have a declaring type: methods defined on arrays etc.
       // Currently known: class literals don't have a declaring type - use Object
       //        if (declaration == null) {
       //          return "java.lang.Object".toCharArray(); //$NON-NLS-1$
       //        }
       return Signature.toCharArray(declaration);
     case CompletionProposal.LIBRARY_PREFIX:
       return proposal.getDeclarationSignature();
       //      case CompletionProposal.JAVADOC_TYPE_REF:
     case CompletionProposal.TYPE_REF:
       return Signature.toCharArray(proposal.getSignature());
     case CompletionProposal.LOCAL_VARIABLE_REF:
     case CompletionProposal.VARIABLE_DECLARATION:
     case CompletionProposal.KEYWORD:
     case CompletionProposal.LABEL_REF:
     case CompletionProposal.TYPE_IMPORT:
     case CompletionProposal.OPTIONAL_ARGUMENT:
     case CompletionProposal.NAMED_ARGUMENT:
       //      case CompletionProposal.JAVADOC_BLOCK_TAG:
       //      case CompletionProposal.JAVADOC_INLINE_TAG:
       //      case CompletionProposal.JAVADOC_PARAM_REF:
       return null;
     default:
       Assert.isTrue(false);
       return null;
   }
 }
 /**
  * Creates the context information for a given method reference proposal. The passed proposal must
  * be of kind {@link CompletionProposal#METHOD_REF}.
  *
  * @param methodProposal the method proposal for which to create context information
  * @return the context information for <code>methodProposal</code>
  */
 protected final IContextInformation createMethodContextInformation(
     CompletionProposal methodProposal) {
   Assert.isTrue(methodProposal.getKind() == CompletionProposal.METHOD_REF);
   return new ProposalContextInformation(methodProposal);
 }