Reputation: 1501
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?
Upvotes: 11
Views: 1600
Reputation: 23179
Eclipse offers the ability to configure the Clean Up tool to do this for you.
Upvotes: 7
Reputation: 533780
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.
Upvotes: 2
Reputation: 3084
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
Upvotes: 1
Reputation: 1503070
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.
Upvotes: 19
Reputation: 34179
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.
Upvotes: 9