自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Eclipse重構(gòu)功能:擴(kuò)展點(diǎn)的使用

開(kāi)發(fā) 后端
本文介紹了Eclipse重構(gòu)功能的實(shí)現(xiàn)。Eclipse中提供了幾個(gè)擴(kuò)展點(diǎn),方便擴(kuò)展重構(gòu)功能。 基本的重構(gòu)功能有Rename,Move,Create,Delete,Copy。

Eclipse中提供了幾個(gè)擴(kuò)展點(diǎn),方便擴(kuò)展重構(gòu)功能。

基本的重構(gòu)功能有,

Rename,Move,Create,Delete,Copy。對(duì)應(yīng)擴(kuò)展點(diǎn)即為:

  1. org.eclipse.ltk.core.refactoring.renameParticipants    
  2. org.eclipse.ltk.core.refactoring.moveParticipants    
  3. org.eclipse.ltk.core.refactoring.createParticipants    
  4. org.eclipse.ltk.core.refactoring.deleteParticipants    
  5. org.eclipse.ltk.core.refactoring.copyParticipants   

以ReName為例,其余4項(xiàng)與ReName大同小異。

實(shí)現(xiàn)這個(gè)擴(kuò)展點(diǎn)的基本語(yǔ)法:

  1. < extension point="org.eclipse.ltk.core.refactoring.renameParticipants">    
  2. < renameParticipant    
  3.     id="jp.co.intramart.app.producer.refactoring.renameTypeParticipant"    
  4.     name="Ebuilder RenameTypeParticipant"     
  5.     class="jp.co.intramart.app.producer.refactoring.TypeRenameParticipant">     
  6.     < enablement>    
  7.     < /enablement>        
  8. < /renameParticipant>    
  9. < /extension>   

這里默認(rèn)對(duì)響應(yīng)所有改名事件,如果需要過(guò)濾可以在元素< enablement/>中加以定義。不贅述。實(shí)現(xiàn)改名擴(kuò)展的關(guān)鍵在實(shí)現(xiàn)類,必須是org.eclipse.ltk.core.refactoring.participants.RenameParticipant;的子類

下面代碼進(jìn)行了簡(jiǎn)單的Eclipse重構(gòu)功能實(shí)現(xiàn)。

  1. import org.eclipse.core.resources.IFile;    
  2. import org.eclipse.core.resources.ResourcesPlugin;    
  3. import org.eclipse.core.runtime.CoreException;    
  4. import org.eclipse.core.runtime.IProgressMonitor;    
  5. import org.eclipse.core.runtime.OperationCanceledException;    
  6. import org.eclipse.ltk.core.refactoring.Change;    
  7. import org.eclipse.ltk.core.refactoring.RefactoringStatus;    
  8. import org.eclipse.ltk.core.refactoring.TextFileChange;    
  9. import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;    
  10. import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;    
  11. import org.eclipse.text.edits.ReplaceEdit;    
  12.     
  13. public class TypeRenameParticipant extends RenameParticipant {    
  14.     
  15.     public TypeRenameParticipant() {    
  16.     }    
  17.     
  18.     @Override    
  19.     public RefactoringStatus checkConditions(IProgressMonitor pm,    
  20.             CheckConditionsContext context) throws OperationCanceledException {    
  21.         return new RefactoringStatus();    
  22.     }    
  23.     
  24.     @Override    
  25.     public Change createChange(IProgressMonitor pm) throws CoreException,    
  26.             OperationCanceledException {    
  27.         IFile file = ResourcesPlugin.getWorkspace().getRoot().getProject("a")    
  28.                 .getFile("a");    
  29.         TextFileChange textFileChange = new TextFileChange("File Changed ",    
  30.                 file);    
  31.     
  32.         ReplaceEdit edit = new ReplaceEdit(01"haha");    
  33.         textFileChange.setEdit(edit);    
  34.         return textFileChange;    
  35.     }    
  36.     
  37.     @Override    
  38.     public String getName() {    
  39.         return "Ebuilder RenameTypeParticipant";    
  40.     }    
  41.     
  42.     @Override    
  43.     protected boolean initialize(Object element) {    
  44.         // need sub    
  45.         return true;    
  46.     }    
  47.     
  48. }   

CreateChange方法內(nèi)實(shí)現(xiàn)過(guò)于粗糙,僅僅是為了可以讓大家看到結(jié)果。

Eclipse重構(gòu)功能結(jié)果預(yù)覽

通過(guò)利用擴(kuò)展點(diǎn),我們就自然的將重構(gòu)時(shí)的差異比較,警告,preview,重構(gòu)history,redo/undo等,eclipse平臺(tái)提供的基本功能加以利用了。

Preview的結(jié)果如下圖。

Preview的結(jié)果 

Eclipse重構(gòu)功能:特殊需求

下面我來(lái)介紹,通過(guò)擴(kuò)展點(diǎn)實(shí)現(xiàn)特殊需求。

