SamYonnou
SamYonnou

Reputation: 2068

Refreshing classpath container name in Eclipse

Hi I'm working on a plugin for Eclipse which in part involves creating/upkeeping classpath containers for java projects. Under some conditions it is possible for a container name (getDescription()) to change. Now just selecting the container or the project and hitting F5 refreshes no problem and shows the new name, but I can't seem to do this programatically. I've tried:

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
...
for (IProject p: root.getProjects()) {
    ... some checks done here...
    p.refreshLocal(IResource.DEPTH_INFINITE, null);
}

but this doesn't seem to refresh the name. I've also tried some silly things like duplicating parts of what RefreshAction (what is used when pressing F5 I presume) does, but that did not work either. Any help would be appreciated.

Upvotes: 0

Views: 254

Answers (1)

Konstantin Komissarchik
Konstantin Komissarchik

Reputation: 29139

I found that JDT expects classpath containers to behave in immutable fashion. That is, none of the values returned by IClasspathContainer methods are expected to change from one invocation to another. Funny things can happen with JDT if they do. It's not a very good API.

So, treat it as an immutable object and when you need to change something (whether its the entries or description), supply a new IClasspathContainer instance via a JavaCore.setClasspathContainer() call. This will ensure that everything is updated correctly.

Upvotes: 2

Related Questions