问题
Is there a static analysis tool that can enforce usage of the @Override annotation consistently that can be run outside of an IDE? CheckStyle has a MissingOverride check but it only applies to methods that use the @inheritDoc Javadoc tag. I'm looking for a tool that can be run in a new build configuration on a continuous integration machine.
回答1:
PMD now has a MissingOverride rule.
What about PMD or Findbugs? PMD enables that you can even write your own rule (if it isn't disposable in the default rule set).
https://pmd.github.io/pmd-6.3.0/pmd_userdocs_extending_writing_pmd_rules.html
回答2:
I am using Sonar wich gives me the warnings but most importantly I am using eclipse (and so does my team) and I have set an option "add missing @Overrides" to be done on save action.
回答3:
One way is to use TeamCity's "Inspection" runner. I'm not sure if it really qualifies as running outside the IDE since it's configured in IntelliJ and it works by running IntelliJ in headless mode on the TeamCity side.
回答4:
Error Prone has a MissingOverride Pattern It appears that errorprone is evaluated at compile time. By default this is a warning but I configured it to be an error.
回答5:
On IntelliJ 2017, go to Settings -> Editor -> Inspections -> Missing @Override annotation
image example 0 (no enough reputation to post images)
来源:https://stackoverflow.com/questions/5794382/how-to-enforce-usage-of-the-override-annotation