简体   繁体   中英

Eclipse Plugin Developement find out which workingSet an ICompilationUnit belongs to

I have an ICompilationUnit and try to find out which workingSet it belongs to , or if it even has a workingSet. I have looked at the diffrent methods that ICompilationUnit has, howeber i did not find anything that helps. Does anyone have an idea?

A compilation unit may be a member of 0, 1, or many working sets. You will have to search through the list of working sets seeing which contain it.

Get the working sets with:

IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();

IWorkingSet [] sets = manager.getAllWorkingSets();

for each working set get the members with:

IAdaptable [] members = set.getElements();

Members can be many things, instanceof ICompilationUnit may work for some members or you may need to adapt:

ICompilationUnit unit = (ICompilationUnit)member.getAdapter(ICompilationUnit.class);

Note: the exact syntax of the getAdapter call varies depending on the Eclipse release as generics support was added in 4.5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM