问题描述:

I am using IElementChangedListener to listen to changes in the Java Model in eclipse plug-in I am making.

Is there any way I can get the path of the java file that had the change using this Listener or should I try a different Listener?

Any suggestions or links are appreciated.

Thanks

网友答案:

The IJavaElementDelta available in the ElementChangedEvent event has a getElement() method which returns an IJavaElement.

IJavaElement has a getPath() method which 'Returns the path to the innermost resource enclosing this element'.

You may have to look at the added / affected / changed children in the delta to get all changes.

网友答案:

Try the following:

elementChangedListener.elementChanged(ElementChangedEvent event) {
    IJavaElementDelta delta = ElementChangedEvent.getDelta();
    int kind = delta.getKind();
    int flags = delta.getFlags();
    // flags -> F_ARCHIVE_CONTENT_CHANGED, F_ADDED_TO_CLASSPATH, F_CLASSPATH_REORDER, F_REMOVED_FROM_CLASSPATH
    if ((delta.getFlags() & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) != 0) {
        // The contents of an archive has changed in some way
    }
}

See documentation of org.eclipse.jdt.core.IJavaElementDelta

相关阅读:
Top