下面列出了org.eclipse.jface.text.contentassist.IContentAssistant#getContentAssistProcessor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
}
public ContentAssistProcessorTestBuilder assertMatchString(String matchString)
throws Exception {
String currentModelToParse = getModel();
final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(currentModelToParse, getEncoding()));
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();
}
}
/**
* 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();
}
}
/**
* Requests proposals in the last location of the given editor.
*/
protected ICompletionProposalHandle[] requestProposals(String mod1Contents, PyEdit editor) {
editor.setSelection(mod1Contents.length(), 0);
IContentAssistant contentAssistant = editor.getEditConfiguration().getContentAssistant(
editor.getPySourceViewer());
SimpleAssistProcessor processor = (SimpleAssistProcessor) contentAssistant
.getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE);
processor.doCycle(); //we want to show the default completions in this case (not the simple ones)
ICompletionProposal[] props = processor.computeCompletionProposals(editor.getPySourceViewer(),
mod1Contents.length());
ArrayList<ICompletionProposalHandle> lst = new ArrayList<>(props.length);
for (ICompletionProposal iCompletionProposal : props) {
lst.add((ICompletionProposalHandle) iCompletionProposal);
}
return lst.toArray(new ICompletionProposalHandle[0]);
}
protected ICompletionProposal[] computeCompletionProposals(final IXtextDocument xtextDocument, int cursorPosition,
XtextSourceViewerConfiguration configuration, ISourceViewer sourceViewer) throws BadLocationException {
IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
String contentType = xtextDocument.getContentType(cursorPosition);
IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
if (processor != null) {
return processor.computeCompletionProposals(sourceViewer, cursorPosition);
}
return new ICompletionProposal[0];
}
protected ICompletionProposal[] computeCompletionProposals(final IXtextDocument xtextDocument, int cursorPosition,
XtextSourceViewerConfiguration configuration, ISourceViewer sourceViewer) throws BadLocationException {
IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
String contentType = xtextDocument.getContentType(cursorPosition);
IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
if (processor != null) {
return processor.computeCompletionProposals(sourceViewer, cursorPosition);
}
return new ICompletionProposal[0];
}
private ICompletionProposal[] computeCompletionProposals(
final IXtextDocument xtextDocument, int cursorPosition,
XtextSourceViewerConfiguration configuration,
ISourceViewer sourceViewer) throws BadLocationException {
IContentAssistant contentAssistant = configuration
.getContentAssistant(sourceViewer);
String contentType = xtextDocument.getContentType(cursorPosition);
IContentAssistProcessor processor = contentAssistant
.getContentAssistProcessor(contentType);
if (processor != null) {
return processor.computeCompletionProposals(sourceViewer,
cursorPosition);
}
return new ICompletionProposal[0];
}
public ICompletionProposal[] computeCompletionProposals(final XtextEditor editorForCompletion, final XtextEditor dirtyEditor, final int cursorPosition) throws BadLocationException {
this.syncUtil.waitForReconciler(dirtyEditor);
final ISourceViewer sourceViewer = editorForCompletion.getInternalSourceViewer();
final IContentAssistant contentAssistant = editorForCompletion.getXtextSourceViewerConfiguration().getContentAssistant(sourceViewer);
final String contentType = editorForCompletion.getDocument().getContentType(cursorPosition);
final IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
if ((processor != null)) {
return processor.computeCompletionProposals(sourceViewer, cursorPosition);
}
return null;
}
/**
* 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);
}