Track files changes done by eclipse cleanup programmatically

时光总嘲笑我的痴心妄想 提交于 2020-01-14 05:12:27

问题


I have written one eclipse osgi plugin that runs cleanup and formatting actions on java files present in eclipse project. Some thing like:

  • Run batch file that has eclipse command
  • It open's eclipse editor
  • Loads eclipse project passed as parameter in batch command
  • Run cleanup and formatting actions
  • Closes eclipse

Now my problem is I need to track the files that has been changed by this action. I am performing cleanup changes using cleanUpsAction that runs as thread over multiple files and forks further. It returns void.

There is IResourceChangeListener which I tried as well but I am not able to get name of resources that are changed. I get object of IResourceChangeEvent but details of resource are not coming out of it, it always return project name when I prints IResourceChangeEvent.getSource().


回答1:


There are multiple levels of object in the IResourceChangeEvent at the top is usually the project or the workspace and below that are folders and files. These are represented by IResourceDelta objects.

To see all of them first get the top level IResourceDelta from the event:

IResourceChangeEvent event = ... the event

IResourceDelta delta = event.getDelta();

and then use an IResourceDeltaVisitor to visit each resource in the delta:

delta.accept(visitor);

where visitor is a class implementing IResourceDeltaVisitor.

There is just one method in the visitor:

public boolean visit(IResourceDelta delta) throws CoreException

which is given a delta for each resource.

IResourceDelta.getResource gives you the changed resource. IResourceDelta.getKind tells you the type of change (add, delete, change).



来源:https://stackoverflow.com/questions/42562305/track-files-changes-done-by-eclipse-cleanup-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!