Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Ignore checkstyle javadoc warning for a method with a specific annotation

Checkstyle warns when I have a public method without javadoc, which is nice! When I override a public method I don't get the warning because the javadoc is already available in the parent class for the method.

Now I have an other annotation for my method for example @MyEvent. Now I do get the warning but don't want it because the annotation says enough. Can I exclude warnings for methods with a specific annotation?

There are some solutions that involve adding stuff to my code like @SuppressWarnings or comments like // CHECKSTYLE.OFF but this does not make my code nicer, i could instead just add the javadoc. So I'm looking for a configuration level solution.

like image 765
Martin Avatar asked Sep 30 '14 11:09

Martin


People also ask

How do I stop checkstyle warnings?

It is possible to suppress all the checkstyle warnings with the argument "all" . You can also use a checkstyle: prefix to prevent compiler from processing these annotations. You can also define aliases for check names that need to be suppressed.

How do I exclude files from checkstyle?

To skip all checks in all files under directories (packages) named "generated", you must use regex pattern <suppress checks="[a-zA-Z0-9]*" files="[\\/]generated[\\/]" /> It was really little hard for me to find out the right pattern for files parameter.


2 Answers

The allowedAnnotations property of JavadocMethod module defines which annoted methods are skipped/ignored for javadoc check. The given example uses Checkstyle v8.8 .

<module name="Checker">
  <module name="TreeWalker">
    <module name="JavadocMethod">
      <property name="allowedAnnotations" value="Override, Test, Before, BeforeClass"/>
    </module>
  </module>
</module>
like image 82
Naxos84 Avatar answered Oct 22 '22 04:10

Naxos84


Can I exclude warnings for methods with a specific annotation?

You can suppress warnings by using one specific annotation (@SuppressWarnings), but other annotations can not be used to that effect (such as @MyEvent).

At least not out of the box. If you are willing to do some programming, you can develop your own custom filter that does what you need.

like image 1
barfuin Avatar answered Oct 22 '22 02:10

barfuin