Search in sources :

Example 1 with XtextSourceViewerConfiguration

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

the class ContentAssistProcessorTestBuilder method appendAndApplyProposal.

public ContentAssistProcessorTestBuilder appendAndApplyProposal(String model, int position, String proposalString) throws Exception {
    IXtextDocument document = getDocument(getModel());
    Shell shell = new Shell();
    try {
        XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
        ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
        ICompletionProposal[] proposals = computeCompletionProposals(document, position, shell);
        ICompletionProposal proposal = findProposal(proposalString, proposals);
        return appendAndApplyProposal(proposal, sourceViewer, model, position);
    } finally {
        shell.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Example 2 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 3 with XtextSourceViewerConfiguration

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

the class ContentAssistProcessorTestBuilder method appendAndApplyProposal.

public ContentAssistProcessorTestBuilder appendAndApplyProposal(String model, int position, String proposalString) throws Exception {
    IXtextDocument document = getDocument(getModel());
    Shell shell = new Shell();
    try {
        XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
        ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
        ICompletionProposal[] proposals = computeCompletionProposals(document, position, shell);
        ICompletionProposal proposal = findProposal(proposalString, proposals);
        return appendAndApplyProposal(proposal, sourceViewer, model, position);
    } finally {
        shell.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Example 4 with XtextSourceViewerConfiguration

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

the class AbstractContentAssistUiTest method createCompletionProposalComputer.

/**
 * Helper function to find the correct CompletionProposalComputer for the given offset.
 *
 * @param offset
 *          offset in test file
 * @return language and offset specific content assist proposal computer
 */
private CompletionProposalComputer createCompletionProposalComputer(final int offset) {
    XtextSourceViewerConfiguration configuration = getEditor().getXtextSourceViewerConfiguration();
    IContentAssistant contentAssistant = configuration.getContentAssistant(getViewer());
    IContentAssistProcessor contentAssistProcessor;
    try {
        contentAssistProcessor = contentAssistant.getContentAssistProcessor(getDocument().getContentType(offset));
    } catch (BadLocationException e) {
        contentAssistProcessor = getTestUtil().get(IContentAssistProcessor.class);
    }
    if (contentAssistProcessor == null) {
        contentAssistProcessor = getTestUtil().get(IContentAssistProcessor.class);
    }
    return new CompletionProposalComputer((State) contentAssistProcessor, (ITextViewer) getViewer(), offset);
}
Also used : CompletionProposalComputer(org.eclipse.xtext.ui.editor.contentassist.CompletionProposalComputer) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) BadLocationException(org.eclipse.jface.text.BadLocationException) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Example 5 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)

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