开发者

Customizing inclusion guards in eclipse CDT

开发者 https://www.devze.com 2023-01-12 11:07 出处:网络
Is there a way to customize the format of inclusion guards in eclipse CDT for the class generation template? The curren开发者_如何学Pythont format is <Class Name>_H, but what I would like is som

Is there a way to customize the format of inclusion guards in eclipse CDT for the class generation template? The curren开发者_如何学Pythont format is <Class Name>_H, but what I would like is something like <namespace>_<namespace>_<class name>_H. Not that I expect to have classes with the same name in different namespaces within my own project, but I'd prefer not to worry about it should the case arise.


There is hard way to do this. You can rebuild plugin CDT plugin. Information about code repository and needed enviroment for rebuild available here. In your case you need change behavior of generateIncludeGuardSymbol() method that in

core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java

More about it described in this answer


I like Stuart's answer here:

How to customize eclipse CDT code templates

Just customize the template.

So in the Preferences dialog under C/C++ -> Code Style -> Code Templates you can modify the template to be closer to what you need, for example if you need the namespace in the guard, you can do something like.

${filecomment}

#ifndef ${namespace_name}_${include_guard_symbol}
#define ${namespace_name}_${include_guard_symbol}

${includes}

${namespace_begin}

${declarations}

${namespace_end}

#endif /* ${namespace_name}_${include_guard_symbol} */


This is in Neon...

Open up Window/Preferences.
Go down to C/C++/Code Style/Name Style.
Under Code you will find Include Guard.
It looks like some customization is allowed there.

This is the thing that gets expanded to ${include_guard_symbol}.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号