This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 85968

Summary: Fix Imports should use context clues to determine imports
Product: java Reporter: Petr Hrebejk <phrebejk>
Component: SourceAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: blocker CC: malfunction84, tboudreau
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description Petr Hrebejk 2006-09-27 22:36:00 UTC
You are probably already planning this anyway, but:

When I use Alt-Shift-F to fix imports, say of
Document d = jtc.getDocument();

fix imports should notice that there is also a line
if ('\n' == d.getText (pos, 1).charAt(0)) { //NOI18N

which probably guarantees this is javax.swing.text.Document, and if it does, it
should auto-import it with no dialog.
Comment 1 Rastislav Komara 2009-02-03 10:55:19 UTC
Overtake.
Comment 2 malfunction84 2009-02-12 22:55:03 UTC
Fix Imports could take into account other things too, like assignment to/from other known types, and whether the type is
being used as an annotation.

- Method invocations:
    unknownType.doSomething();
    // only suggest types which have a doSomething() method.

- Assignments from known subtypes:
    UnknownType u = (KnownType) map.get(key);
    // only suggest types which KnownType extends or implements

- Assignments to known supertypes:
    KnownType k = (UnknownType) map.get(key);
    // only suggest types which extend or implement KnownType

- Annotations:
    @UnknownType
    private int i;
    // only suggest types which are annotations that can be applied to fields

So basically, it should only offer suggestions that will compile cleanly.

The dialog's appearance can still be based off the number of matches:
- If only one type works, it should automatically import that type.
- If multiple types work, it should offer them in the Fix Imports dialog.
- If no types work, then it should match on class names only (current behavior) and offer them in the Fix Imports dialog.
Comment 3 malfunction84 2009-02-12 23:01:49 UTC
*** Issue 140522 has been marked as a duplicate of this issue. ***
Comment 4 malfunction84 2009-02-12 23:04:48 UTC
*** Issue 130115 has been marked as a duplicate of this issue. ***
Comment 5 Jan Lahoda 2010-05-11 13:46:49 UTC
Resetting assignee to default for all bugs reported against product java and assigned to moonko.