How to avoid Eclipse importing a class when putting the class name in the comments, so that checkstyle does not complain later?

后端 未结 4 941
花落未央
花落未央 2021-02-12 22:43

Sometimes I put the class name in the comments of methods or class just for referencing. But eclipse does the import automatically and leaves an import statement in the file whi

相关标签:
4条回答
  • 2021-02-12 22:57

    The Checkstyle bug has been fixed now. In Checkstyle config, go Imports > Unused Imports > click Open > make sure processJavadoc is checked.

    enter image description here

    Now Checkstyle doesn't warn on this anymore.

    0 讨论(0)
  • 2021-02-12 22:59

    In checkstyle.xml, change

    <module name="UnusedImports"/>
    

    to:

    <module name="UnusedImports">
            <property name="processJavadoc" value="true"/>
    </module>
    

    This requires version 6.0 of Checkstyle.

    Source: https://github.com/jboss/jboss-parent-pom/issues/23

    0 讨论(0)
  • 2021-02-12 23:12

    If you use the fully-qualified class name in the JavaDoc, Eclipse will not add an import, e.g.

    /**
     * This class is a {@link java.io.File} that blah blah blah
     */
    
    0 讨论(0)
  • 2021-02-12 23:13

    People don't agree whether this is a bug or not. Javadoc needs the imports to create appropriate links. I'd say checkstyle should provide an option (and Eclipse maybe too) to change the warning.

    There are two relevant bug reports:

    • eclipse
    • checkstyle (now fixed)

    Update: The mentioned bug has been fixed in checkstyle. You know have the option to configure the behavior.

    0 讨论(0)
提交回复
热议问题