Community
Participate
Working Groups
Build ID: I20070621-1340 Steps To Reproduce: The following scenario creates an unused import, which I usually get rid of by having "Organize imports" active in "Save Actions", but which in this case gets recreated automatically: 1. Windows/Preferences/Save Actions/Organize imports on 2. Create a project with these two classes: package test; public interface A { interface A2 { } void doIt(A2 a2); } and package test; /** * * @author koen * */ public class B implements A { public void doIt(A2 a2) { // TODO Auto-generated method stub } } 3. Open B.java in an editor 4. put the insertion cursor after the * in the second line of the javadoc 5. type "A2" (without the quotes), followed by Control-Space and Enter 6. This results in the following javadoc /** * {@link A2} * @author koen * */ 7. Save B.java This result in an import being generated, which is not needed: import test.A.A2; This import is not generated when the "Organize imports" option is not active in "Save Actions" Manualy removing the import and saving again creates the import again. More information:
Think this bug is mis-classified. It is not an ALF bug
The problem is in the compiler warning. The import 'import test.A.A2;' is required, otherwise the Javadoc tool can not find the reference to 'A2' (A2 is only visible inside the classbody of B, not outside) package test; import test.A.A2; // import marked as unused, but is required /** * {@link A2} * @author koen * */ public class B implements A { public void doIt(A2 a2) { } } package test; public interface A { interface A2 { } void doIt(A2 a2); }
Problem comes from JavadocSingleTypeReference.internalResolveType(Scope). The given scope is a class scope on type 'B' which implements A => while resolving the reference, the need of import is not stored hence the final incorrect 'unused import' warning...
I pretty sure that A2 is found thru inheritance so the import is not needed.
To test this, remove the import and run the Javadoc command. You will get an error that 'A2' can not be resolved.
Martin, please try this example with A & B defined in the default package. I'm seeing an error on the generated import
As for the visibility of A2 to the Javadoc tool - isn't it resolved in the context of B? Its attached to B so it should see the hierarchy of B. Does it use the classScope for B or not? When I remove the import, I do not get any errors/warnings AND can still hover over the link to A2 to see the correct type. So without the import, what isn't supposed to work?
Kent, file a new bug with the default package, if this is of importance (default package is always a corner case). The Javadoc tool has it's own special rules with resolving. What we want is that the Eclipse compiler emits the same warnings as the Javadoc tool.
I'm also seeing a similar problem when using ecj (Eclipse Java Compiler 0.671, 3.2.0 release in this case but sounds like it still exists in 3.3) separately to compile GNU Classpath. The compiler generates a lot of unused import warnings for imports that are actually used solely by the Javadoc in a particular class (and thus should not be removed).
I see a similar issue as well. Imports that are there just for the benefit of the Javadoc tool do not show up in the Problems view of Eclipse 3.3 during development, but they are generated when using PDE to do a headless build of an RCP application.
Ownership has changed for the javadoc comments bugs, but I surely will not have enough time to fix your bug during the 3.5 development process, hence set its priority to P5. Please provide a patch if you definitely need the bug to be fixed in this version and I'll have a look at it... TIA
This looks like a duplicate of bug #128661.
Using 3.6 this works as expected: if Javadoc processing is enabled an import inserted since it is needed to correctly generate the Javadoc. If Javadoc processing is disabled, then no import is added.
Verified.