Bug 419411 - [content assist] should have option to prevent direct import of inner classes
Summary: [content assist] should have option to prevent direct import of inner classes
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P5 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
: 131705 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-10-14 20:49 EDT by jules CLA
Modified: 2013-12-05 05:56 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jules CLA 2013-10-14 20:49:57 EDT
In the context of an expression whose type is known to be a nested type of another class, content assist will suggest completions for constructor calls, e.g. with a static class "Schedule.Item", typing:

    Schedule.Item item = new

and pressing ctrl+space gives a list of the constructors for Schedule.Item.  If one of these constructors is selected, content assist inserts an import for Schedule.Item, and completes the line with "Item (arg1, ...)". As it is quite common for names of such classes to be practically meaningless without the name of the class they are a component of, adding such imports can be a bad idea (examples of names that are meaningless without the additional context include: Map.Entry, RowFilter.Entry and KeyStore.Entry; all of the concrete classes in java.awt.geom - e.g. Rectangle2D.Double; Character.Subset; the various subclasses of javax.sound.sampled.Control.Type; the subclasses of Format.Field; any of several nested classes in the API whose name is 'Builder', which is useless without knowing what it builds; and so on).  Such naming being so common, I would even argue that the option should default to not importing such classes.
Comment 1 Dani Megert CLA 2013-10-15 04:36:43 EDT
Jules, can you give a complete example? When I try "it" in 4.4 M2, no such import is added.
Comment 2 Timo Kinnunen CLA 2013-10-16 08:29:23 EDT
I don't see an import either, but the inserted code doesn't compile either. Content assist for javax.swing.text.html.HTML.UnknownTag u = new produces

javax.swing.text.html.HTML.UnknownTag u = new UnknownTag(id);

The quick-fix for that only offers to add import javax.swing.text.html.HTML.UnknownTag. This issue is much easier to see with Ctrl-1 or Ctrl-2 quick assists when making new local variables. For example:

		color=HTML.Attribute.COLOR;
		CSS.getAttribute("color");

Creating two local variables from those with CSS and HTML already imported results in:

		Attribute color = HTML.Attribute.COLOR;
		javax.swing.text.html.CSS.Attribute attribute = CSS.getAttribute("color");

rather than the more desirable:

		HTML.Attribute color = HTML.Attribute.COLOR;
		CSS.Attribute attribute = CSS.getAttribute("color");
Comment 3 Dani Megert CLA 2013-10-30 07:08:45 EDT
(In reply to Timo Kinnunen from comment #2)
> I don't see an import either, but the inserted code doesn't compile either.

Yes, that's bug 294002.

> Content assist for javax.swing.text.html.HTML.UnknownTag u = new produces

Yes, if you choose the constructor proposal. If you choose the type it adds the import.


I see what you mean now:

1. paste this:
import java.util.Map;
class Snippet {
	Entry
}
2. content assist after Entry
==> additional import is added, but one might want to replace Entry with Map.Entry instead.


See also bug 99511.
Comment 4 Dani Megert CLA 2013-10-30 07:09:16 EDT
*** Bug 131705 has been marked as a duplicate of this bug. ***