* Different type of resource is returned based on the length of the path
* and whether or not it ends with a path separator.
*/
public static IResource getResource(IPath path) {
try {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
if (path.segmentCount() == 0) {
return root;
}
IProject project = root.getProject(path.segment(0));
if (path.segmentCount() == 1) {
return project;
}
if (path.hasTrailingSeparator()) {
return root.getFolder(path);
}
else {
return root.getFile(path);
}
}
catch (Exception e) {
e.printStackTrace();
return null;