Example usage for org.eclipse.jdt.core CompletionProposal getRequiredProposals

List of usage examples for org.eclipse.jdt.core CompletionProposal getRequiredProposals

Introduction

In this page you can find the example usage for org.eclipse.jdt.core CompletionProposal getRequiredProposals.

Prototype

public CompletionProposal[] getRequiredProposals() 

Source Link

Document

Returns the required completion proposals.

Usage

From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java

License:Open Source License

/********************************************************************************/

static void outputCompletion(CompletionProposal cp, IvyXmlWriter xw) {
    xw.begin("COMPLETION");
    fieldValue(xw, "ACCESSIBILITY", cp.getAccessibility(), accessibility_types);
    if (cp.isConstructor())
        xw.field("CONSTRUCTOR", true);
    xw.field("TEXT", cp.getCompletion());
    xw.field("INDEX", cp.getCompletionLocation());
    xw.field("DECLKEY", cp.getDeclarationKey());
    switch (cp.getKind()) {
    case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
    case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
    case CompletionProposal.FIELD_IMPORT:
    case CompletionProposal.FIELD_REF:
    case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
    case CompletionProposal.METHOD_IMPORT:
    case CompletionProposal.METHOD_REF:
    case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
    case CompletionProposal.METHOD_DECLARATION:
    case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
        xw.field("DECLSIGN", cp.getDeclarationSignature());
        break;//from   www .ja va  2 s . co m
    case CompletionProposal.PACKAGE_REF:
    case CompletionProposal.TYPE_IMPORT:
    case CompletionProposal.TYPE_REF:
        xw.field("DOTNAME", cp.getDeclarationSignature());
        break;
    }
    fieldFlags(xw, "ACCESS", cp.getFlags(), access_flags);
    xw.field("FLAGS", cp.getFlags());
    xw.field("KEY", cp.getKey());
    xw.field("NAME", cp.getName());
    xw.field("RELEVANCE", cp.getRelevance());
    xw.field("REPLACE_START", cp.getReplaceStart());
    xw.field("REPLACE_END", cp.getReplaceEnd());
    xw.field("SIGNATURE", cp.getSignature());
    xw.field("TOKEN_START", cp.getTokenStart());
    xw.field("TOKEN_END", cp.getTokenEnd());
    fieldValue(xw, "KIND", cp.getKind(), completion_types);
    if (cp instanceof ICompletionProposalExtension4) {
        ICompletionProposalExtension4 icp4 = (ICompletionProposalExtension4) cp;
        xw.field("AUTO", icp4.isAutoInsertable());
    }

    if (CompletionFlags.isStaticImport(cp.getAdditionalFlags()))
        xw.field("STATICIMPORT", true);

    if (cp.getKind() == CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER
            || cp.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) {
        xw.field("RECEIVER_SIGN", cp.getReceiverSignature());
        xw.field("RECEIVER_START", cp.getReceiverStart());
        xw.field("RECEIVER_END", cp.getReceiverEnd());
    }
    xw.field("RCVR", cp.getReceiverSignature());

    xw.cdataElement("DESCRIPTION", cp.toString());

    CompletionProposal[] rq = cp.getRequiredProposals();
    if (rq != null) {
        xw.begin("REQUIRED");
        for (CompletionProposal xcp : rq)
            outputCompletion(xcp, xw);
        xw.end("REQUIRED");
    }

    xw.end("COMPLETION");
}

From source file:org.eclipse.flux.jdt.services.CompletionProposalDescriptionProvider.java

License:Open Source License

