Search in sources :

Example 6 with XtextSourceViewerConfiguration

use of org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration in project xtext-eclipse by eclipse.

the class ContentAssistProcessorTestBuilder method assertMatchString.

public ContentAssistProcessorTestBuilder assertMatchString(String matchString) throws Exception {
    String currentModelToParse = getModel();
    final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(currentModelToParse));
    final IXtextDocument xtextDocument = getDocument(xtextResource, currentModelToParse);
    XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
    Shell shell = new Shell();
    try {
        ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
        IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
        String contentType = xtextDocument.getContentType(currentModelToParse.length());
        if (contentAssistant.getContentAssistProcessor(contentType) != null) {
            ContentAssistContext.Factory factory = get(ContentAssistContext.Factory.class);
            ContentAssistContext[] contexts = factory.create(sourceViewer, currentModelToParse.length(), xtextResource);
            for (ContentAssistContext context : contexts) {
                Assert.assertTrue("matchString = '" + matchString + "', actual: '" + context.getPrefix() + "'", "".equals(context.getPrefix()) || matchString.equals(context.getPrefix()));
            }
        } else {
            Assert.fail("No content assistant for content type " + contentType);
        }
        return this;
    } finally {
        shell.dispose();
    }
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) Shell(org.eclipse.swt.widgets.Shell) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) XtextResource(org.eclipse.xtext.resource.XtextResource) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Example 7 with XtextSourceViewerConfiguration

use of org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration in project xtext-eclipse by eclipse.

the class ContentAssistProcessorTestBuilder method applyProposal.

protected ContentAssistProcessorTestBuilder applyProposal(ICompletionProposal proposal, int position, IXtextDocument document) throws Exception {
    Shell shell = new Shell();
    try {
        XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
        ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
        return appendAndApplyProposal(proposal, sourceViewer, model, position);
    } finally {
        shell.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Example 8 with XtextSourceViewerConfiguration

use of org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration in project xtext-eclipse by eclipse.

the class ContentAssistProcessorTestBuilder method computeCompletionProposals.

protected ICompletionProposal[] computeCompletionProposals(final IXtextDocument xtextDocument, int cursorPosition, Shell shell) throws BadLocationException {
    XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
    ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
    return computeCompletionProposals(xtextDocument, cursorPosition, configuration, sourceViewer);
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Example 9 with XtextSourceViewerConfiguration

use of org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration in project xtext-eclipse by eclipse.

the class ContentAssistProcessorTestBuilder method assertMatchString.

public ContentAssistProcessorTestBuilder assertMatchString(String matchString) throws Exception {
    String currentModelToParse = getModel();
    final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(currentModelToParse));
    final IXtextDocument xtextDocument = getDocument(xtextResource, currentModelToParse);
    XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
    Shell shell = new Shell();
    try {
        ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
        IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
        String contentType = xtextDocument.getContentType(currentModelToParse.length());
        if (contentAssistant.getContentAssistProcessor(contentType) != null) {
            ContentAssistContext.Factory factory = get(ContentAssistContext.Factory.class);
            ContentAssistContext[] contexts = factory.create(sourceViewer, currentModelToParse.length(), xtextResource);
            for (ContentAssistContext context : contexts) {
                Assert.assertTrue("matchString = '" + matchString + "', actual: '" + context.getPrefix() + "'", "".equals(context.getPrefix()) || matchString.equals(context.getPrefix()));
            }
        } else {
            Assert.fail("No content assistant for content type " + contentType);
        }
        return this;
    } finally {
        shell.dispose();
    }
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) Shell(org.eclipse.swt.widgets.Shell) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) XtextResource(org.eclipse.xtext.resource.XtextResource) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Example 10 with XtextSourceViewerConfiguration

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

the class AcfContentAssistProcessorTestBuilder method internalComputeCompletionProposals.

/**
 * Internally compute completion proposals.
 *
 * @param cursorPosition
 *          the position of the cursor in the {@link IXtextDocument}
 * @param xtextDocument
 *          the {@link IXtextDocument}
 * @return a pair of {@link ICompletionProposal}[] and {@link BadLocationException}. If the tail argument is not {@code null}, an exception occurred in the UI
 *         thread.
 */
private Pair<ICompletionProposal[], BadLocationException> internalComputeCompletionProposals(final int cursorPosition, final IXtextDocument xtextDocument) {
    XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
    Shell shell = new Shell();
    try {
        ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
        IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
        String contentType = xtextDocument.getContentType(cursorPosition);
        IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
        if (processor != null) {
            return Tuples.create(processor.computeCompletionProposals(sourceViewer, cursorPosition), null);
        }
        return Tuples.create(new ICompletionProposal[0], null);
    } catch (BadLocationException e) {
        return Tuples.create(new ICompletionProposal[0], e);
    } finally {
        shell.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) BadLocationException(org.eclipse.jface.text.BadLocationException) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Aggregations

XtextSourceViewerConfiguration (org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)10 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)9 Shell (org.eclipse.swt.widgets.Shell)7 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)4 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IContentAssistProcessor (org.eclipse.jface.text.contentassist.IContentAssistProcessor)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 ContentAssistContext (org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 CompletionProposalComputer (org.eclipse.xtext.ui.editor.contentassist.CompletionProposalComputer)1