Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to get fully qualified names of classes in a project
How to get fully qualified names of classes in a project [message #330734] Tue, 12 August 2008 12:37 Go to next message
Prasanna K is currently offline Prasanna KFriend
Messages: 78
Registered: July 2009
Member
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Prasanna K is currently offline Prasanna KFriend
Messages: 78
Registered: July 2009
Member
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.
Re: How to get fully qualified names of classes in a project [message #330776 is a reply to message #330774] Wed, 13 August 2008 08:50 Go to previous message
Prasanna K is currently offline Prasanna KFriend
Messages: 78
Registered: July 2009
Member
Please reply in this thread :
http://www.eclipse.org/newsportal/article.php?id=23300&g roup=eclipse.tools.jdt#23300
Thanks.
Previous Topic:[Databinding] Without PropertyChangeListener
Next Topic:Remove specific Menu-contributions via Activities
Goto Forum:
  


Current Time: Tue Jul 16 17:11:46 GMT 2024

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

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

Back to the top