Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 which causes "unused import" checkstyle errors later. Is there some configuration I can change to avoid eclipse automatically importing when I type the class name in the comments?

like image 310
newguy Avatar asked Sep 06 '10 07:09

newguy


People also ask

When using Eclipse whichever classes are needed for the present class can be imported automatically?

In above situation, Eclipse comes with a nice feature called “Organize Imports” to imports all the classes that are used, automatically. A copied source code without imports.


2 Answers

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.

like image 113
musiKk Avatar answered Oct 02 '22 19:10

musiKk


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
 */
like image 27
Andrew Swan Avatar answered Oct 02 '22 18:10

Andrew Swan