views:

81

answers:

2

Is there a way to enforce a code style programatically in eclipse e.g. using eclipse plugins.

I have created a code template. I want to enforce it so that everytime a user selects save or saveas,the code template is checked against the one I created. If it matches the file is saved otherwise the user gets an error message.

The problem I am facing is - how do I get Code Style (template) name at run time.. and where do i add this code so that to enforce it...

Any pointers is greatly appreciated.

A: 

Look into save actions which allow you to dó many things. We reformat ón every save according to our formatting rule set.

Thorbjørn Ravn Andersen
The code template is for C/C++.And I want to formate the code programatically. That is end user does not has to set anything. Everything should be automatic.There is particular code format say "xyz" according to which the code has to be autoformatted on save.So, I have to find out the code template saved and that too at runtime.Is there a class or file which persists the value of code template selected. so that I can get it and set the template to xyz if it is not already selected.
kumar
If the template is for C/C++ and not Java you might get better answers by not using the java tag for the question...
Thorbjørn Ravn Andersen
+1  A: 

Preferences -> Java -> Editor -> Save Actions -> Perform the selected actions on save -> Format source code

nanda
thanks. it seems to work for java code. Is there a way to incorporate a similar feature for C/C++ code. I installed cdt but it does not provide the same features as jdt.
kumar