Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Adding namespace declaration programmatically
Adding namespace declaration programmatically [message #987163] Fri, 23 November 2012 22:12
Nehme Bilal is currently offline Nehme BilalFriend
Messages: 1
Registered: November 2012
Junior Member
Hello,

I am trying to programmatically add a namespace declaration to a ITranslationUnit of a class.

To get the ITranslationUnit I use:
ITranslationUnit tu = CoreModelUtil.findTranslationUnit(file);

where file is an IFile.

To add the namespace I use:
INamespace ns = tu.createNamespace("foo", null,	null);

This will create a namespace declaration at the end of the ITranslationUnit. Now, I'd like to move the class declaration into the namespace declaration. I have an ICElement reference to the class. To move the class, I tried:
ICElement[] ce = new ICElement[] { classElement }; // this is the class
ICElement[] nse = new ICElement[] { ns }; // this is the namespace
tu.getCModel().move(ce, nse, null, null, true, null);

It does move the class but it puts it after the namespace declaration not inside it:
namespace foo {
}
class C1 {
public:
	C1();
	virtual ~C1();
};


The description of ICModel::move says:
void move(ICElement[] elements,
          ICElement[] containers,
          ICElement[] siblings,
          String[] renamings,
          boolean replace,
          IProgressMonitor monitor)
          throws CModelException

Moves the given elements to the specified container(s). If one container is specified, all elements are moved to that container. If more than one container is specified, the number of elements and containers must match, and each element is moved to its associated container. 


It doesn't seem to be moving the elements to the container but after the container.

Can anyone help with that ?

Thanks !
Previous Topic:"Can't linke to a main executable"
Next Topic:Eclipse download location
Goto Forum:
  


Current Time: Sun Nov 23 10:02:41 GMT 2014

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

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