下面列出了怎么用org.eclipse.jface.text.contentassist.IContentAssistProcessor的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Creates the content assistant.
*
* @return the content assistant
*/
private SubjectControlContentAssistant createContentAssistant() {
final SubjectControlContentAssistant contentAssistant = new SubjectControlContentAssistant();
contentAssistant.setRestoreCompletionProposalSize(
CheckstyleUIPlugin.getDefault().getDialogSettings());
IContentAssistProcessor processor = new RegExContentAssistProcessor(true);
contentAssistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
contentAssistant.setInformationControlCreator(new IInformationControlCreator() {
/*
* @see org.eclipse.jface.text.IInformationControlCreator# createInformationControl(
* org.eclipse.swt.widgets.Shell)
*/
@Override
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent);
}
});
return contentAssistant;
}
/**
* Creates the content assistant.
*
* @return the content assistant
*/
private SubjectControlContentAssistant createContentAssistant() {
final SubjectControlContentAssistant contentAssistant = new SubjectControlContentAssistant();
contentAssistant
.setRestoreCompletionProposalSize(CheckstyleUIPlugin.getDefault().getDialogSettings());
IContentAssistProcessor processor = new RegExContentAssistProcessor(true);
contentAssistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
contentAssistant.setInformationControlCreator(new IInformationControlCreator() {
/*
* @see IInformationControlCreator#createInformationControl(Shell)
*/
@Override
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent);
}
});
return contentAssistant;
}
public static IContentAssistant configContentAssistant(IPySyntaxHighlightingAndCodeCompletionEditor edit,
PyContentAssistant pyContentAssistant) {
// next create a content assistant processor to populate the completions window
IContentAssistProcessor processor = new SimpleAssistProcessor(edit, new PythonCompletionProcessor(edit,
pyContentAssistant), pyContentAssistant);
PythonStringCompletionProcessor stringProcessor = new PythonStringCompletionProcessor(edit, pyContentAssistant);
// No code completion in comments and strings
for (String s : PythonPartitions.STRING_PROCESSOR_PARTITIONS) {
pyContentAssistant.setContentAssistProcessor(stringProcessor, s);
}
pyContentAssistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
pyContentAssistant.enableAutoActivation(true); //always true, but the chars depend on whether it is activated or not in the preferences
//note: delay and auto activate are set on PyContentAssistant constructor.
pyContentAssistant.setDocumentPartitioning(IPythonPartitions.PYTHON_PARTITION_TYPE);
pyContentAssistant.setAutoActivationDelay(PyCodeCompletionPreferences.getAutocompleteDelay());
return pyContentAssistant;
}
/**
* Registers a given code assist processor for a particular content type. If there is already a processor registered
* for this type, the new processor is registered instead of the old one.
*
* @param processor
* the code assist processor to register, or <code>null</code> to remove an existing one
* @param contentType
* the content type under which to register
*/
public void setContentAssistProcessor(IContentAssistProcessor processor, String contentType)
{
if (fProcessors == null)
{
fProcessors = new HashMap<String, IContentAssistProcessor>();
}
if (processor == null)
{
fProcessors.remove(contentType);
}
else
{
fProcessors.put(contentType, processor);
}
}
/**
* Returns an array of context information objects computed based on the specified document position. The position
* is used to determine the appropriate code assist processor to invoke.
*
* @param contentAssistSubjectControl
* the code assist subject control
* @param offset
* a document offset
* @return an array of context information objects
* @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
* @since 3.0
*/
IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubjectControl, int offset)
{
fLastErrorMessage = null;
IContextInformation[] result = null;
IContentAssistProcessor p = getProcessor(contentAssistSubjectControl, offset);
if (p instanceof ISubjectControlContentAssistProcessor)
{
result = ((ISubjectControlContentAssistProcessor) p).computeContextInformation(contentAssistSubjectControl,
offset);
fLastErrorMessage = p.getErrorMessage();
}
return result;
}
public IContentAssistProcessor getContentAssistProcessor(AbstractThemeableEditor editor, String contentType)
{
if (contentType.startsWith(JSSourceConfiguration.PREFIX))
{
return JSSourceConfiguration.getDefault().getContentAssistProcessor(editor, contentType);
}
if (contentType.startsWith(CSSSourceConfiguration.PREFIX))
{
return CSSSourceConfiguration.getDefault().getContentAssistProcessor(editor, contentType);
}
if (contentType.startsWith(SVGSourceConfiguration.PREFIX))
{
return SVGSourceConfiguration.getDefault().getContentAssistProcessor(editor, contentType);
}
return new HTMLContentAssistProcessor(editor);
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
protected LangContentAssistProcessor getLangContentAssistProcessor(ContentAssistant assistant) {
IContentAssistProcessor cap = assistant.getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE);
if(cap instanceof LangContentAssistProcessor)
return (LangContentAssistProcessor) cap;
return null;
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
/**
* @generated
*/
public IContentAssistProcessor getCompletionProcessor() {
if (getParserElement() == null || getParser() == null) {
return null;
}
return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
}
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];
}