shaILU
shaILU

Reputation: 2116

Track files changes done by eclipse cleanup programmatically

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

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().

Upvotes: 1

Views: 448

Answers (1)

greg-449
greg-449

Reputation: 111142

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).

Upvotes: 1

Related Questions