Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » API to find out about available JDT packages/classes in a project
API to find out about available JDT packages/classes in a project [message #249226] Sun, 04 November 2007 13:35 Go to next message
Eclipse UserFriend
Hi All,

I'd like to know if there's some public API to find out about the
available packages/classes within a given Java Project classpath entry.

I'm trying to integrate code-completion in Pydev using JDT... I've already
done it for external jars, but I do the jar traverse in pydev to know the
module names/classes and use the JDT code-completion engine for actually
getting the completions for a type which is already know at that point --
but for a given JDT project, calculating the packages/classes in my plugin
doesn't seem right.

It seems that the code below is able to do what I want, but it is
JDT-internal code... is there any other way to get it?

//create a unit with the parts of the classpaths we're interested in...
ICompilationUnit unit = new WorkingCopyOwner(){}.newWorkingCopy("Temp",
classpathsArray, new NullProgressMonitor());

//cast to a java project (that has the newNameLookup)
org.eclipse.jdt.internal.core.JavaProject j = (JavaProject) javaProject
org.eclipse.jdt.internal.core.NameLookup n = j.newNameLookup(new
ICompilationUnit[]{unit});

//use name lookup seek methods to get the classes/packages.

It also appears that using JavaProject.newSearchableNameEnvironment()
works, but it's also not public...

So, any 'public' ways to get that info?

Thanks,

Fabio
Re: API to find out about available JDT packages/classes in a project [message #249343 is a reply to message #249226] Wed, 07 November 2007 13:30 Go to previous messageGo to next message
Eclipse UserFriend
Anyone? (I'm still looking into this)...

Thanks,

Fabio

Fabio Zadrozny wrote:

> Hi All,

> I'd like to know if there's some public API to find out about the
> available packages/classes within a given Java Project classpath entry.

> I'm trying to integrate code-completion in Pydev using JDT... I've already
> done it for external jars, but I do the jar traverse in pydev to know the
> module names/classes and use the JDT code-completion engine for actually
> getting the completions for a type which is already know at that point --
> but for a given JDT project, calculating the packages/classes in my plugin
> doesn't seem right.

> It seems that the code below is able to do what I want, but it is
> JDT-internal code... is there any other way to get it?

> //create a unit with the parts of the classpaths we're interested in...
> ICompilationUnit unit = new WorkingCopyOwner(){}.newWorkingCopy("Temp",
> classpathsArray, new NullProgressMonitor());

> //cast to a java project (that has the newNameLookup)
> org.eclipse.jdt.internal.core.JavaProject j = (JavaProject) javaProject
> org.eclipse.jdt.internal.core.NameLookup n = j.newNameLookup(new
> ICompilationUnit[]{unit});

> //use name lookup seek methods to get the classes/packages.

> It also appears that using JavaProject.newSearchableNameEnvironment()
> works, but it's also not public...

> So, any 'public' ways to get that info?

> Thanks,

> Fabio
Re: API to find out about available JDT packages/classes in a project [message #249344 is a reply to message #249343] Wed, 07 November 2007 13:43 Go to previous messageGo to next message
Eclipse UserFriend
Fabio Zadrozny a écrit :
> Anyone? (I'm still looking into this)...
Do you want the package as IPackageFragment ?
If yes, you can org.eclipse.jdt.core.IJavaProject#getPackageFragments().
Once you have the IPackageFragments elements, you can iterate over them
to collect the compilation units using:
org.eclipse.jdt.core.IPackageFragment#getCompilationUnits().

Does this answer the question?
--
Olivier
Re: API to find out about available JDT packages/classes in a project [message #249470 is a reply to message #249344] Sat, 10 November 2007 06:54 Go to previous message
Eclipse UserFriend
Hi Olivier,

Actually, I've tried that approach, but I wanted to be able to get only a
part of the package fragments for the given project
(org.eclipse.jdt.core.IJavaProject#getPackageFragments() will return all
the package fragments from the project + system + deps), which is not
really what I want... I want to be able to get the packages from a given
IClassPathEntry (usually starting with a given string). So far I've only
been able to do that efficiently using the internal API...

I've just found out about findPackageFragmentRoots(entry) and it may be
able to do what I want -- not sure if it'll be as efficient as the
internal API, as I'll have to get each package name to do the filtering,
but it may be able to do it -- will check a bit further on this approach...

Thanks for your support,

Fabio

Olivier Thomann wrote:

> Fabio Zadrozny a écrit :
>> Anyone? (I'm still looking into this)...
> Do you want the package as IPackageFragment ?
> If yes, you can org.eclipse.jdt.core.IJavaProject#getPackageFragments().
> Once you have the IPackageFragments elements, you can iterate over them
> to collect the compilation units using:
> org.eclipse.jdt.core.IPackageFragment#getCompilationUnits().

> Does this answer the question?
> --
> Olivier
Previous Topic:Does/Will Eclipse use the Manifest Information in the JARs in the Build Path?
Next Topic:Open Source Software Research
Goto Forum:
  


Current Time: Fri Apr 25 22:29:19 EDT 2025

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

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

Back to the top