private static StyledString getDisplayName(String methodName, String returnTypeSig) {
   StyledString buf = new StyledString();
   buf.append(methodName);
   buf.append('(');
   buf.append(')');
   if (returnTypeSig != null) {
     buf.append(" : "); // $NON-NLS-1$
     buf.append(Signature.toString(returnTypeSig));
     buf.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$
     buf.append(
         DartTextMessages.MethodCompletionProposal_method_label, StyledString.QUALIFIER_STYLER);
   } else {
     buf.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$
     buf.append(
         DartTextMessages.MethodCompletionProposal_constructor_label,
         StyledString.QUALIFIER_STYLER);
   }
   return buf;
 }
  private IDartCompletionProposal createMethodDeclarationProposal(CompletionProposal proposal) {
    if (fCompilationUnit == null || fDartProject == null) {
      return null;
    }

    String name = String.valueOf(proposal.getName());
    String[] paramTypes = Signature.getParameterTypes(String.valueOf(proposal.getSignature()));
    for (int index = 0; index < paramTypes.length; index++) {
      paramTypes[index] = Signature.toString(paramTypes[index]);
    }
    int start = proposal.getReplaceStart();
    int length = getLength(proposal);

    StyledString label =
        new StyledString(
            fLabelProvider.createOverrideMethodProposalLabel(proposal)); // TODO(messick)

    DartCompletionProposal dartProposal =
        new OverrideCompletionProposal(
            fDartProject,
            fCompilationUnit,
            name,
            paramTypes,
            start,
            length,
            getLengthIdentifier(proposal),
            label,
            String.valueOf(proposal.getCompletion()));
    dartProposal.setImage(getImage(fLabelProvider.createMethodImageDescriptor(proposal)));
    // TODO(scheglov) implement documentation comment
    //    dartProposal.setProposalInfo(new MethodProposalInfo(fDartProject, proposal));
    dartProposal.setRelevance(computeRelevance(proposal));

    fSuggestedMethodNames.add(new String(name));
    return dartProposal;
  }
  @Override
  protected boolean updateReplacementString(
      IDocument document, char trigger, int offset, ImportRewrite impRewrite)
      throws CoreException, BadLocationException {

    CodeGenerationSettings settings =
        JavaPreferencesSettings.getCodeGenerationSettings(fType.getDartProject());
    boolean addComments = settings.createComments;

    String[] empty = new String[0];
    String lineDelim = TextUtilities.getDefaultLineDelimiter(document);
    @SuppressWarnings("deprecation")
    String declTypeName = fType.getTypeQualifiedName('.');
    boolean isInterface = fType.isInterface();

    StringBuffer buf = new StringBuffer();
    if (addComments) {
      String comment =
          CodeGeneration.getMethodComment(
              fType.getCompilationUnit(),
              declTypeName,
              fMethodName,
              empty,
              empty,
              fReturnTypeSig,
              lineDelim);
      if (comment != null) {
        buf.append(comment);
        buf.append(lineDelim);
      }
    }

    if (fReturnTypeSig != null) {
      buf.append(Signature.toString(fReturnTypeSig));
    }
    buf.append(' ');
    buf.append(fMethodName);
    if (isInterface) {
      buf.append("();"); // $NON-NLS-1$
      buf.append(lineDelim);
    } else {
      buf.append("() {"); // $NON-NLS-1$
      buf.append(lineDelim);

      String body =
          CodeGeneration.getMethodBodyContent(
              fType.getCompilationUnit(),
              declTypeName,
              fMethodName,
              fReturnTypeSig == null,
              "",
              lineDelim); //$NON-NLS-1$
      if (body != null) {
        buf.append(body);
        buf.append(lineDelim);
      }
      buf.append("}"); // $NON-NLS-1$
      buf.append(lineDelim);
    }
    String stub = buf.toString();

    // use the code formatter
    IRegion region = document.getLineInformationOfOffset(getReplacementOffset());
    int lineStart = region.getOffset();
    int indent =
        Strings.computeIndentUnits(
            document.get(lineStart, getReplacementOffset() - lineStart),
            settings.tabWidth,
            settings.indentWidth);

    String replacement =
        CodeFormatterUtil.format(
            CodeFormatter.K_CLASS_BODY_DECLARATIONS,
            stub,
            indent,
            null,
            lineDelim,
            fType.getDartProject());

    if (replacement.endsWith(lineDelim)) {
      replacement = replacement.substring(0, replacement.length() - lineDelim.length());
    }

    setReplacementString(Strings.trimLeadingTabsAndSpaces(replacement));
    return true;
  }