Bug 41920 - Imports for inner classes show as unused...
Summary: Imports for inner classes show as unused...
Status: CLOSED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows All
: P3 minor (vote)
Target Milestone: 3.0 M7   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2003-08-25 10:34 EDT by Michael Bauer CLA
Modified: 2009-08-30 02:05 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Bauer CLA 2003-08-25 10:34:02 EDT
Imports that are used by inner classes, but not referenced by the outer class, 
are designated by the editor as being unused imports.  The check to see if an 
import is used or not should also include inner classes, which is does not seem 
to currently do.

To recreate:
1) Create a class
2) Create an inner class
3) Make a reference to some object (StringTokenizer, for instance) in the inner 
class somewhere, and Ctrl-space the name to add the import statement.

The import should be underlined in yellow now, and an error should be added to 
the error tab below.
Comment 1 Rafael Chaves CLA 2003-08-25 10:41:57 EDT
Routing to JDT/Core.
Comment 2 Olivier Thomann CLA 2003-08-25 11:04:15 EDT
Are you sure that you don't have another error in your code?
For example, this reports two errors:
import java.util.StringTokenizer;

public class Foo {

	class B {
		public static Object bar() {
			return new StringTokenizer("");
		}
	}
}
Because a static method has to be in a static inner class or a top level class. 
The import is reported as unused, because the method is not parsed (its 
signature is invalid).
Do you have something similar? If you remove the static keyword in the bar 
signature, then the unused import error is removed as well.
Comment 3 Michael Bauer CLA 2003-08-25 15:27:31 EDT
My inner class is not static.  I have a normal, named inner class...something 
like:

package my.package

import java.util.StringTokenizer;

public class A {
  /*
   ... code ...
  */

  protected class B {
     public void myMethod() {
        StringTokenizer strtok = new StringTokenizer("my string");
     }
  }
}


In this example, like 3, the import statement, would be marked with an '!' 
warining message and underlined in yellow, with the message telling me that the 
import for StringTokenizer is not used.  If I remove this import, then the 
warning gets replaced by an error on line 12 because I am using a class without 
importing it.  Its a catch 22, either I get a warning or an error.  I can live 
with the warning, but then that breaks the "Optimize Imports" functionality, 
because doing so will remove the import, causing the error on line 12.

I believe the correct functionality would be to not display ANY error/warning 
in this code, as nothing is wrong with it as-is.
Comment 4 Philipe Mulet CLA 2003-08-28 12:22:53 EDT
Cannot reproduce with your test case using 20030827. Can you please double 
check your steps and reopen this defect then ?
Comment 5 Philipe Mulet CLA 2004-01-15 19:19:58 EST
Closing as never reproduced in a long time.
Comment 6 Denis Roy CLA 2009-08-30 02:05:13 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.