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 57853 - Fix Import should default to favorite classes
Summary: Fix Import should default to favorite classes
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 5.x
Hardware: All Windows XP
: P3 blocker with 1 vote (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-13 22:15 UTC by _ gtzabari
Modified: 2013-11-08 18:24 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ gtzabari 2005-04-13 22:15:09 UTC
When "Fix Imports" is invoked and there are multiple possible matches, always
default to the most frequently chosen entry. That is, if whenever I was
presented with classes A or B I always chose class A, then Netbeans should
default to matching against A automatically.
Comment 1 tomwheeler 2011-09-24 19:39:14 UTC
I will second this and add some more explanation about the problem and potential solutions.

In order to use the IDE as efficiently as possible, I tend to call a method in some class in my source code, then hit Alt+Enter to add the import statement for that class.  In my view, having to deal with import statements gets in the way of the problem I am trying to solve and it's best when the IDE can handle this for me.

When you have a unique classname (like TopComponent) the "use first, import later" method I describe works great.  Where it fails is when you have a classname which exists in several packages.  For example, if I am using Log4J in my project, then a reference to Logger should offer Log4J's logger as the first choice and java.util.Logger as the second.  

A more complex case might be a class like Node.  In a given project, I might be using Node from the NetBeans Node API, an XML DOM node or a Java 3D node.  In such a case, the IDE should be able to tell from the context (i.e. which method I invoked and what it's return value is) in order to tell which class to import.

See also issues #154258 and #120614.
Comment 2 Jan Lahoda 2011-10-26 14:18:14 UTC
FYI: the basic import features contain a few heuristics to guess the correct types to import since 6.0. The Add import hint and Fix All Imports dialog painted the unsuitable imports in gray. It has been disabled for a while, as it was confusing users. Has been reenabled in 6.9 or 7.0 (don't remember exactly), but is only used to sort the suitable imports above the unsuitable. E.g., if you will add this into an empty class:
    List l = new ArrayList();

the java.util.List should be the first, as is the only import that matches java.util.ArrayList (which is the only accessible ArrayList in J2SE). There is a command line option to specify coloring for the unsuitable imports:
-J-Dorg.netbeans.modules.java.editor.imports.JavaFixAllImports.invalid_import_html="<html><font color='#808080'>"