/**
 * Creates a display label for the given method proposal. The display label
 * consists of:/*from   ww w .j a v  a 2  s  .  c  o m*/
 * <ul>
 *   <li>the method name</li>
 *   <li>the parameter list (see {@link #createParameterList(CompletionProposal)})</li>
 *   <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})</li>
 *   <li>the raw simple name of the declaring type</li>
 * </ul>
 * <p>
 * Examples:
 * For the <code>get(int)</code> method of a variable of type <code>List<? extends Number></code>, the following
 * display name is returned: <code>get(int index)  Number - List</code>.<br>
 * For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the following
 * display name is returned: <code>add(Number o)  void - List</code>.<br>
 * </p>
 *
 * @param methodProposal the method proposal to display
 * @return the display label for the given method proposal
 */
StringBuilder createMethodProposalLabel(CompletionProposal methodProposal) {
    StringBuilder description = new StringBuilder();

    description.append("[");

    description.append("{\"value\":\"");
    // method name
    description.append(methodProposal.getName());

    // parameters
    description.append('(');
    appendUnboundedParameterList(description, methodProposal);
    description.append(')');

    // return type
    if (!methodProposal.isConstructor()) {
        // TODO remove SignatureUtil.fix83600 call when bugs are fixed
        char[] returnType = createTypeDisplayName(SignatureUtil
                .getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature()))));
        description.append(RETURN_TYPE_SEPARATOR);
        description.append(returnType);
    }

    description.append("\"}");

    description.append(",");
    description.append("{\"value\":\"");

    // declaring type
    description.append(QUALIFIER_SEPARATOR);
    String declaringType = extractDeclaringTypeFQN(methodProposal);

    if (methodProposal.getRequiredProposals() != null) {
        String qualifier = Signature.getQualifier(declaringType);
        if (qualifier.length() > 0) {
            description.append(qualifier);
            description.append('.');
        }
    }

    declaringType = Signature.getSimpleName(declaringType);
    description.append(declaringType);

    description.append("\",\"style\":{");
    description.append("\"color\":\"#AAAAAA\"");
    description.append("}");
    description.append("}");

    description.append("]");

    return description;
}

From source file:org.eclipse.flux.jdt.services.CompletionProposalDescriptionProvider.java

License:Open Source License

StringBuilder createLabelWithTypeAndDeclaration(CompletionProposal proposal) {
    char[] name = proposal.getCompletion();
    if (!isThisPrefix(name))
        name = proposal.getName();/*from   ww w  .  j  a v a2s  .c o  m*/
    StringBuilder buf = new StringBuilder();
    buf.append("[");

    buf.append("{\"value\":\"");

    buf.append(name);
    char[] typeName = Signature.getSignatureSimpleName(proposal.getSignature());
    if (typeName.length > 0) {
        buf.append(VAR_TYPE_SEPARATOR);
        buf.append(typeName);
    }
    buf.append("\"}");

    char[] declaration = proposal.getDeclarationSignature();
    if (declaration != null) {
        declaration = Signature.getSignatureSimpleName(declaration);
        if (declaration.length > 0) {
            buf.append(",");
            buf.append("{\"value\":\"");
            buf.append(QUALIFIER_SEPARATOR);
            if (proposal.getRequiredProposals() != null) {
                String declaringType = extractDeclaringTypeFQN(proposal);
                String qualifier = Signature.getQualifier(declaringType);
                if (qualifier.length() > 0) {
                    buf.append(qualifier);
                    buf.append('.');
                }
            }
            buf.append(declaration);
            buf.append("\",\"style\":{");
            buf.append("\"color\":\"#AAAAAA\"");
            buf.append("}");
            buf.append("}");
        }
    }
    buf.append("]");
    return buf;
}

From source file:org.eclipse.flux.jdt.services.CompletionProposalDescriptionProvider.java

License:Open Source License

