The Java editor is capable of generating often used constructs for you automatically. Press Alt+Insert to invoke the code generation menu and pick what you want to generate
To add import statements: Use error hints: Click on the error mark with the light bulb or press Alt+Enter. It will offer you a list of possible classes to import. Pick the proper hint and you are done
Use the import class dialog: Put the caret into the name of an unimported class and press Alt+Shift+I. A list of possible classes to import will appear. Use the smart fix import: Press Ctrl+Shift+I. You will get a dialog that lists all unresolved identifiers in the source. If there is more than one option for resolving the identifier you may choose using the combo box. Classes shown in gray do not fit for some reason.
Method exit points: Putting the caret on the return type of a method definition will highlight all places where the method can exit
Exception throwing points: Putting the caret on an exception in a method declaration throws clause will highlight all the places where that exception can be thrown
If you want to surround a piece of text with a template, just select the text and invoke hints with Alt+Enter
Sometimes it is useful to select text based on Java syntax. To do this, press Alt+Shift+PERIOD (Ctrl-Shift-PERIOD on a Mac) to expand the selection and Alt+Shift+COMMA (Ctrl-Shift-COMMA on a Mac) to shrink the selection based on the structure of your Java source code
How to use Live Templates
![](http://2.bp.blogspot.com/_aAoblje1r7Q/SKvc0Xa38sI/AAAAAAAAABw/mg75-XnvXQQ/s400/untitled3.bmp)
Creating a new template You can define new templates: go to Menu->Tools->Options, then choose the Editor category and the Code Templates tab. You may want to look at the existing Java templates and try to create your own
Javadoc popup window Put the caret on a symbol of choice and press Ctrl+Shift+Space. Javadoc view window Go to Window->Javadoc View in the main menu. This will open a separate window which always shows Javadoc for the element under the caret
Opening a type in the editor If you know the name of the type (class, interface, annotation or enum) you want to open, press Alt+Shift+O and type the name into the dialog. Notice that you can use prefix, camel case and wild cards
Implements/Overrides annotation Methods which implement or override another method are marked with a glyph in the editor gutter. Clicking the icon will take you to the overridden method or to the method from the interface. Pressing Ctrl+B does the same.
Comments