Eclipse rcp EclipseRCP-内容辅助故障
我正在尝试向我的编辑器添加内容辅助。我补充说Eclipse rcp EclipseRCP-内容辅助故障,eclipse-rcp,Eclipse Rcp,我正在尝试向我的编辑器添加内容辅助。我补充说 public IContentAssistant getContentAssistant(ISourceViewer sv) { ContentAssistant ca = new ContentAssistant(); IContentAssistProcessor pr = new TagCompletionProcessor(); ca.setContentAssistProcessor(pr, XMLParti
public IContentAssistant getContentAssistant(ISourceViewer sv) {
ContentAssistant ca = new ContentAssistant();
IContentAssistProcessor pr = new TagCompletionProcessor();
ca.setContentAssistProcessor(pr, XMLPartitionScanner.XML_TAG);
ca.setContentAssistProcessor(pr, IDocument.DEFAULT_CONTENT_TYPE);
return ca;
}
到编辑器配置,然后生成完成处理器类:
public class TagCompletionProcessor implements IContentAssistProcessor {
private ITypedRegion wordRegion;
private String currentWord;
private SmartTreeSet tags;
public TagCompletionProcessor() {
tags = new SmartTreeSet();
//filling tags skipped
}
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
int offset) {
System.out.println("compute");
wordRegion = viewer.getDocument().getDocumentPartitioner().getPartition(offset);
try {
int offs = wordRegion.getOffset();
int len = wordRegion.getLength();
currentWord = viewer.getDocument().get(offs, len);
return tags.getProposals(currentWord.toLowerCase(), offs, len);
} catch (BadLocationException e) {
return null;
}
}
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer,
int offset) {
return null;
}
@Override
public char[] getCompletionProposalAutoActivationCharacters() {
return new char[] {'<'};
}
@Override
public char[] getContextInformationAutoActivationCharacters() {
return null;
}
@Override
public IContextInformationValidator getContextInformationValidator() {
return null;
}
@Override
public String getErrorMessage() {
return "No tags found";
}
公共类TagCompletionProcessor实现IContentAsistProcessor{
私人IT区;
私有字符串;
私有SmartTreeSet标签;
公共标记完成处理器(){
标签=新的SmartTreeSet();
//已跳过填充标记
}
@凌驾
公共ICompletionProposal[]计算完成建议(ITextViewer、,
整数偏移){
System.out.println(“计算”);
wordRegion=viewer.getDocument().getDocumentPartitioner().getPartition(偏移量);
试一试{
int offs=wordRegion.getOffset();
int len=wordRegion.getLength();
currentWord=viewer.getDocument().get(offs,len);
return tags.getPropositions(currentWord.toLowerCase(),offs,len);
}捕获(错误位置异常e){
返回null;
}
}
@凌驾
公共IContextInformation[]计算上下文信息(ITextViewer、,
整数偏移){
返回null;
}
@凌驾
公共字符[]getCompletionProposalAutoActivationCharacters(){
如果您的文档实现IDocumentExtension3,则返回新字符[]{',然后您必须设置助手的分区
ca.setDocumentPartitioning(MyPartitionScanner.MyPartitioning);
希望此帮助您应该在编辑器中注册您的操作并替换默认操作。
下面是一个如何使用内容辅助操作的示例
< P>对不起,中间有一些空输出。