【Eclipse外掛程式開發】基於WTP開發自訂的JSP編輯器(九)

來源:互聯網
上載者:User

定製StructuredTextEditor源碼即時校正

上一節我們定製了WTP StructuredTextEditor的自動提示功能特徵,本節將定製另外一個功能特徵即 時源碼校正。所謂源碼即時校正,就是在使用者編輯過程中(並未儲存),針對使用者編輯的內容改變做即時 校正,並給使用者即時反饋相關的錯誤或者其他類型的提示資訊。在本節中,我們將以標籤的即時校正為例 ,示範如何定製WTP StructuredTextEditor的源碼即時校正。

在定製之前,我們先來看一下WTP StructuredTextEditor已有的源碼即時校正功能:

我們看到,我們刪除</jsp:text>的瞬間,WTP StructuredTextEditor的即時校正就給出了錯誤 提示。其實我們在很多其他的編輯器,例如java源碼編輯器等,都可以看到類似的即時校正功能。

【JFace Text Framework中相關內容】

說白了,我們的源碼編輯對應的控制項就是ISourceViewer, 那麼這個校正也理所當然應該是ISourceViewer所提供的一個服務。JFace Text Framework中確實針對源 碼即時校正提供了相應的機制,我們看一下相應的介面和運行原理。

【相關介面】

1、IReconciler (org.eclipse.jface.text.reconciler.IReconciler),調解者,當文檔發生變化時,根據分區類型( 如果這個概念忘記了,翻一下前面的文章)提供相應的調解策略(直接說成是驗證策略吧^_^)。 public interface IReconciler {
/**
* Installs the reconciler on the given text viewer. After this method has been
* finished, the reconciler is operational, i.e., it works without requesting
* further client actions until <code>uninstall</code> is called.
*
* @param textViewer the viewer on which the reconciler is installed
*/
void install(ITextViewer textViewer);
/**
* Removes the reconciler from the text viewer it has
* previously been installed on.
*/
void uninstall();
/**
* Returns the reconciling strategy registered with the reconciler
* for the specified content type.
*
* @param contentType the content type for which to determine the reconciling strategy
* @return the reconciling strategy registered for the given content type, or
* <code>null</code> if there is no such strategy
*/
IReconcilingStrategy getReconcilingStrategy(String contentType);
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.