Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Advanced editor templates for C++.(Question + proposal about the Eclipse "editor templates" functionality)
Advanced editor templates for C++. [message #1733530] Sun, 29 May 2016 19:58
Goncharuk Vladislav is currently offline Goncharuk VladislavFriend
Messages: 1
Registered: May 2016
Junior Member
Hi, Eclipse community.
I've registered here to post a new topic about the Eclipse "editor templates".

Beforehand, let me apologize for my bad English. It is not my native language. Wink

I'm using Eclipse CDT for about 3 years in my everyday work.

It fits all my internal requirements.
- The best autocomplete, which is able to resolve types from the nested C++ template classes.
- The built-in viewer of the preprocessor output ( which allow to quickly debug complicated macros ).
- Very useful third-party highlighting plugin ( as I remember, it is called EditBox ), which allows to work with code faster.
- Auto generated doxygen comments
And many more things, for which I really love CDT.

( Here comes the BUT ).

BUT.

For this 2 days I was trying to find out, how can I work with code faster, using the CDT. The thing is about the automation of the boilerplate code.

I've read the documentation about the editor templates. I've used this feature before only to save some code snippets, but now I had some time to improve my skills in this area.

Well, I've found, that there is not much preferences, which I can use. Only about 10 predefined variables + availability to define the placeholders.

This is not enough. I thought there will be much more functionality in this area.

I've also read, that there is a possibility to extend the amount of the predefined variables via some kind of extension points. But I am the C++ developer.

I know some basic things about Java. I've actually written some code generators iusing Java and Xtend.

But, from the users point of view, I would like to have the possibility, to create advanced C++ templates without the need to create the eclipse extensions or plugins in Java.

Is there a way to do it?
May be we could think about such kind of extension for CDT?

What I'm talking about is some kind of script language for C++ templates definitions, which will allow user to interact with the indexer data. I want to be able to do something like:

Template name : switch for enum.
Template description : creates switch for enumeration type.
Template content:

if( true == is_type( word_selection ) )
{
   if( getCPPType( word_selection ) == enum )
   {
      '''switch( ${word_selection} )
        {'''
      for( value : getEnumValues( word_selection ) )
      {
         '''   case ${value}:
                 break;'''
      }
      '''}'''
   }
}


In this case I've used ''' sign for the literal, which will be placed as the result.
All such literals should be appended together.

Another example could be a template for copy / move constructors :

Template name : copy constructor.
Template description : creates copy constructor implementation
Template content:

if( true == is_type( word_selection ) )
{
   if( ( getCPPType( word_selection ) == class ) || ( getCPPType( word_selection ) == struct ) )
   {
      '''${word_selection}::${word_selection }( ${word_selection }& rhs )
        {'''
      for( field : getFields( word_selection ) )
      {
         '''   ${field} = rhs.${field};'''
      }
      '''}'''
   }
}


The above text is just draft examples.
It is not about the final version of the possible synthax.
It is about some powerful thing we might have.

It also can be used to generate enum2string methods, to generate stub implementations of the interfaces ( we will be able to iterate over the inherited classes and their pure virtual methods ).

It would be a great improvement to have such a flexible template system. It would leave all other IDEs far behind.

I can even invest my time to develop some extensions. But I should know the following things:

- May be there is something like this on the eclipse market and I just don't know about it?
- Is it possible to do something like this with current template editor? Or I should create this functionality as a separate plugin from scratch?
- Is there a way to interact with the CDT built-in C++ parser? I want to use its model to get the data about parsed types.
- If I will be forced to right a separate plugin - is it possible to interact with content assist to add new suggestions to the list?
- Is it possible for a single person to develop such thing? Or I will drown in the amount of work?

If it is a stupid and useless suggestion, feel free to say so. ))
Previous Topic:Include a path for system headers (-isystem)
Next Topic:Trouble with libraries
Goto Forum:
  


Current Time: Wed Nov 22 05:54:07 GMT 2017

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

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