Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Finding all classes in the current project's classpath
Finding all classes in the current project's classpath [message #286537] Mon, 13 June 2005 07:19 Go to next message
exquisitus is currently offline exquisitusFriend
Messages: 13
Registered: July 2009
Junior Member
Hi,

I am developing a simple wizard that will let the users select methods of
one or more classes in the classpath of the current project. After looking
around in Eclipse 3.0 I found the jdt internal "AllTypesCache" class that
provided similar capabilities, but I noticed that in Eclipse 3.1 that's
not present. I would just like to know what's a good way to find the
classes in the current project. A working code snippet would be greatly
appreciated.

Thanks,
- Nitin
Re: Finding all classes in the current project's classpath [message #286544 is a reply to message #286537] Mon, 13 June 2005 08:30 Go to previous messageGo to next message
Przemyslaw Doe is currently offline Przemyslaw DoeFriend
Messages: 49
Registered: July 2009
Member
"Nitin" <nitin@technobuff.net> schrieb im Newsbeitrag
news:025adcff9b8d1b357ff39c1ce11b5a62$1@www.eclipse.org...
> Hi,
>
> I am developing a simple wizard that will let the users select methods of
> one or more classes in the classpath of the current project. After looking
> around in Eclipse 3.0 I found the jdt internal "AllTypesCache" class that
> provided similar capabilities, but I noticed that in Eclipse 3.1 that's
> not present. I would just like to know what's a good way to find the
> classes in the current project. A working code snippet would be greatly
> appreciated.
>
> Thanks,
> - Nitin
>

Hello,
I use:

public final IType[] getTypes(IJavaProject javaproject) {
ArrayList typeList = new ArrayList();
try {
IPackageFragmentRoot[] roots = javaproject
.getPackageFragmentRoots();
for (int i = 0; i < roots.length; i++) {
IPackageFragmentRoot root = roots[i];
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
IJavaElement[] javaElements = root.getChildren();
for (int j = 0; j < javaElements.length; j++) {
IJavaElement javaElement = javaElements[j];
if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
IPackageFragment pf = (IPackageFragment) javaElement;
ICompilationUnit[] compilationUnits = pf
.getCompilationUnits();
for (int k = 0; k < compilationUnits.length; k++) {
ICompilationUnit unit = compilationUnits[k];
if (unit.isStructureKnown()) {
typeList.addAll(Arrays.asList(unit.getTypes()));
}
}
}
}
}
}
}catch(CoreException e) {
e.printStackTrace();
}
IType[] types = new IType[typeList.size()];
return (IType[])typeList.toArray(types);
}
Re: Finding all classes in the current project's classpath [message #286649 is a reply to message #286544] Tue, 14 June 2005 06:16 Go to previous messageGo to next message
exquisitus is currently offline exquisitusFriend
Messages: 13
Registered: July 2009
Junior Member
Thanks Przemyslaw,

It works.

By any chance do you know how to get the Java project associated with the
current resource. I tried "workspaceRoot.getProject()", but that always
returns null in my case.

Thanks,
- Nitin
Re: Finding all classes in the current project's classpath [message #286661 is a reply to message #286649] Tue, 14 June 2005 13:14 Go to previous message
Przemyslaw Doe is currently offline Przemyslaw DoeFriend
Messages: 49
Registered: July 2009
Member
I m not sure to understand your question...maybe this helps:
IResource res;
IProject project = res.getProject();
IJavaProject javaProject = JavaCore.create(project) ;



"Nitin" <nitin@technobuff.net> schrieb im Newsbeitrag
news:32ebb0b5420ed797ca73301b05895e7c$1@www.eclipse.org...
> Thanks Przemyslaw,
>
> It works.
>
> By any chance do you know how to get the Java project associated with the
> current resource. I tried "workspaceRoot.getProject()", but that always
> returns null in my case.
>
> Thanks,
> - Nitin
>
Previous Topic:Automatically break strings
Next Topic:Hide my breakpoints
Goto Forum:
  


Current Time: Sat Jul 13 16:57:52 GMT 2024

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

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

Back to the top