Smart.Instantiate

Smart.Instantiate is an additional functionality of Class.Insight that allows adding instantiation of a particular class by invoking Class.Insight, selecting the class and pressing SHIFT+ENTER. Smart.Instantiate recognizes the need to define a variable or just to create a new object. For example, when you type List fList = new List(100); and use Smart.Instantiate to create an ArrayList instance, Class.Insight replaces only the appropriate class name and preserves the variable definition and constructor parameters. You will get the following List fList = new ArrayList(100); The same behavior is exhibited when using Smart.Instantiate to create a new instance and as a parameter to a method call. In other cases, Smart.Instantiate inserts definition and initialization of the variable with a new instance of the selected class.

When an interface is selected to be instantiated, Smart.Instantiate automatically inserts implementation of the interface as an anonymous inner class. You can control this behavior using the Project Properties | Class.Insight | General property page.

A couple of samples of illustrating what Smart.Instantiate can do for you!

Code before invocation of Smart.Instantiate
Code before invocation of Smart.Instantiate
And code after invocation of Smart.Instantiate!
And code after invocation of Smart.Instantiate!
Code before invocation of Smart.Instantiate
Code before invocation of Smart.Instantiate
And code after invocation of Smart.Instantiate!
And code after invocation of Smart.Instantiate!

An alternative way to get Smart.Instantiate executed is using the shortcut Alt+I (CUA) that invokes a particular Smart.Instantiate popup. This popup is similar to the Class.Insight one but it doesn't require holding the SHIFT key to activate Smart.Instantiate - you just need to select a class and press the ENTER key to instantiate it.


Sample of Class.Insight hint
Sample of Smart.Instantiate Popup

Showing Navigation Pane

You can switch the Smart.Instantiate popup to show the Navigation Pane by turning off the Editor Options | Productivity! | Usage | Show Class.Insight popup as list checkbox. With this option turned off, Smart.Instantiate popup will be shown with the Navigation Pane, that allow to use Smart.Instantiate even if there is no word at the cursor position or if there are no classes matching it. To find matches, type a word in the Instantiate Class edit box and Smart.Instantiate will dynamically rearrange the classes' list to show the matching ones.

Options Dependency

Please note that the set of classes shown in the Smart.Instantiate list depends on Packages Exclusion settings on Project Properties | Productivity! | General property page.

Import statements are generated basing on the Imports Generation settings on Editor Options | Productivity! | General property page. There you can also customize other options of Smart.Instantiate, such as Search Options, Sort Classes By, Autocomplete and Productivity! Insights Usage

Using the Project Properties | Productivity! | General property page you can customize Code Generation Options which allow you to adjust the code style for the generated methods code.

See also: Productivity! Tools, Customizing Productivity!