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();
}
}
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();
}
}
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);
}
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();
}
}
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();
}
}
Aggregations