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

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

Introduction

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

Prototype

public int getReplaceEnd() 

Source Link

Document

Returns the character index of the end of the subrange in the source file buffer to be replaced by the completion string.

Usage

From source file:com.microsoft.javapkgsrv.JavaParser.java

License:MIT License

private AutocompleteResponse.Completion translateToCompletion(CompletionProposal proposal) {
    AutocompleteResponse.Completion.Builder builder = AutocompleteResponse.Completion.newBuilder()
            .setKind(AutocompleteResponse.Completion.CompletionKind.valueOf(proposal.getKind()))
            .setIsConstructor(proposal.isConstructor())
            .setCompletionText(String.copyValueOf(proposal.getCompletion())).setFlags(proposal.getFlags())
            .setRelevance(proposal.getRelevance()).setReplaceStart(proposal.getReplaceStart())
            .setReplaceEnd(proposal.getReplaceEnd());

    char[] sig = proposal.getSignature();

    if (sig != null) {
        if (proposal.getKind() == CompletionProposal.METHOD_REF
                || proposal.getKind() == CompletionProposal.JAVADOC_METHOD_REF)
            builder.setSignature(new String(Signature.toCharArray(sig, proposal.getName(), null, false, true)));
        else/*from ww w  . ja v a2s  .  c om*/
            builder.setSignature(new String(Signature.toCharArray(sig)));
    }
    char[] name = proposal.getName();
    if (name == null)
        builder.setName(builder.getCompletionText());
    else
        builder.setName(String.copyValueOf(name));
    return builder.build();
}

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   ww  w .j a v a  2  s . c  om*/
    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.bonitasoft.studio.contract.ui.property.constraint.edit.editor.contentassist.ContractInputProposalsCodeVisitorSupport.java

License:Open Source License

private ICompletionProposal createProposalFor(final ContentAssistInvocationContext context,
        final CharSequence prefix, final ContractInput input) {
    final String name = input.getName();
    final CompletionProposal proposal = CompletionProposal.create(CompletionProposal.FIELD_REF,
            context.getInvocationOffset());
    proposal.setCompletion(name.substring(prefix.length()).toCharArray());
    proposal.setName(name.toCharArray());
    proposal.setFlags(Flags.AccPublic);/*from w  w w .  j a  va  2s .c  o m*/
    proposal.setReplaceRange(context.getInvocationOffset(), context.getInvocationOffset());
    final String completion = String.valueOf(proposal.getCompletion());
    final int start = proposal.getReplaceStart();
    final int end = proposal.getReplaceEnd();
    final int length = end - start;

    final ContractInputLabelProvider labelProvider = new ContractInputLabelProvider();
    final Image image = labelProvider.getImage(input);
    return new JavaCompletionProposal(completion, start, length, image, labelProvider.getStyledString(input),
            100, false);
}

From source file:org.bonitasoft.studio.groovy.ui.contentassist.VariablesCompletionProposalProvider.java

License:Open Source License

private JavaCompletionProposal getProposalFor(final ContentAssistInvocationContext context,
        final CompletionProposalLabelProvider fLabelProvider, final CharSequence prefix, final String name,
        final String typeName) {
    final CompletionProposal proposal = CompletionProposal.create(CompletionProposal.FIELD_REF,
            context.getInvocationOffset());
    proposal.setCompletion(name.substring(prefix.length()).toCharArray());
    proposal.setName(name.toCharArray());
    proposal.setFlags(Flags.AccPublic);/*from w  ww  .  j  ava  2s  . c  om*/
    proposal.setReplaceRange(context.getInvocationOffset(), context.getInvocationOffset());
    //        Class type = BonitaSyntaxHighlighting.getTypeForKeyWord(keyWord) ;
    if (typeName != null) {
        proposal.setSignature(Signature.createTypeSignature(typeName, true).toCharArray());
    }
    String completion = String.valueOf(proposal.getCompletion());
    int start = proposal.getReplaceStart();
    int end = proposal.getReplaceEnd();
    int length = end - start;

    StyledString label = fLabelProvider.createStyledLabel(proposal);
    final Image image = JavaPlugin.getImageDescriptorRegistry()
            .get(fLabelProvider.createImageDescriptor(proposal));
    return new JavaCompletionProposal(completion, start, length, image, label, 100, false);

    //        final CompletionProposal proposal = CompletionProposal.create(CompletionProposal.FIELD_REF, context.getInvocationOffset());
    //        proposal.setCompletion(name.toCharArray());
    //        proposal.setName(name.toCharArray());
    //        proposal.setFlags(Flags.AccPublic);
    //        proposal.setReplaceRange(context.getInvocationOffset() - prefix.length(), context.getInvocationOffset() + name.length() - prefix.length());
    //        if (typeName != null) {
    //            proposal.setSignature(Signature.createTypeSignature(typeName, true).toCharArray());
    //        }
    //        final String completion = String.valueOf(proposal.getCompletion());
    //        final int start = proposal.getReplaceStart();
    //        final int end = proposal.getReplaceEnd();
    //        final int length = end - start;
    //
    //        final StyledString label = fLabelProvider.createStyledLabel(proposal);
    //
    //        final BonitaConstantsCompletionProposal javaProposal = new BonitaConstantsCompletionProposal(
    //                ((JavaContentAssistInvocationContext) context).getCompilationUnit(), completion, start, length, image, label, 1000, false,
    //                (JavaContentAssistInvocationContext) context);
    //        return javaProposal;
}