StringBuilder createAnonymousTypeLabel(CompletionProposal proposal) {
    char[] declaringTypeSignature = proposal.getDeclarationSignature();
    declaringTypeSignature = Signature.getTypeErasure(declaringTypeSignature);

    StringBuilder buf = new StringBuilder();
    buf.append("[");
    buf.append("{\"value\":\"");

    buf.append(Signature.getSignatureSimpleName(declaringTypeSignature));
    buf.append('(');
    appendUnboundedParameterList(buf, proposal);
    buf.append(')');
    buf.append("  "); //$NON-NLS-1$
    buf.append("Anonymous Inner Type"); //TODO: consider externalization
    buf.append("\"}");
    if (proposal.getRequiredProposals() != null) {
        char[] signatureQualifier = Signature.getSignatureQualifier(declaringTypeSignature);
        if (signatureQualifier.length > 0) {
            buf.append(",");
            buf.append("{\"value\":\"");
            buf.append(QUALIFIER_SEPARATOR);
            buf.append(signatureQualifier);
            buf.append("\",\"style\":{");
            buf.append("\"color\":\"#AAAAAA\"");
            buf.append("}");
            buf.append("}");
        }//from   w  w w  .  j av a2 s .c o m
    }
    buf.append("]");
    return buf;
}

From source file:org.eclipse.flux.jdt.services.CompletionProposalReplacementProvider.java

License:Open Source License

public StringBuilder createReplacement(CompletionProposal proposal, char trigger, List<Integer> positions) {
    StringBuilder completionBuffer = new StringBuilder();
    if (isSupportingRequiredProposals(proposal)) {
        CompletionProposal[] requiredProposals = proposal.getRequiredProposals();
        for (int i = 0; requiredProposals != null && i < requiredProposals.length; i++) {
            if (requiredProposals[i].getKind() == CompletionProposal.TYPE_REF) {
                appendRequiredType(completionBuffer, requiredProposals[i], trigger, positions);
            } else if (requiredProposals[i].getKind() == CompletionProposal.TYPE_IMPORT) {
                appendImportProposal(completionBuffer, requiredProposals[i], proposal.getKind());
            } else if (requiredProposals[i].getKind() == CompletionProposal.METHOD_IMPORT) {
                appendImportProposal(completionBuffer, requiredProposals[i], proposal.getKind());
            } else if (requiredProposals[i].getKind() == CompletionProposal.FIELD_IMPORT) {
                appendImportProposal(completionBuffer, requiredProposals[i], proposal.getKind());
            } else {
                /*//from  w  w  w .  j a  va2  s.  c o m
                 * In 3.3 we only support the above required proposals, see
                 * CompletionProposal#getRequiredProposals()
                 */
                Assert.isTrue(false);
            }
        }
    }

    //         boolean isSmartTrigger= isSmartTrigger(trigger);

    appendReplacementString(completionBuffer, proposal, positions);

    //         String replacement;
    //         if (isSmartTrigger || trigger == (char) 0) {
    //            int referenceOffset= offset - prefix.length() + completionBuffer.length();
    //            //add ; to the replacement string if replacement string do not end with a semicolon and the document do not already have a ; at the reference offset.
    //            if (trigger == ';'
    //               && proposal.getCompletion()[proposal.getCompletion().length - 1] != ';'
    //               && (referenceOffset >= compilationUnit.getBuffer()
    //                     .getLength() || compilationUnit.getBuffer()
    //                     .getChar(referenceOffset) != ';')) {
    //               completionBuffer.append(';');
    //            }
    //         } else {
    //            StringBuffer buffer= new StringBuffer(getReplacementString());
    //
    //            // fix for PR #5533. Assumes that no eating takes place.
    //            if ((getCursorPosition() > 0 && getCursorPosition() <= buffer.length() && buffer.charAt(getCursorPosition() - 1) != trigger)) {
    //               // insert trigger ';' for methods with parameter at the end of the replacement string and not at the cursor position.
    //               int length= getReplacementString().length();
    //               if (trigger == ';' && getCursorPosition() != length) {
    //                  if (buffer.charAt(length - 1) != trigger) {
    //                     buffer.insert(length, trigger);
    //                  }
    //               } else {
    //                  buffer.insert(getCursorPosition(), trigger);
    //                  setCursorPosition(getCursorPosition() + 1);
    //               }
    //            }
    //
    //            replacement= buffer.toString();
    //            setReplacementString(replacement);
    //         }
    //
    //         // PR 47097
    //         if (isSmartTrigger) {
    //            // avoid inserting redundant semicolon when smart insert is enabled.
    //            if (!(trigger == ';' && (completionBuffer.charAt(completionBuffer.length() - 1) == ';' /*|| document.getChar(referenceOffset) == ';'*/))) { //$NON-NLS-1$
    //               handleSmartTrigger(trigger, offset - prefix.length() + completionBuffer.length());
    //            }
    //         }

    return completionBuffer;
}

