有人扩展过eclipse的重构功能么?谢谢

fly1028 2010-12-04 01:22:14
有人扩展过eclipse的重构功能么?因为比较急,能否给点思路?谢谢
...全文
89 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
salever 2010-12-06
  • 打赏
  • 举报
回复
类似于Jdt的重构么?
fly1028 2010-12-05
  • 打赏
  • 举报
回复
主要是自己不懂插件开发,而这个东西又很急,谁能帮帮我阿?
核桃科技 2010-12-05
  • 打赏
  • 举报
回复
外包吧 代码给你都搞不定 还能咋滴
fly1028 2010-12-04
  • 打赏
  • 举报
回复
能介绍更详细一点么? 我要先建个fragment 工程还是plugin工程阿? 谢谢
核桃科技 2010-12-04
  • 打赏
  • 举报
回复
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>
  这里默认对响应所有改名事件,如果需要过滤可以在元素< enablement/>中加以定义。不赘述。实现改名扩展的关键在实现类,必须是 org.eclipse.ltk.core.refactoring.participants.RenameParticipant;的子类
  下面代码进行了简单的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平台提供的基本功能加以利用了。
  Preview的结果如下。
  下面我来介绍,通过扩展点实现特殊需求。
  除了增,删,改,移等基本重构外,可以增加特殊需求的重构,比如JDT中对类,方法,变量名的重构。
  实现特殊需求,就要实现自己的Refactoring类,继承类 org.eclipse.ltk.core.refactoring.Refactoring实现相关方法,这个类的结构与 RenameParticipant等类的结构基本一致,直接上代码,不再赘述。
  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";
  }
  }
  这个类负责处理特殊需求与重构的特殊逻辑。
  除了逻辑层,还需要对表现层有实现:
  RefactoringWizard 及 RefactoringWizardPage.
  实现了Refactoring,Wizard,WizardPage后,即完成了,UI到逻辑的实现。
  通过相应的Action的配置,使用RefactoringWizardOpenOperation.即完成了特殊重构需求的开发。
  为了方便对特殊需求的Refactoring逻辑部分的重用,eclipse提供了一个扩展点:
  org.eclipse.ltk.core.refactoring.refactoringContributions
  通过扩展点的配置,使用时通过ID即可随时得到Refactoring对象。
Jlins 2010-12-04
  • 打赏
  • 举报
回复
。[Quote=引用 3 楼 heming1990 的回复:]

你去看看fragment 工程 plugin工程是啥不就清楚了?
[/Quote]
核桃科技 2010-12-04
  • 打赏
  • 举报
回复
你去看看fragment 工程 plugin工程是啥不就清楚了?

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