I am developing a plugin that requires retrieval of path/filename of java files.
The code that I have written, successfully retrieves the filenames/path of the xml or manifest files, but is unable to retrieve the path of the Java files in the packages.
The code I have used is :-
if (selection instanceof IStructuredSelection)
{
Object o = ((IStructuredSelection) selection).getFirstElement();
if (o instanceof IFile)
{
IPath loc = ((IFile) o).getLocation();
if (loc != null)
{
selectedFile = loc.toOSString();
}
else
selectedFile = "Error at loc";
}
else
selectedFile = "Error at O";
}
THANKS GUYZ, I WAS ABLE TO FIGURE IT OUT WITH YOUR HELP
THE SOLUTION IS –
Object o = ((IStructuredSelection) selection).getFirstElement();
den
IPath loc = ((ICompilationUnit) o).getPath();
den
selectedFile = loc.toOSString();
With this, you will be able to get the path of the java file that u selected. and also, this shows the pathname starting from the project name, can someone tell how to get the entire physical pathname, with the drives and such as well..??