How to get fully qualified names of classes in a project [message #255527] |
Tue, 12 August 2008 08:39  |
Eclipse User |
|
|
|
Hi,
I am sure there must be a way to achieve this.
Let's say there is a package
abc.pack.myFirst
And there are two classes (java files) in this package : FirstClass.java
SecondClass.java
I want the list which should include two entries :
abc.pack.myFirst.FirstClass,
abc.pack.myFirst.SecondClass
How do I achieve this?
Thanks.
|
|
|
Re: How to get fully qualified names of classes in a project [message #255536 is a reply to message #255527] |
Tue, 12 August 2008 11:58   |
Eclipse User |
|
|
|
"kaprasanna" <kaprasannagt@gmail.com> wrote in message
news:ea2726cc8307327d2746b9bd8615f654$1@www.eclipse.org...
> Let's say there is a package
> abc.pack.myFirst
> And there are two classes (java files) in this package : FirstClass.java
> SecondClass.java
> I want the list which should include two entries :
> abc.pack.myFirst.FirstClass,
> abc.pack.myFirst.SecondClass
>
> How do I achieve this?
Your question is less well-formed than it seems.
Broadly speaking, you will use methods on IJavaElement and IOpenable to
start with some sort of root (an IPackageFragmentRoot or an IProject,
perhaps) and iterate its children, to some hierarchical depth depending on
what it is you're trying to find. But if you can be more specific about
your question we can probably provide better answers. Here's why:
A .java file, aka a "compilation unit", may contain more than one class.
Here's a valid java file with four different _kinds_ of classes:
Foo.java:
/////////////////////////
package p;
public class Foo {
public static class Bar {}
public Bar getBar() {
class Humpf extends Quux {}
return new Humpf();
}
}
class Quux extends Foo.Bar {}
//////////////////////////
Also, be aware that packages can have multiple fragments - for instance,
abc.pack might be getting some of its classes from source code, others from
JARs on the build path.
So, I am not sure exactly what things you are trying to list - the .class
files that will be generated from the source code in your project? All the
visible types within an entire package? There are many subtly different
things you could mean; precise definition now will avoid bugs later.
|
|
|
|
Re: How to get fully qualified names of classes in a project [message #255556 is a reply to message #255544] |
Wed, 13 August 2008 04:48  |
Eclipse User |
|
|
|
Eric Rizzo,
Apologies for having posted same question in two different newsgroups.
Will take care in future.
For now, I have added a reply in the other thread to divert the traffic to
this thread.
Walter Harley,
I admit my question doesn't describe the whole scenario.
It is something like this :
The user right clicks on a project and the context menu appears and he
clicks on the custom menu.
The action needs to be taken in public void run(IAction action) {} method
in the class that implements this interface :
org.eclipse.ui.IObjectActionDelegate.
The selected object we have got is an instance of IProject.
We need a list of Strings at the end of this.
Each String should be the fully qualified name of the class present in the
project.
There might be following folders in the selected project :
src
bin
...
...
src might have following following folder :
java
This folder might have following packages :
com.abc.core
com.abc.util
Let's say following are the (.java) files in respective packages :
com.abc.core
AppInterface.java
AppInterfaceImpl.java
MyAppCore.java
com.abc.util
ProjectUtil.java
AppUtil.java
Let's say ProjectUtil.java looks like this :
package com.abc.util;
class ProjectUtil {
class SpecificUtil {
}
}
ALso let's assume MyAppCore.java looks like this
package com.abc.core;
class MyAppCore {
}
class MyAppHelp {
}
The list we are interested in should have following elements :
com.abc.core.AppInterface
com.abc.core.AppInterfaceImpl
com.abc.core.MyAppCore
com.abc.core.MyAppHelp
com.abc.util.ProjectUtil
com.abc.util.ProjectUtil$SpecificUtil
com.abc.util.AppUtil
Thanks.
|
|
|
Powered by
FUDForum. Page generated in 0.02908 seconds