Bug 198518 - [javadoc] Wrong warning of unused import for reference in Javadoc
Summary: [javadoc] Wrong warning of unused import for reference in Javadoc
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P5 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2007-08-01 07:15 EDT by Koen van Dijken CLA
Modified: 2016-10-10 12:57 EDT (History)
10 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Koen van Dijken CLA 2007-08-01 07:15:54 EDT
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:
Comment 1 Tim Buss CLA 2007-08-09 11:13:45 EDT
Think this bug is mis-classified.  It is not an ALF bug
Comment 2 Martin Aeschlimann CLA 2007-08-14 05:41:52 EDT
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);

}
Comment 3 Frederic Fusier CLA 2007-08-14 07:14:55 EDT
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...
Comment 4 Kent Johnson CLA 2007-08-14 09:51:10 EDT
I pretty sure that A2 is found thru inheritance so the import is not needed.
Comment 5 Martin Aeschlimann CLA 2007-08-14 09:55:47 EDT
To test this, remove the import and run the Javadoc command. You will get an error that 'A2' can not be resolved.
Comment 6 Kent Johnson CLA 2007-08-14 11:20:34 EDT
Martin, please try this example with A & B defined in the default package.

I'm seeing an error on the generated import
Comment 7 Kent Johnson CLA 2007-08-14 11:26:24 EDT
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?
Comment 8 Martin Aeschlimann CLA 2007-08-14 11:48:29 EDT
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.
Comment 9 Andrew John Hughes CLA 2008-02-16 19:58:53 EST
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).
Comment 10 Andy Gianfagna CLA 2008-03-27 15:25:51 EDT
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.
Comment 11 Frederic Fusier CLA 2008-09-04 12:14:07 EDT
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
Comment 12 Joerg Hohwiller CLA 2009-07-25 07:09:25 EDT
This looks like a duplicate of bug #128661.
Comment 13 Dani Megert CLA 2010-07-14 09:54:23 EDT
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.
Comment 14 Olivier Thomann CLA 2011-01-25 11:14:19 EST
Verified.