From source file:org.codehaus.groovy.eclipse.codeassist.proposals.GroovyJavaFieldCompletionProposal.java

License:Apache License

public GroovyJavaFieldCompletionProposal(CompletionProposal proposal, Image image, StyledString displayString) {
    super(String.valueOf(proposal.getName()), proposal.getReplaceStart(),
            proposal.getReplaceEnd() - proposal.getReplaceStart(), image, displayString,
            proposal.getRelevance());/*from  w w w  .ja  v  a2 s.c  om*/
    this.proposal = proposal;
    this.setRelevance(proposal.getRelevance());
    this.setTriggerCharacters(ProposalUtils.VAR_TRIGGER);
}

From source file:org.eclipse.ajdt.internal.core.contentassist.ProposalRequestorWrapper.java

License:Open Source License

private void translateReplaceRange(CompletionProposal proposal) {
    int s = proposal.getReplaceStart();
    int e = proposal.getReplaceEnd();
    proposal.setReplaceRange(trans(s), trans(e));

    /* AJDT 1.7 */
    // translate all proposals contained in this one
    if (proposal instanceof InternalCompletionProposal) {
        InternalCompletionProposal internalProposal = (InternalCompletionProposal) proposal;
        if (internalProposal.getRequiredProposals() != null) {
            for (int i = 0; i < internalProposal.getRequiredProposals().length; i++) {
                translateReplaceRange(internalProposal.getRequiredProposals()[i]);
            }//from  w w w .j  a  v a 2  s. c o  m
        }
    }
}

From source file:org.eclipse.jst.jsp.ui.internal.contentassist.JSPELProposalCollector.java

License:Open Source License

protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) {
    JSPCompletionProposal jspProposal = null;

    if (null == proposal || null == proposal.getName())
        return (null);

    String rawName = new String(proposal.getName());
    String completion = null;//from w w w  .j  a  va2  s  .  com

    if (proposal.getKind() == CompletionProposal.METHOD_REF && proposal.findParameterNames(null).length == 0) {
        if (rawName.length() > 3 && rawName.startsWith("get")) { //$NON-NLS-1$
            completion = rawName.substring(3, 4).toLowerCase() + rawName.substring(4, rawName.length());
        } else {
            return null;
        }

        // java offset
        int offset = proposal.getReplaceStart();

        // replacement length
        //-3 for "get" pre text on the java proposal
        int length = proposal.getReplaceEnd() - offset - 3;

        // translate offset from Java > JSP
        offset = getTranslation().getJspOffset(offset);

        // cursor position after must be calculated
        int positionAfter = offset + completion.length();

        // from java proposal
        IJavaCompletionProposal javaProposal = super.createJavaCompletionProposal(proposal);
        Image image = null;
        String longDisplayString = javaProposal.getDisplayString();
        int fistSpaceIndex = longDisplayString.indexOf(' ');
        String shortDisplayString = longDisplayString;

        if (fistSpaceIndex != -1) {
            shortDisplayString = longDisplayString.substring(fistSpaceIndex);
        }

        String displayString = completion + " " + shortDisplayString; //$NON-NLS-1$
        IContextInformation contextInformation = javaProposal.getContextInformation();
        String additionalInfo = javaProposal.getAdditionalProposalInfo();
        int relevance = javaProposal.getRelevance();

        boolean updateLengthOnValidate = true;

        jspProposal = new JSPCompletionProposal(completion, offset, length, positionAfter, image, displayString,
                contextInformation, additionalInfo, relevance, updateLengthOnValidate);

        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483
        // set wrapped java proposal so additional info can be calculated on demand
        jspProposal.setJavaCompletionProposal(javaProposal);

        return jspProposal;
    } else {
        return null;
    }
}

From source file:org.eclipse.jst.jsp.ui.internal.contentassist.JSPProposalCollector.java

License:Open Source License

