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 - Fix Imports should use context clues to determine imports
Summary: Fix Imports should use context clues to determine imports
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker with 1 vote (vote)
Assignee: Svata Dedic
: 130115 (view as bug list)
Depends on:
Reported: 2006-09-27 22:36 UTC by Petr Hrebejk
Modified: 2013-09-02 14:19 UTC (History)
2 users (show)

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
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
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:
    // 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:
    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.