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 static 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With