I could get a set of ICompilationUnit using the following code, but I need get the physical file path from the ICompilationUnit or IWorkspaceRoot.
How can I do that?
private static Set<ICompilationUnit> getFiles(String projname)
throws CoreException {
IWorkspaceRoot ws = ResourcesPlugin.getWorkspace().getRoot();
IProject proj = ws.getProject(projname);
IJavaProject javaProject = JavaCore.create(proj);
Set<ICompilationUnit> files = new HashSet<ICompilationUnit>();
javaProject.open(new NullProgressMonitor());
for (IPackageFragment packFrag : javaProject.getPackageFragments()) {
for (ICompilationUnit icu : packFrag.getCompilationUnits()) {
files.add(icu);
}
}
javaProject.close();
return files;
}
Send the ICompilationUnit the getUnderlyingResource() method. It returns an IResource that can tell you if it’s a file and, if so, what the various forms of its file name and path are.
Note that a null can be returned, too, so watch for that.
something like this: