Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Getting IResource from sourcepath entries
Getting IResource from sourcepath entries [message #182049] Tue, 12 October 2004 05:53 Go to next message
Eclipse UserFriend
Hi,

I need to get corresponding IFolder for each project sourcepath entries.

// variable declarations
IProject project;
IJavaProject javaProject;


IClasspathEntry [] entries=javaProject.getResolvedClasspath(true);

for (int i = 0; i < entries.length; i++) {
IClasspathEntry entry=entries[i];
if ( entry.getEntryKind() == IClasspathEntry.CPE_SOURCE ) {
IPath path=entry.getPath();
IFolder folder=project.getWorkspace().getRoot().getFolder(path);
}
}


Problem is that it doesn't work if
1) Path is absolute, containing device letters( e.g. c:/projects/test )
2) If path points to project root dir
3) If project sourcepath isn't under eclipse's workspace dir

I tried also with javaProject.getPackageFragmentRoots()
but still same problems ...

So how to get *IFolder* from *absolute* IPath?

thanks
Re: Getting IResource from sourcepath entries [message #182079 is a reply to message #182049] Tue, 12 October 2004 06:46 Go to previous message
Eclipse UserFriend
1) The path of a source classpath entry must be an absolute
workspace-relative path (see JavaCore#newSourceEntry). "c:/projects/test"
indicates an absolute file system relative path.
2) If the path points to the project, then no corresponding IFolder exists.
You should use getProject(String) in this case:
IContainer container = path.segmentCount() == 1 ?
root.getProject(path.segment(0)) : root.getFolder(path);
3) I'm not sure to understand what you mean here. Even if the location of
the project isn't in the workspace directory, you can still get an IResource
for it.

If you want to use IPackageFragmentRoots, see IJavaElement#getResource().

Jerome

"Tonis" <tvwww@hot.ee> wrote in message news:ckg986$elu$1@eclipse.org...
>
> Hi,
>
> I need to get corresponding IFolder for each project sourcepath entries.
>
> // variable declarations
> IProject project;
> IJavaProject javaProject;
>
>
> IClasspathEntry [] entries=javaProject.getResolvedClasspath(true);
>
> for (int i = 0; i < entries.length; i++) {
> IClasspathEntry entry=entries[i];
> if ( entry.getEntryKind() == IClasspathEntry.CPE_SOURCE ) {
> IPath path=entry.getPath();
> IFolder folder=project.getWorkspace().getRoot().getFolder(path);
> }
> }
>
>
> Problem is that it doesn't work if
> 1) Path is absolute, containing device letters( e.g. c:/projects/test )
> 2) If path points to project root dir
> 3) If project sourcepath isn't under eclipse's workspace dir
>
> I tried also with javaProject.getPackageFragmentRoots()
> but still same problems ...
>
> So how to get *IFolder* from *absolute* IPath?
>
> thanks
Previous Topic:eclipse editor shows only a part of the code
Next Topic:launching a clas
Goto Forum:
  


Current Time: Wed Sep 17 11:59:04 EDT 2025

Powered by FUDForum. Page generated in 0.03116 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top