Search in sources :

Example 1 with XtextTemplateProposal

use of org.eclipse.xtext.ui.editor.templates.XtextTemplateProposal in project dsl-devkit by dsldevkit.

the class AcfContentAssistProcessorTestBuilder method applyText.

/**
 * Applies a content assist proposal using the expected display string.
 *
 * @param expectedDisplayString
 *          the content assist proposal to apply
 * @param appendSpace
 *          whether to append a space
 * @return a new {@link AcfContentAssistProcessorTestBuilder} with the text applied.
 * @throws Exception
 *           if there was a problem loading the xtext resource
 */
public AcfContentAssistProcessorTestBuilder applyText(final String expectedDisplayString, final boolean appendSpace) throws Exception {
    ICompletionProposal proposal = null;
    for (final ICompletionProposal p : computeCompletionProposals(getModel(), getCursorPosition())) {
        if (expectedDisplayString.equals(p.getDisplayString())) {
            proposal = p;
            break;
        }
    }
    assertNotNull(MessageFormat.format("\"{0}\" not a valid completion proposal", expectedDisplayString), proposal);
    String text = "";
    if (proposal instanceof ConfigurableCompletionProposal) {
        text = ((ConfigurableCompletionProposal) proposal).getReplacementString();
    } else if (proposal instanceof XtextTemplateProposal) {
        // These may occur in the context of custom content assist templates
        text = ((XtextTemplateProposal) proposal).getAdditionalProposalInfo();
    }
    AcfContentAssistProcessorTestBuilder ret = append(text);
    if (appendSpace) {
        return ret.append(" ");
    }
    return ret;
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) XtextTemplateProposal(org.eclipse.xtext.ui.editor.templates.XtextTemplateProposal)

Aggregations

ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)1 XtextTemplateProposal (org.eclipse.xtext.ui.editor.templates.XtextTemplateProposal)1