Eclipse再構成機能:拡張点の使用
転載先:http://developer.51cto.com/art/200908/143871.htm
Eclipseにはいくつかの拡張点が提供され、再構成機能を拡張しやすい。
基本的な再構成機能は、
Rename、Move、Create、Delete、Copy。対応する拡張点は、次の通りです。
ReNameを例にとって、残りの4つはReNameと大同小異です。
この拡張点を実現するための基本的な文法:
以下のコードは簡単なEclipse再構成機能を実現します。
CreateChangeメソッドでは、あまりにも粗い実現は、結果を見ることができるようにするためだけです。
Eclipse再構成機能結果プレビュー
拡張点を利用することで、再現時の違いを自然に比較し、警告、preview、再構築history、redo/undoなど、eclipseプラットフォームが提供する基本機能を利用しました。
Prevewの結果は下図の通りです。
Eclipse再構成機能:特殊需要
ここで紹介します。拡張点によって特別な需要が実現されます。
増加、削除、変更、シフトなどの基本的な再構成に加えて、JDTでのペア、方法、変数名の再構成など、特別な需要を増やすことができます。
特殊な需要を実現するには、自分のRefactoring類を実現し、クラスorg.eclipse.ltk.com re.refactoring.Refactoringに関連する方法を実現します。このような構造はRenamePartcipartなどの構造とほぼ一致しています。
このクラスは特殊な需要と再構成の特殊な論理を処理する責任があります。
論理層の他に、表現層の実現が必要である。
Refactoring Wizard及びRefactorngWizardPage。
Refactoring,Wizard,WizardPageを実現すると,UIが論理的に実現される。
対応するアクションの構成により、RefactorngWizard OpenOperationを使用する。特殊な再構成ニーズの開発が完了しました。
特殊需要のRefactoring論理部分の再利用を容易にするために、eclipseは拡張点を提供する:
org.eclipse.ltk.com re.refactoring.refactorigonConttributions
拡張点の配置により、使用時にIDでいつでもRefactoringオブジェクトが得られます。
この記事はeclipseの肩に立ちます。
Eclipseにはいくつかの拡張点が提供され、再構成機能を拡張しやすい。
基本的な再構成機能は、
Rename、Move、Create、Delete、Copy。対応する拡張点は、次の通りです。
- org.eclipse.ltk.core.refactoring.renameParticipants
- org.eclipse.ltk.core.refactoring.moveParticipants
- org.eclipse.ltk.core.refactoring.createParticipants
- org.eclipse.ltk.core.refactoring.deleteParticipants
- org.eclipse.ltk.core.refactoring.copyParticipants
ReNameを例にとって、残りの4つはReNameと大同小異です。
この拡張点を実現するための基本的な文法:
- < extension point="org.eclipse.ltk.core.refactoring.renameParticipants">
- < renameParticipant
- id="jp.co.intramart.app.producer.refactoring.renameTypeParticipant"
- name="Ebuilder RenameTypeParticipant"
- class="jp.co.intramart.app.producer.refactoring.TypeRenameParticipant">
- < enablement>
- < /enablement>
- < /renameParticipant>
- < /extension>
ここではデフォルトですべての改名イベントに対応しています。フィルタリングが必要なら、要素の中で定義できます。贅を要しない。改名拡張を実現するための鍵となる実現カテゴリは、org.eclipspe.ltk.com re.refactoring.participnts.Rename Particparticpartでなければなりません。のサブクラス以下のコードは簡単なEclipse再構成機能を実現します。
- import org.eclipse.core.resources.IFile;
- import org.eclipse.core.resources.ResourcesPlugin;
- import org.eclipse.core.runtime.CoreException;
- import org.eclipse.core.runtime.IProgressMonitor;
- import org.eclipse.core.runtime.OperationCanceledException;
- import org.eclipse.ltk.core.refactoring.Change;
- import org.eclipse.ltk.core.refactoring.RefactoringStatus;
- import org.eclipse.ltk.core.refactoring.TextFileChange;
- import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
- import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
- import org.eclipse.text.edits.ReplaceEdit;
-
- public class TypeRenameParticipant extends RenameParticipant {
-
- public TypeRenameParticipant() {
- }
-
- @Override
- public RefactoringStatus checkConditions(IProgressMonitor pm,
- CheckConditionsContext context) throws OperationCanceledException {
- return new RefactoringStatus();
- }
-
- @Override
- public Change createChange(IProgressMonitor pm) throws CoreException,
- OperationCanceledException {
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getProject("a")
- .getFile("a");
- TextFileChange textFileChange = new TextFileChange("File Changed ",
- file);
-
- ReplaceEdit edit = new ReplaceEdit(0, 1, "haha");
- textFileChange.setEdit(edit);
- return textFileChange;
- }
-
- @Override
- public String getName() {
- return "Ebuilder RenameTypeParticipant";
- }
-
- @Override
- protected boolean initialize(Object element) {
- // need sub
- return true;
- }
-
- }
CreateChangeメソッドでは、あまりにも粗い実現は、結果を見ることができるようにするためだけです。
Eclipse再構成機能結果プレビュー
拡張点を利用することで、再現時の違いを自然に比較し、警告、preview、再構築history、redo/undoなど、eclipseプラットフォームが提供する基本機能を利用しました。
Prevewの結果は下図の通りです。
Eclipse再構成機能:特殊需要
ここで紹介します。拡張点によって特別な需要が実現されます。
増加、削除、変更、シフトなどの基本的な再構成に加えて、JDTでのペア、方法、変数名の再構成など、特別な需要を増やすことができます。
特殊な需要を実現するには、自分のRefactoring類を実現し、クラスorg.eclipse.ltk.com re.refactoring.Refactoringに関連する方法を実現します。このような構造はRenamePartcipartなどの構造とほぼ一致しています。
- import org.eclipse.core.runtime.CoreException;
- import org.eclipse.core.runtime.IProgressMonitor;
- import org.eclipse.core.runtime.OperationCanceledException;
- import org.eclipse.ltk.core.refactoring.Change;
- import org.eclipse.ltk.core.refactoring.Refactoring;
- import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-
- public class ProducerRefactoring extends Refactoring {
-
- @Override
- public RefactoringStatus checkFinalConditions(IProgressMonitor pm)
- throws CoreException, OperationCanceledException {
- // need sub
- return new RefactoringStatus();
- }
-
- @Override
- public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
- throws CoreException, OperationCanceledException {
- // need sub
- return new RefactoringStatus();
- }
-
- @Override
- public Change createChange(IProgressMonitor pm) throws CoreException,
- OperationCanceledException {
- // need sub
- return null;
- }
-
- @Override
- public String getName() {
- return "ProducerRefactoring";
- }
-
- }
このクラスは特殊な需要と再構成の特殊な論理を処理する責任があります。
論理層の他に、表現層の実現が必要である。
Refactoring Wizard及びRefactorngWizardPage。
Refactoring,Wizard,WizardPageを実現すると,UIが論理的に実現される。
対応するアクションの構成により、RefactorngWizard OpenOperationを使用する。特殊な再構成ニーズの開発が完了しました。
特殊需要のRefactoring論理部分の再利用を容易にするために、eclipseは拡張点を提供する:
org.eclipse.ltk.com re.refactoring.refactorigonConttributions
拡張点の配置により、使用時にIDでいつでもRefactoringオブジェクトが得られます。
この記事はeclipseの肩に立ちます。