下面列出了org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Returns the completion proposal available at the given offset of the viewer's document. Delegates the work to the
* code assistant.
*
* @param offset
* the offset
* @param autoActivated
* @return the completion proposals available at this offset
*/
private ICompletionProposal[] computeProposals(int offset, boolean autoActivated)
{
if (fContentAssistSubjectControl != null)
{
return fContentAssistant.computeCompletionProposals(fContentAssistSubjectControl, offset, fActivationKey);
}
IContentAssistProcessor processor = fContentAssistant.getProcessor(fViewer, offset);
if (processor == null) {
return null;
}
if (processor instanceof ICommonContentAssistProcessor) {
ICommonContentAssistProcessor commonProcessor = (ICommonContentAssistProcessor)processor;
return commonProcessor.computeCompletionProposals(fViewer, offset, fActivationKey, autoActivated);
} else {
return processor.computeCompletionProposals(fViewer, offset);
}
}
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];
}
@SuppressWarnings("unchecked")
protected void doComputeCompletionProposals(T context, List<ICompletionProposal> completionProposals) {
for (IContentAssistProcessor contentAssistProcessor : contentAssistProcessors) {
if (contentAssistProcessor instanceof ICompletionContextUser) {
((ICompletionContextUser<T>)contentAssistProcessor).setCompletionContext(context);
}
ICompletionProposal[] cp = contentAssistProcessor.computeCompletionProposals(context.getViewer(), context.getOffset());
CollectionUtils.addAll(completionProposals, cp);
}
}
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;
}
/**
* Returns an array of completion proposals computed based on the specified document position. The position is used
* to determine the appropriate code assist processor to invoke.
*
* @param viewer
* the viewer for which to compute the proposals
* @param offset
* a document offset
* @param autoActivated
* determines whether we were autoActivated or not
* @return an array of completion proposals
* @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
*/
ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset, char activationChar,
boolean autoActivated)
{
fLastErrorMessage = null;
fUserAgentColumnCount = 0;
ICompletionProposal[] result = null;
IContentAssistProcessor processor = this.getProcessor(viewer, offset);
if (processor != null)
{
if (processor instanceof ICommonContentAssistProcessor)
{
ICommonContentAssistProcessor commonProcessor = (ICommonContentAssistProcessor) processor;
result = commonProcessor.computeCompletionProposals(viewer, offset, activationChar, autoActivated);
String[] ids = ((ICommonContentAssistProcessor) processor).getActiveUserAgentIds();
fUserAgentColumnCount = (ids != null) ? ids.length : 0;
}
else
{
result = processor.computeCompletionProposals(viewer, offset);
}
fLastErrorMessage = processor.getErrorMessage();
}
return result;
}