Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » How to find if a project is a C/C++ project
How to find if a project is a C/C++ project [message #48290] Thu, 31 October 2002 14:45 Go to next message
Eclipse UserFriend
Hi,

I am writing a plugin which uses CDT. When the user clicks on a project,
I need to find if the selection made is a C/C++ project.

I am doing something like this.

Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof ICProject)
{ //do something
}

I created both a C and C++ project in the C/C++ perspective. But the
above code does not work when these projects are selected and I get the
following exception.

Unhandled exception caught in event loop.
Reason:
org/eclipse/cdt/core/model/ICProject

I am not sure if I am doing something wrong. Any help is greatly
appreciated.

Thanks
-Kiran
Re: How to find if a project is a C/C++ project [message #48502 is a reply to message #48290] Sat, 02 November 2002 20:47 Go to previous message
Eclipse UserFriend
Hi Kiran

"Kiran" <klingutla@hotmail.com> wrote in message
news:3DC18844.2000409@hotmail.com...
> Hi,
>
> I am writing a plugin which uses CDT. When the user clicks on a project,
> I need to find if the selection made is a C/C++ project.

Projects all have something called natures. In the case of the C/C++
projects it works like this.

All Eclipse projects are considered Simple Projects. This is implied, there
is no explicit nature assigned.
All C Projects have a cnature and all C++ prjects have both a C nature and a
C++ nature.

There are several things that you can do programmatically to find out if a
project has the required projects.
The simpliest is as follows:
I am away from the source code right now, so I may get class names wrong,
but they should be close enough to find the correct one is you are good at
searches. If you still haven't found then, I'll check back with the correct
ones on Monday.

OK... There is a class in the CDT called "CNature" (or something very close
to it.) It has methods that allow you to pass it an IProject and ask whether
it has a cnature or a cppnature..
Hopefuly this is enough to get you started.

Note: The project must be open in order for the methods to not throw an
exception.

The Conversion Wizards might be a good place to look for how to deal with
natures. If you find any erros be sure to let me know ;)
They can be found in org.eclipse.cdt.ui in wizards.conversion

Good luck

-Judy


>
> I am doing something like this.
>
> Object obj = ((IStructuredSelection) selection).getFirstElement();
> if (obj instanceof ICProject)
> { //do something
> }
>
> I created both a C and C++ project in the C/C++ perspective. But the
> above code does not work when these projects are selected and I get the
> following exception.
>
> Unhandled exception caught in event loop.
> Reason:
> org/eclipse/cdt/core/model/ICProject
>
> I am not sure if I am doing something wrong. Any help is greatly
> appreciated.
>
> Thanks
> -Kiran
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.410 / Virus Database: 231 - Release Date: 10/31/02
Previous Topic:F4 posted ready for download
Next Topic:Build Command
Goto Forum:
  


Current Time: Sun Jul 13 18:04:11 EDT 2025

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

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

Back to the top