score:0

Accepted answer

thanks to greg, i was able to get a solution.

my initial class now looks like this:

public class resourcechangelistener implements iresourcechangelistener {

    private logger logger = logger.getanonymouslogger();

    public void resourcechanged(iresourcechangeevent event) {
        iresourcedelta[] allchanges = event.getdelta().getaffectedchildren();

        for(iresourcedelta delta : allchanges) {
            if(delta.getkind() == 4) {  // only check projects when there are actual changes (4 = changed)
                try {
                    // visits resource deltas
                    resourcedeltavisitor resourcedeltavisitor = new resourcedeltavisitor();
                    delta.accept(resourcedeltavisitor);
                    arraylist<iresource> changedclasses = resourcedeltavisitor.getchangedresources();

                    for(iresource changedclass : changedclasses) {
                        icompilationunit icompilationunit = (icompilationunit)javacore.create(changedclass);
                        // do something with icompilationunits...
                    }
                }
                catch (coreexception e1) {
                    // catch exception here
                }
            }
        }
    }

}

my resourcedeltavisitor class looks like this:

public class resourcedeltavisitor implements iresourcedeltavisitor {

    private arraylist<iresource> changedclasses = new arraylist<iresource>();

    public boolean visit(iresourcedelta delta) {
        iresource res = delta.getresource();
        if(res.getname().endswith(".java")) {
            addresource(res);
        }
        return true; // visit the children
    }

    public arraylist<iresource> getchangedresources() {
        return changedclasses;
    }

    private void addresource(iresource res) {
        changedclasses.add(res);
    }
}

this is not the best solution, but it works for me.


Related Query

More Query from same tag