Community
Participate
Working Groups
Just tried out M6 for the first time. Given: I have a src file with an import that is not used by any source but is referred to in javadoc comment. Try: Organize Imports Expected: that the unused import would be removed What Really Happens: The import is not removed. I must use the "remove import" quick fix (or delete the javadoc reference and organize again).
To recreate, make the following class Foo.java as follows: public class Foo { /** * @throws IOException */ public void bar() { } } If you create this class then do an "Organise Imports" on it in the Java IDE then the following import will be inserted in the class file: import java.io.IOException; The Eclipse IDE will then complain that "The import java.io.IOException is never used". You can try to do an "Organise Imports" again, but the error remains. Deleting the "@throws IOException" javadoc clears the error. PB
Importing the exception is correct when you have "Process Javadoc" enabled on the compiler preference page since the Javadoc tool needs to have that import to correctly generated Javadoc. However there seems to be a problem that the compiler flags the import as unused although it is used inside Javadoc.
I would submit that this statement: "However there seems to be a problem that the compiler flags the import as unused although it is used inside Javadoc." ibhs completely backwards. An import is unused if it is not referenced in the *code* not the javadoc. Javadoc is useful text but last time I checked it is not part of the executable for my class. Isn't that what Annotations in JDK 1.5 are for?
Side effect of build optimization. Doc comment support was invalidate while building if no specific javadoc tags options (invalid or missing) were set. Need to add unused import also as in this case it's really important to look inside javadoc to find used references...
About comment 3: no it's not backwards. If user still want consider javadoc comment as flat text, then he can do it by unsetting option "Process Javadoc Comments". But ,as soon as this option is set (which is the default), then compiler considers that some part of javadoc comments can be considered as code (typically @see references) and parse it to verify their accuracy. This is obviously necessary while renaming types, methods and fields. With "Process Javadoc Comments" option set, refactoring will rename all references even those which are in javadoc comments for free (and it's sometimes really appreciable...) Note that javadoc.exe do the same to report warnings when references put after @see, @link, etc. tags are not accurate.
Fixed and released in HEAD. Now Java Builder does not unset doc comment support when option unused import is activated. [jdt-core-internal] Change done in AbstractImageBuilder.newCompiler() method. Test case added in BasicBuildTests
Verified for 3.1 M7 using build I20050509-2010 + jdt.core HEAD.
*** Bug 100126 has been marked as a duplicate of this bug. ***
*** Bug 149752 has been marked as a duplicate of this bug. ***
*** Bug 253750 has been marked as a duplicate of this bug. ***
*** Bug 266979 has been marked as a duplicate of this bug. ***
I am able to reproduce this in 3.7 - an exception that only appears in the javadoc (throws XYException) will be automatically added to the imports of the class.