Community
Participate
Working Groups
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.
Jules, can you give a complete example? When I try "it" in 4.4 M2, no such import is added.
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");
(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.
*** Bug 131705 has been marked as a duplicate of this bug. ***