From source file:org.eclipse.objectteams.otdt.tests.model.CompletionTestsRequestor2.java

License:Open Source License

protected StringBuffer printProposal(CompletionProposal proposal, int tab, StringBuffer buffer) {
    for (int i = 0; i < tab; i++) {
        buffer.append("   "); //$NON-NLS-1$
    }// w ww  .jav a2s. c o m
    buffer.append(getElementName(proposal));
    buffer.append('[');
    switch (proposal.getKind()) {
    case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
        buffer.append("ANONYMOUS_CLASS_DECLARATION"); //$NON-NLS-1$
        break;
    case CompletionProposal.FIELD_REF:
        buffer.append("FIELD_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
        buffer.append("FIELD_REF_WITH_CASTED_RECEIVER"); //$NON-NLS-1$
        break;
    case CompletionProposal.KEYWORD:
        buffer.append("KEYWORD"); //$NON-NLS-1$
        break;
    case CompletionProposal.LABEL_REF:
        buffer.append("LABEL_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.LOCAL_VARIABLE_REF:
        buffer.append("LOCAL_VARIABLE_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.METHOD_DECLARATION:
        buffer.append("METHOD_DECLARATION"); //$NON-NLS-1$
        if (proposal.isConstructor()) {
            buffer.append("<CONSTRUCTOR>"); //$NON-NLS-1$
        }
        break;
    case CompletionProposal.METHOD_REF:
        buffer.append("METHOD_REF"); //$NON-NLS-1$
        if (proposal.isConstructor()) {
            buffer.append("<CONSTRUCTOR>"); //$NON-NLS-1$
        }
        break;
    case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
        buffer.append("METHOD_REF_WITH_CASTED_RECEIVER"); //$NON-NLS-1$
        if (proposal.isConstructor()) {
            buffer.append("<CONSTRUCTOR>"); //$NON-NLS-1$
        }
        break;
    case CompletionProposal.PACKAGE_REF:
        buffer.append("PACKAGE_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.TYPE_REF:
        buffer.append("TYPE_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.VARIABLE_DECLARATION:
        buffer.append("VARIABLE_DECLARATION"); //$NON-NLS-1$
        break;
    case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
        buffer.append("POTENTIAL_METHOD_DECLARATION"); //$NON-NLS-1$
        break;
    case CompletionProposal.METHOD_NAME_REFERENCE:
        //{ObjectTeams: original "METHOD_IMPORT" is now misleading (used for rhs short method spec, too)            
        buffer.append("METHOD_NAME_REF"); //$NON-NLS-1$
        // SH}            
        break;
    //{ObjectTeams: new kinds:            
    case CompletionProposal.OT_METHOD_SPEC:
        buffer.append("METHOD_SPEC"); //$NON-NLS-1$
        break;
    case CompletionProposal.OT_FIELD_SPEC:
        buffer.append("FIELD_SPEC"); //$NON-NLS-1$
        break;
    case CompletionProposal.OT_CALLOUT_GET:
        buffer.append("CALLOUT_GET"); //$NON-NLS-1$
        break;
    case CompletionProposal.OT_CALLOUT_SET:
        buffer.append("CALLOUT_SET"); //$NON-NLS-1$
        break;
    case CompletionProposal.OT_CALLOUT_DECLARATION:
        buffer.append("CALLOUT_DECLARATION"); //$NON-NLS-1$
        break;
    case CompletionProposal.OT_CALLOUT_OVERRIDE_DECLARATION:
        buffer.append("CALLOUT_OVERRIDE_DECLARATION"); //$NON-NLS-1$
        break;
    case CompletionProposal.OT_CALLIN_DECLARATION:
        buffer.append("CALLIN_DECLARATION"); //$NON-NLS-1$
        break;
    // SH}
    case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
        buffer.append("ANNOTATION_ATTRIBUTE_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.JAVADOC_BLOCK_TAG:
        buffer.append("JAVADOC_BLOCK_TAG"); //$NON-NLS-1$
        break;
    case CompletionProposal.JAVADOC_INLINE_TAG:
        buffer.append("JAVADOC_INLINE_TAG"); //$NON-NLS-1$
        break;
    case CompletionProposal.JAVADOC_FIELD_REF:
        buffer.append("JAVADOC_FIELD_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.JAVADOC_METHOD_REF:
        buffer.append("JAVADOC_METHOD_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.JAVADOC_TYPE_REF:
        buffer.append("JAVADOC_TYPE_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.JAVADOC_PARAM_REF:
        buffer.append("JAVADOC_PARAM_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.JAVADOC_VALUE_REF:
        buffer.append("JAVADOC_VALUE_REF"); //$NON-NLS-1$
        break;
    case CompletionProposal.FIELD_IMPORT:
        buffer.append("FIELD_IMPORT"); //$NON-NLS-1$
        break;
    case CompletionProposal.METHOD_IMPORT:
        buffer.append("METHOD_IMPORT"); //$NON-NLS-1$
        break;
    case CompletionProposal.TYPE_IMPORT:
        buffer.append("TYPE_IMPORT"); //$NON-NLS-1$
        break;
    default:
        buffer.append("PROPOSAL"); //$NON-NLS-1$
        break;

    }
    buffer.append("]{");
    buffer.append(proposal.getCompletion() == null ? NULL_LITERAL : proposal.getCompletion());
    buffer.append(", ");
    buffer.append(
            proposal.getDeclarationSignature() == null ? NULL_LITERAL : proposal.getDeclarationSignature());
    buffer.append(", ");
    buffer.append(proposal.getSignature() == null ? NULL_LITERAL : proposal.getSignature());

    char[] receiverSignature = proposal.getReceiverSignature();
    if (receiverSignature != null) {
        buffer.append(", ");
        buffer.append(receiverSignature);
    }

    if (this.showUniqueKeys) {
        buffer.append(", ");
        buffer.append(proposal.getDeclarationKey() == null ? NULL_LITERAL : proposal.getDeclarationKey());
        buffer.append(", ");
        buffer.append(proposal.getKey() == null ? NULL_LITERAL : proposal.getKey());
    }
    buffer.append(", ");
    buffer.append(proposal.getName() == null ? NULL_LITERAL : proposal.getName());
    if (this.showParameterNames) {
        char[][] parameterNames = proposal.findParameterNames(null);
        buffer.append(", ");
        if (parameterNames == null || parameterNames.length <= 0) {
            buffer.append(NULL_LITERAL);
        } else {
            buffer.append("(");
            for (int i = 0; i < parameterNames.length; i++) {
                if (i > 0)
                    buffer.append(", ");
                buffer.append(parameterNames[i]);
            }
            buffer.append(")");
        }
    }

    if (this.showPositions) {
        buffer.append(", ");
        if (this.showTokenPositions || receiverSignature != null)
            buffer.append("replace");
        buffer.append("[");
        buffer.append(proposal.getReplaceStart());
        buffer.append(", ");
        buffer.append(proposal.getReplaceEnd());
        buffer.append("]");
    }
    if (this.showTokenPositions) {
        buffer.append(", token[");
        buffer.append(proposal.getTokenStart());
        buffer.append(", ");
        buffer.append(proposal.getTokenEnd());
        buffer.append("]");
    }
    if (this.showPositions && receiverSignature != null) {
        buffer.append(", receiver[");
        buffer.append(proposal.getReceiverStart());
        buffer.append(", ");
        buffer.append(proposal.getReceiverEnd());
        buffer.append("]");
    }
    buffer.append(", ");
    buffer.append(proposal.getRelevance());
    buffer.append('}');
    if (this.showMissingTypes) {
        CompletionProposal[] requiredProposals = proposal.getRequiredProposals();
        if (requiredProposals != null) {
            int length = requiredProposals.length;
            System.arraycopy(requiredProposals, 0, requiredProposals = new CompletionProposal[length], 0,
                    length);
            quickSort(requiredProposals, 0, length - 1);
            for (int i = 0; i < length; i++) {
                buffer.append('\n');
                printProposal(requiredProposals[i], tab + 1, buffer);
            }
        }
    }
    return buffer;
}

From source file:org.jboss.tools.vscode.java.CompletionProposalDescriptionProvider.java

License:Open Source License

/**
 * Creates a display label for the given method proposal. The display label
 * consists of:/*from   w  w  w  .  j  av a2 s  .c  o m*/
 * <ul>
 *   <li>the method name</li>
 *   <li>the parameter list (see {@link #createParameterList(CompletionProposal)})</li>
 *   <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})</li>
 *   <li>the raw simple name of the declaring type</li>
 * </ul>
 * <p>
 * Examples:
 * For the <code>get(int)</code> method of a variable of type <code>List<? extends Number></code>, the following
 * display name is returned: <code>get(int index)  Number - List</code>.<br>
 * For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the following
 * display name is returned: <code>add(Number o)  void - List</code>.<br>
 * </p>
 *
 * @param methodProposal the method proposal to display
 * @return the display label for the given method proposal
 */
StringBuilder createMethodProposalLabel(CompletionProposal methodProposal) {
    StringBuilder description = new StringBuilder();

    // method name
    description.append(methodProposal.getName());

    // parameters
    description.append('(');
    appendUnboundedParameterList(description, methodProposal);
    description.append(')');

    // return type
    if (!methodProposal.isConstructor()) {
        // TODO remove SignatureUtil.fix83600 call when bugs are fixed
        char[] returnType = createTypeDisplayName(SignatureUtil
                .getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature()))));
        description.append(RETURN_TYPE_SEPARATOR);
        description.append(returnType);
    }

    // declaring type
    description.append(QUALIFIER_SEPARATOR);
    String declaringType = extractDeclaringTypeFQN(methodProposal);

    if (methodProposal.getRequiredProposals() != null) {
        String qualifier = Signature.getQualifier(declaringType);
        if (qualifier.length() > 0) {
            description.append(qualifier);
            description.append('.');
        }
    }

    declaringType = Signature.getSimpleName(declaringType);
    description.append(declaringType);

    return description;
}

From source file:org.jboss.tools.vscode.java.CompletionProposalDescriptionProvider.java

License:Open Source License

StringBuilder createLabelWithTypeAndDeclaration(CompletionProposal proposal) {
    char[] name = proposal.getCompletion();
    if (!isThisPrefix(name))
        name = proposal.getName();//from  w ww.  j a  v  a2s  .  c  om
    StringBuilder buf = new StringBuilder();

    buf.append(name);
    char[] typeName = Signature.getSignatureSimpleName(proposal.getSignature());
    if (typeName.length > 0) {
        buf.append(VAR_TYPE_SEPARATOR);
        buf.append(typeName);
    }

    char[] declaration = proposal.getDeclarationSignature();
    if (declaration != null) {
        declaration = Signature.getSignatureSimpleName(declaration);
        if (declaration.length > 0) {
            buf.append(QUALIFIER_SEPARATOR);
            if (proposal.getRequiredProposals() != null) {
                String declaringType = extractDeclaringTypeFQN(proposal);
                String qualifier = Signature.getQualifier(declaringType);
                if (qualifier.length() > 0) {
                    buf.append(qualifier);
                    buf.append('.');
                }
            }
            buf.append(declaration);
        }
    }
    return buf;
}

From source file:org.jboss.tools.vscode.java.CompletionProposalDescriptionProvider.java

License:Open Source License

StringBuilder createAnonymousTypeLabel(CompletionProposal proposal) {
    char[] declaringTypeSignature = proposal.getDeclarationSignature();
    declaringTypeSignature = Signature.getTypeErasure(declaringTypeSignature);

    StringBuilder buf = new StringBuilder();

    buf.append(Signature.getSignatureSimpleName(declaringTypeSignature));
    buf.append('(');
    appendUnboundedParameterList(buf, proposal);
    buf.append(')');
    buf.append("  "); //$NON-NLS-1$
    buf.append("Anonymous Inner Type"); //TODO: consider externalization
    if (proposal.getRequiredProposals() != null) {
        char[] signatureQualifier = Signature.getSignatureQualifier(declaringTypeSignature);
        if (signatureQualifier.length > 0) {
            buf.append(",");
            buf.append(QUALIFIER_SEPARATOR);
            buf.append(signatureQualifier);
        }//from  ww  w.  j  a  va  2s.  com
    }
    return buf;
}

From source file:org.jboss.tools.vscode.java.internal.CompletionProposalDescriptionProvider.java

License:Open Source License

/**
 * Updates a display label for the given method proposal to item. The display label
 * consists of:/*from w w w  .j av a 2 s. c om*/
 * <ul>
 *   <li>the method name</li>
 *   <li>the parameter list (see {@link #createParameterList(CompletionProposal)})</li>
 *   <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})</li>
 *   <li>the raw simple name of the declaring type</li>
 * </ul>
 * <p>
 * Examples:
 * For the <code>get(int)</code> method of a variable of type <code>List<? extends Number></code>, the following
 * display name is returned: <code>get(int index)  Number - List</code>.<br>
 * For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the following
 * display name is returned: <code>add(Number o)  void - List</code>.<br>
 * </p>
 *
 * @param methodProposal the method proposal to display
 * @param item to update 
 */
private void createMethodProposalLabel(CompletionProposal methodProposal, CompletionItem item) {
    StringBuilder description = new StringBuilder();

    // method name
    description.append(methodProposal.getName());

    // parameters
    description.append('(');
    appendUnboundedParameterList(description, methodProposal);
    description.append(')');

    // return type
    if (!methodProposal.isConstructor()) {
        // TODO remove SignatureUtil.fix83600 call when bugs are fixed
        char[] returnType = createTypeDisplayName(SignatureUtil
                .getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature()))));
        description.append(RETURN_TYPE_SEPARATOR);
        description.append(returnType);
    }

    item.setLabel(description.toString());
    // declaring type
    StringBuilder typeInfo = new StringBuilder();
    String declaringType = extractDeclaringTypeFQN(methodProposal);

    if (methodProposal.getRequiredProposals() != null) {
        String qualifier = Signature.getQualifier(declaringType);
        if (qualifier.length() > 0) {
            typeInfo.append(qualifier);
            typeInfo.append('.');
        }
    }

    declaringType = Signature.getSimpleName(declaringType);
    typeInfo.append(declaringType);
    item.setDetail(typeInfo.toString());

    setSignature(item, String.valueOf(methodProposal.getSignature()));
    setDeclarationSignature(item, String.valueOf(methodProposal.getDeclarationSignature()));
    setName(item, String.valueOf(methodProposal.getName()));

}