Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 372376

Summary: Auto-import of static nested class does not work
Product: [Eclipse Project] JDT Reporter: Blessed Geek <blessedgeek>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: stephan.herrmann
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Blessed Geek CLA 2012-02-23 12:03:29 EST
Build Identifier: M20110909-1335

Possibly related to issues 294002 and 230300.

Project is JDK 1.6 compliant.
I am using it in conjunction with GWT 2.4.0.

Issues
- Java editor shows error when Generic parameter is a nested class.
- Java editor error would go away by importing the inner nested class.
- Auto-complete does not list current class and therefore auto-complete is unhelpful in importing current-class.nested-class.
- Auto-import dialog suggests importing the nested class, but clicking on the suggestion in the dialog does not have any effect.

Reproducible: Always

Steps to Reproduce:
Consider the following class:

package red.riding.hood.toyfactory.client.details.view;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;

public class ToyPropertyDefinitionGrid
extends Grid<PropertyDefinitionModel>{ // Line 6

  static public class PropertyDefinitionModel
  extends BaseModel{
    ....
  }
  ....
}

With regards to the line commented as //Line 6 above ...

First Issue:

1. PropertyDefinitionModel is a static nested class of ToyPropertyDefinitionGrid.

2. ToyPropertyDefinitionGrid extends Grid<PropertyDefinitionModel>

3. Java editor marks Line 6 as error because the editor is not able to locate static inner class without an import statement.

4. Right click on Line 6
extends Grid<^cursor here>{

5. Progress the cursor rightwords until Line 6 becomes 
extends Grid<PropertyDefinitionModel^cursor here>{

6. Hit return to confirm auto-complete. Auto-import does not occur at all.


2nd Issue:

7. Key in the import line at the import section, terminating it with a dot.

import red.riding.hood.toyfactory.client.client.view.ToyPropertyDefinitionGrid.^cursor here

8. The current class does not show up among the list.

9. If the current class does not show up in the list, how then can I depend on auto-complete to import a class nested in the current class?

Finally:

10. Does the java specs say that you need an import statement for using a class nested in the current class?
Comment 1 Stephan Herrmann CLA 2012-02-23 13:07:23 EST
This is not an issue of imports, which only serve to make classes from other packages available by their simple name.

I think you're facing the following problem: At the class header of ToyPropertyDefinitionGrid the type PropertyDefinitionModel is not visible, because it exists only *inside* the class, but the header is not part of "the inside".

The solution would be to specify:
public class ToyPropertyDefinitionGrid
extends Grid<ToyPropertyDefinitionGrid.PropertyDefinitionModel>

No import needed.
I don't think there's a way to abbreviate this.
Comment 2 Stephan Herrmann CLA 2012-02-23 13:18:27 EST
See also bug 325357 for an inconclusive discussion on whether or not imports should make a difference in similar situations.
Comment 3 Eclipse Genie CLA 2020-03-13 17:17:47 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.