开发者

Enforce "this" access

Due to some weird requirements (post processing of source code) I need to use "this." syntax instead of just the member variable name. Is there a way I can enforce stati开发者_Python百科c checks at compile time to ensure that I am using "this." instead of the shorter equivalent?


In Eclipse you could go into Java / Compiler / Errors and warnings / Code Style and change "unqualified access to instance field" to Error instead of the default Ignore.

EDIT: Using a mixture of this change to the IDE (if you're using Eclipse, of course) and checkstyle as part of your build rules should suffice.


Have you ever used checkstyle? You can define your code style rule in xml and run it at compile time. There is also a maven plugin if you care.


Eclipse offers the ability to configure the Clean Up tool to do this for you.

Enforce "this" access


IntelliJ has a code style check for Instance field access not qualified with 'this'

It also has the option correct this for a field, class or modules. This sort of thing could safe you having to touch many files yourself.


You could use checkstyle to impose such requirements.


You should be able to use a static code analyzer like CheckStyle to acomplish this in compile time.

http://checkstyle.sourceforge.net/config_coding.html#RequireThis

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