How to get fully qualified names of classes in a project [message #330734] |
Tue, 12 August 2008 12:37  |
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 #330737 is a reply to message #330734] |
Tue, 12 August 2008 13:48   |
Eclipse User |
|
|
|
Originally posted by: lifesting.gmail.com
kaprasanna wrote:
> 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.
>
Yes, you can use JDT to visit Java resources such Package,
Class(CompilationUnit), Src Folder(PackageFragmentRoot) etc...
for example, define a WorbenchWindow action:
IPackageFragment pkg = null;
public void selectionChanged(IAction action, ISelection selection) {
if (selection instanceof IStructuredSelection)
{
Object select = ((IStructuredSelection)selection).getFirstElement();
if (select instanceof IPackageFragment)
pkg = (IPackageFragment) select;
else if (select instanceof IAdaptable)
pkg = (IPackageFragment)
((IAdaptable)select).getAdapter(IPackageFragment.class);
else ....
.....
......
}
public void run(IAction action) {
for(IJavaElement cls_or_pkg : pkg.getChildren())
{
if (cls_or_pkg instanceof ICompilationUnit)
fullNames.add(pkg.getElementName()+((ICompilationUnit)cls_or _pkg).getElementName());
}
|
|
|
Re: How to get fully qualified names of classes in a project [message #330774 is a reply to message #330737] |
Wed, 13 August 2008 07:00   |
Eclipse User |
|
|
|
Thanks for the reply.
I think the solution is partially applicable to my problem.
Consider the scenario :
User right clicks on a project and selects a menu.
At this point I need to know the list of fully qualified names of all
classes.
The selected object is an instance of IProject and not of IPackageFragment.
So how do I proceed?
Thanks.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02966 seconds