private JSPCompletionProposal createAutoImportProposal(CompletionProposal proposal) {

    JSPCompletionProposal jspProposal = null;

    String completion = new String(proposal.getCompletion());

    // it's fully qualified so we should
    // add an import statement
    // create an autoimport proposal
    String newCompletion = getTypeName(completion);

    // java offset
    int offset = proposal.getReplaceStart();
    // replacement length
    int length = proposal.getReplaceEnd() - offset;
    // translate offset from Java > JSP
    offset = fTranslation.getJspOffset(offset);
    // cursor position after must be calculated
    int positionAfter = calculatePositionAfter(proposal, newCompletion, offset);

    // from java proposal
    IJavaCompletionProposal javaProposal = super.createJavaCompletionProposal(proposal);
    proposal.getDeclarationSignature();/*from  w  w w  .  j a  v a2 s.c o m*/
    Image image = javaProposal.getImage();
    String displayString = javaProposal.getDisplayString();
    displayString = getTranslation().fixupMangledName(displayString);
    IContextInformation contextInformation = javaProposal.getContextInformation();
    // don't do this, it's slow
    // String additionalInfo = javaProposal.getAdditionalProposalInfo();
    int relevance = javaProposal.getRelevance();

    boolean updateLengthOnValidate = true;

    jspProposal = new AutoImportProposal(completion, fImportContainer, newCompletion, offset, length,
            positionAfter, image, displayString, contextInformation, null, relevance, updateLengthOnValidate);

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483
    // set wrapped java proposal so additional info can be calculated on demand
    jspProposal.setJavaCompletionProposal(javaProposal);

    return jspProposal;
}

From source file:org.eclipse.jst.jsp.ui.internal.contentassist.JSPProposalCollector.java

License:Open Source License

private JSPCompletionProposal createJspProposal(CompletionProposal proposal) {

    JSPCompletionProposal jspProposal;//from   w w  w .  j av  a  2 s  .c om
    String completion = String.valueOf(proposal.getCompletion());
    // java offset
    int offset = proposal.getReplaceStart();
    // replacement length
    int length = proposal.getReplaceEnd() - offset;
    // translate offset from Java > JSP
    offset = fTranslation.getJspOffset(offset);
    // cursor position after must be calculated
    int positionAfter = calculatePositionAfter(proposal, completion, offset);

    // from java proposal
    IJavaCompletionProposal javaProposal = super.createJavaCompletionProposal(proposal);
    proposal.getDeclarationSignature();
    Image image = javaProposal.getImage();
    String displayString = javaProposal.getDisplayString();
    displayString = getTranslation().fixupMangledName(displayString);
    IContextInformation contextInformation = javaProposal.getContextInformation();
    // String additionalInfo = javaProposal.getAdditionalProposalInfo();

    /* the context information is calculated with respect to the java document
     * thus it needs to be updated in respect of the JSP document.
     */
    if (contextInformation instanceof IContextInformationExtension) {
        contextInformation = new JavaContextInformationWrapper(contextInformation);
    }

    int relevance = javaProposal.getRelevance();

    boolean updateLengthOnValidate = true;

    jspProposal = new JSPCompletionProposal(completion, offset, length, positionAfter, image, displayString,
            contextInformation, null, relevance, updateLengthOnValidate);

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483
    // set wrapped java proposal so additional info can be calculated on demand
    jspProposal.setJavaCompletionProposal(javaProposal);

    return jspProposal;
}

From source file:org.eclipse.jst.jsp.ui.internal.contentassist.JSPProposalCollector.java

License:Open Source License

private JSPCompletionProposal createMethodProposal(CompletionProposal proposal) {

    JSPCompletionProposal jspProposal;// w  ww.j av  a 2s. c  o  m
    String completion = String.valueOf(proposal.getCompletion());
    // java offset
    int offset = proposal.getReplaceStart();
    // replacement length
    int length = proposal.getReplaceEnd() - offset;
    // translate offset from Java > JSP
    offset = fTranslation.getJspOffset(offset);
    // cursor position after must be calculated
    int positionAfter = calculatePositionAfter(proposal, completion, offset);

    // from java proposal
    IJavaCompletionProposal javaProposal = super.createJavaCompletionProposal(proposal);
    proposal.getDeclarationSignature();
    Image image = javaProposal.getImage();
    String displayString = javaProposal.getDisplayString();
    displayString = getTranslation().fixupMangledName(displayString);
    IContextInformation contextInformation = javaProposal.getContextInformation();
    // String additionalInfo = javaProposal.getAdditionalProposalInfo();

    /* the context information is calculated with respect to the java document
     * thus it needs to be updated in respect of the JSP document.
     */
    if (contextInformation instanceof IContextInformationExtension) {
        contextInformation = new JavaContextInformationWrapper(contextInformation);
    }

    int relevance = javaProposal.getRelevance();

    boolean updateLengthOnValidate = true;

    jspProposal = new JSPMethodCompletionProposal(proposal, fTranslation.getJavaProject(), completion, offset,
            length, positionAfter, image, displayString, contextInformation, null, relevance,
            updateLengthOnValidate);

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483
    // set wrapped java proposal so additional info can be calculated on demand
    jspProposal.setJavaCompletionProposal(javaProposal);

    return jspProposal;
}