除了增,刪,改,移等基本重構(gòu)外,可以增加特殊需求的重構(gòu),比如JDT中對(duì)類,方法,變量名的重構(gòu)。

實(shí)現(xiàn)特殊需求,就要實(shí)現(xiàn)自己的Refactoring類,繼承類org.eclipse.ltk.core.refactoring.Refactoring實(shí)現(xiàn)相關(guān)方法,這個(gè)類的結(jié)構(gòu)與RenameParticipant等類的結(jié)構(gòu)基本一致,直接上代碼,不再贅述。

  1. import org.eclipse.core.runtime.CoreException;    
  2. import org.eclipse.core.runtime.IProgressMonitor;    
  3. import org.eclipse.core.runtime.OperationCanceledException;    
  4. import org.eclipse.ltk.core.refactoring.Change;    
  5. import org.eclipse.ltk.core.refactoring.Refactoring;    
  6. import org.eclipse.ltk.core.refactoring.RefactoringStatus;    
  7.     
  8. public class ProducerRefactoring extends Refactoring {    
  9.     
  10.     @Override    
  11.     public RefactoringStatus checkFinalConditions(IProgressMonitor pm)    
  12.             throws CoreException, OperationCanceledException {    
  13.         // need sub    
  14.         return new RefactoringStatus();    
  15.     }    
  16.     
  17.     @Override    
  18.     public RefactoringStatus checkInitialConditions(IProgressMonitor pm)    
  19.             throws CoreException, OperationCanceledException {    
  20.         // need sub    
  21.         return new RefactoringStatus();    
  22.     }    
  23.     
  24.     @Override    
  25.     public Change createChange(IProgressMonitor pm) throws CoreException,    
  26.             OperationCanceledException {    
  27.         // need sub    
  28.         return null;    
  29.     }    
  30.     
  31.     @Override    
  32.     public String getName() {    
  33.         return "ProducerRefactoring";    
  34.     }    
  35.     
  36. }   

這個(gè)類負(fù)責(zé)處理特殊需求與重構(gòu)的特殊邏輯。

除了邏輯層,還需要對(duì)表現(xiàn)層有實(shí)現(xiàn):

RefactoringWizard 及 RefactoringWizardPage。

實(shí)現(xiàn)了Refactoring,Wizard,WizardPage后,即完成了,UI到邏輯的實(shí)現(xiàn)。

通過(guò)相應(yīng)的Action的配置,使用RefactoringWizardOpenOperation。即完成了特殊重構(gòu)需求的開(kāi)發(fā)。

為了方便對(duì)特殊需求的Refactoring邏輯部分的重用,eclipse提供了一個(gè)擴(kuò)展點(diǎn):

org.eclipse.ltk.core.refactoring.refactoringContributions

通過(guò)擴(kuò)展點(diǎn)的配置,使用時(shí)通過(guò)ID即可隨時(shí)得到Refactoring對(duì)象。

本文來(lái)自站在eclipse的肩膀上:《簡(jiǎn)單介紹eclipse中的重構(gòu)》。

【編輯推薦】

  1. 在Eclipse中安裝pydev插件的經(jīng)驗(yàn)分享
  2. 自定義Eclipse菜單項(xiàng):去除多余的UI圖標(biāo)
  3. 六大便捷Eclipse JDT特性一覽
  4. 部署Eclipse RAP到Tomcat的步驟詳解
  5. Eclipse平臺(tái)應(yīng)用與開(kāi)發(fā)專題
責(zé)任編輯:yangsai 來(lái)源: defrag_sly的博客
相關(guān)推薦

2011-03-31 09:32:25

EclipseRefactor

2020-11-16 19:18:15

Jupyter微軟編程

2009-06-10 16:24:10

Eclipse平臺(tái)擴(kuò)展

2011-03-16 09:46:54

Eclipse代碼模板

2017-05-09 10:34:21

Spring BootDubbo Activ擴(kuò)展

2017-04-28 08:32:40

Spring BootDubbo Activ使用

2024-02-01 08:28:28

2013-03-06 10:19:56

重構(gòu)架構(gòu)設(shè)計(jì)

2009-10-28 09:19:13

Eclipse 3.5項(xiàng)目導(dǎo)航

2009-01-03 15:05:31

ibmdwEclipseSymphony

2023-11-28 08:01:25

2023-09-28 08:49:41

springBean

2023-12-01 07:28:40

SpringbootBean

2010-06-12 16:29:00

BlackBerry開(kāi)

2009-09-17 09:51:18

Eclipse JDT自定義跳轉(zhuǎn)

2009-08-25 14:25:19

Eclipse 3.5

2010-06-12 13:59:42

Eclipse 4.0CSS主題功能切換

2009-08-28 13:57:29

virtual ove擴(kuò)展點(diǎn)

2009-06-17 17:44:41

Eclipse插件Sp

2022-06-10 07:17:07

重構(gòu)Java應(yīng)用
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)