【JfaceTextFramework学习笔记之一】语法高亮

1-model of damage, repair, and reconciling

2-IPresentationReconciler: 当文本被修改的时候,来决定which region of the visual presentation should be invalidated and how to repair it

3-不同的策略可以应用到不同的Document的分区的内容类型中

4-默认地, SourceViwerConfiguration 并没有配置一个 IPresentationReconciler,因为并不知道要编辑的文件类型

5-为了提供语法高亮,我们可以继承SourceViwerConfiguration,然后重写下面的方法:
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
    PresentationReconciler reconciler= new PresentationReconciler();
    ... return reconciler;
}

6- IPresentationReconciler工作原理: damage, repair, and reconciling.

Damage: 当将java的关键字改变后,要更改其关键字的颜色为常规颜色,计算当修改文本时,要重新显示的内容叫做damage,因为改变一个字符就有可能破坏该段显示的颜色
  IPresentationDamager用来决定需要重建的内容,一种对象和一种特定的文本内容对应,它必须为presentation repairer 提供一个要被修复的区域

Reconciling:描述了整个过程, IPresentationReconciler通过和它绑定的Viewer来监视文本的改变,他使用region来决定被修改的content types,然后再通知一个content type对应的damager,当选择的damager计算后,被传递到对应的repairer,来重建显示。然后再将改变的内容与实际的文件进行同步

7- org.eclipse.jface.text.reconciler 包中提供了额外的支持类来讲文档模型和外部操作进行同步

8- IPresentationReconciler 需要为文档中每一个content type 被提供一个对应的repairer 和 damager 对。 
由Editor来决定 IPresentationReconciler 的合适的实现,
================================================================================
但是平台在 org.eclipse.jface.text.rules 包中提供了支持,使用基于rule的文档扫描来计算和修复damage.在该包中定义了一些默认的damagers和repairers,他们可以和 org.eclipse.jface.text.presentation 包中的标准reconcilers一起合作来实现基于扫描
rule的语法高亮
================================================================================

9-Java例子中, Syntax coloring href="../book.css" type="text/css" charset="ISO-8859-1" rel="STYLESHEET"> href="../book.css" type="text/css" rel="stylesheet"> href="../content/PLUGINS_ROOT/org.eclipse.help.webapp/advanced/breadcrumbs.css" type="text/css" charset="ISO-8859-1" rel="stylesheet"><script language="JavaScript" src="../content/PLUGINS_ROOT/org.eclipse.help/livehelp.js"></script><script>if( self == top ){ window.location.replace( "../../../index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_highlighting.htm");}</script><script language="JavaScript"> </script> JavaPartitionScanner将文档分割为javadoc, multi line comments, and everything else.

每一类被分割出来的类型都需要指定对应的damager/repairer对。

10- 通过使用 org.eclipse.jface.text.presentation包的
PresentationReconciler DefaultDamagerRepairer

JavaColorProvider provider= JavaEditorEnvironment.getJavaColorProvider();
PresentationReconciler reconciler= new PresentationReconciler();

DefaultDamagerRepairer dr= new DefaultDamagerRepairer(JavaEditorEnvironment.getJavaCodeScanner()); reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);

dr= new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(JavaColorProvider.JAVADOC_DEFAULT))));

reconciler.setDamager(dr, JavaPartitionScanner.JAVA_DOC); reconciler.setRepairer(dr, JavaPartitionScanner.JAVA_DOC);

dr= new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(JavaColorProvider.MULTI_LINE_COMMENT))));

reconciler.setDamager(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT); reconciler.setRepairer(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT);

return reconciler;

为每一种文档类型都提供了Scanner

Syntax coloring href="../book.css" type="text/css" charset="ISO-8859-1" rel="STYLESHEET"> href="../book.css" type="text/css" rel="stylesheet"> href="../content/PLUGINS_ROOT/org.eclipse.help.webapp/advanced/breadcrumbs.css" type="text/css" charset="ISO-8859-1" rel="stylesheet"><script language="JavaScript" src="../content/PLUGINS_ROOT/org.eclipse.help/livehelp.js"></script><script>if( self == top ){ window.location.replace( "../../../index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_highlighting.htm");}</script><script language="JavaScript"> </script>

The default content type is set up with a JavaCodeScanner so that keywords can be detected and colored. 


The JavaCodeScanner builds rules for detecting different kinds of tokens, such as single line comments, white space, and words.


It describes the colors that should be used for words of different token types.   


The other content types are set up with a SingleTokenScanner and given a color to be used for tokens in these content types.


All of the details for damaging and repairing the proper parts of the documents according to the scanning rules are handled by DefaultDamagerRepairer


These details typically don't need to be understood by plug-in code. 


插件应该注意到建立一系列的规则来讲文档扫描分区为不同的内容部分


11- 动态加载一个reconciler


Syntax coloring href="../book.css" type="text/css" charset="ISO-8859-1" rel="STYLESHEET"> href="../book.css" type="text/css" rel="stylesheet"> href="../content/PLUGINS_ROOT/org.eclipse.help.webapp/advanced/breadcrumbs.css" type="text/css" charset="ISO-8859-1" rel="stylesheet"><script language="JavaScript" src="../content/PLUGINS_ROOT/org.eclipse.help/livehelp.js"></script><script>if( self == top ){ window.location.replace( "../../../index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_highlighting.htm");}</script><script language="JavaScript"> </script>

java例子提供了一个SourceViewerConfiguration 的子类来安装reconciler。

 

A presentation reconciler也可以被动态地安装到text viewer使用IPresentationReconciler 协议. 


There is no particular runtime benefit to doing it either way, but putting all of the pluggable behavior overrides in a subclass of SourceViewerConfiguration provides the advantage of consolidating all of the behavioral overrides in one place. 


The dynamic protocol 当不同的presentation reconcilers 被附加到中viewer throughout 的时候是有用的







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值