Code Generation

Easy creation of new classes, interfaces, packages, and files

screenshot

It is extremely easy to create a new class/interface, package, directory or file directly from the Project View or Commander with the help of IntelliJ IDEA powerful class/file template support. It is possible not only to use the built-in class/file templates, but also to define your own, as well as include custom headers, footers, or other necessary blocks of code/text into the newly created class or file. Using template variables, you will be able to define their actual values for each new class/file.

Quick generation of standard methods

screenshot

IntelliJ IDEA allows you to easily generate getters, setters or both, for any field in your class directly from the editor. The constructor generation feature allows you to specify a set of class fields to be initialized in the generated constructor. Simultaneous generation of the equals() and hashCode() methods will protect you from possible problems when a class instance is added to a collection. Just press Alt + Insert in the editor, and select the method to be generated.

Quick Override/Implement methods

screenshot

Invoking the Override Methods command (Ctrl + O) anywhere in a class brings the list of all methods from the super class (and its bases) that may be overridden by this class. Selecting one or more methods generates overriding methods which you may quickly fill with appropriate code. The Implement Methods command (Ctrl + I) allows users to implement methods defined in any interface and/or abstract super class of the current class.





 

Live Templates

Live template is a predefined code fragment you can invoke by typing an associated abbreviation. Any of the frequently used blocks of code can be turned to a live template, and then used in any suitable code file by typing and easy-to-remember abbreviation and pressing Ctrl+J. Live templates can include parameters that can automatically adjust them to the insertion context.

Generating "delegation" methods

If you need to delegate the execution of particular methods to an instance of a particular class, you no longer have to do it manually. Just call the Code | Delegate Methods... command, specify the target and methods to become delegates, and IntelliJ IDEA will generate all necessary code immediately.

Surrounding of selected code fragment with try/catch, if/else, synchronized and other constructs

You can quickly enclose an expression, a single statement, or an arbitrary block of code with if/else, try/catch or other code constructs. Select the necessary code block and press
Ctrl + Alt + T. IntelliJ IDEA reformats the code, adjusts the selection, and/or repositions the caret as specified by the template that is fully customizable.

Read more about "Surround with"  functionality.

Generating methods, constants, parameters from unknown usages

Create From Usage
"Create method from usage" quick fix

Create From Usage
Generated method


Now it is not obligatory to define a method, constant, or parameter before using it in other parts of code. You just type a new symbol name, and IntelliJ IDEA prompts you with an unobtrusive popup, suggesting you to create a new element.

If you start using a method, you can also provide necessary parameters, IntelliJ IDEA will create it in the corresponding class/interface, with proper method signature, so that you can implement it later.

JavaDoc Stubs Generation Action

Position caret above a method name, type /** and press Enter to let IntelliJ IDEA automatically generate JavaDoc stubs for this method.

to the top