【发布时间】:2016-03-28 02:39:29
【问题描述】:
我正在开发一个带有自定义文本编辑器的 Eclipse 插件,我想为其提供语法高亮。因此,我实现了自己的 RuleBasedPartitionScanner 和各自的 SourceViewerConfiguration。
当我不弄乱 PartitionScanner 的 defaultReturnToken 但是当我尝试设置默认的 defaultReturnToken 时,一切工作正常,语法突出显示消失了。
我的分区扫描仪:
public class SQFPartitionScanner extends RuleBasedPartitionScanner {
public static final String SQF_COMMENT = "__sqf_Comment";
public static final String SQF_CODE = "__sqf_Code";
public SQFPartitionScanner() {
IToken comment = new Token(SQF_COMMENT);
IToken code = new Token(SQF_CODE);
IPredicateRule[] rules = {
//rule for multiLine comments
new MultiLineRule("/*", "*/", comment),
//rule for singleLine comments
new EndOfLineRule("//", comment)
};
this.setPredicateRules(rules);
this.setDefaultReturnToken(code);
}
}
由于生成的令牌不再是 IDocument.DEFAULT_CONTENT_TYPE 类型,而是 SQFPartitioScanner.CODE 类型,所以我更改了我的 SourceViewerConfiguration 如下(我只更改了 getPresentationReconciler() 方法):
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(this.getKeywordScanner());
// reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
// reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setDamager(dr, SQFPartitionScanner.SQF_CODE);
reconciler.setRepairer(dr, SQFPartitionScanner.SQF_CODE);
return reconciler;
}
还有什么我必须改变的语法突出显示使用 defaultReturnToken 设置为SQFPartitionScanner.SQF_CODE?
编辑:
当我取消注释这些行时
// reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
// reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
和评论
reconciler.setDamager(dr, SQFPartitionScanner.SQF_CODE);
reconciler.setRepairer(dr, SQFPartitionScanner.SQF_CODE);
我仍然没有语法高亮显示。
因此,我怀疑默认令牌没有正确创建,因为显然它不再是 IDocument.DEFAULT_CONTENT_TYPE 类型,但它也不是 SQFPartitionScanner.SQF_CODE 类型
【问题讨论】:
标签: java eclipse eclipse-plugin syntax-highlighting jface