Eclipse cheat sheet
Par Florence CHABANOIS le 13 février 2009 - Eclipse - Lien permanent
Eclipse is THE best development IDE, with an incredible amout of facilities and plugins to make the developer's life easier. These are my favorites.
Configuration
In the menu Windows>Preferences, search for
label decorations
: some labels such as the project's maven version, the branch of the project can be very usefulvalidation
: HTML, XML and JSP files are very, very, very long to validate and the errors raised are not always relevant. Therefore I generally check the "Suspend all validators" option.save actions
: enable some operations to be always made when a file is saved. For example, organizing imports. Available since Eclipse 3.4 only.import
: select the one in Content Assist > Favorites. Eclipse can't automatically import the static imports with CTRL+SHIFT+O if they aren't declared here. Add new Types with theses values :
import static org.junit.Assert // for assertThat import static org.hamcrest.CoreMatchers // for is, equalTo, notNull, etc.
You can have more information about matchers on xebia's site : http://blog.xebia.fr/2008/04/02/simplifier-les-assertions-junit-et-ameliorer-vos-tests/
About Java > Editor
Content Assist: whenCompletion overwrites
is checked, the former choice is overwrited when a suggestion of the autocompletion (got with CTRL+SPACE) is selected.Mark occurenceshighlights all the same occurences in the same file.Templates: I do feel kind of lost when I am working on another computer and don't have them. I have one for log4J logger, for mocking classes, to generate comments... all prefixed with "my_".- in
Typing, whensemicolons
is checked, they are automatically inserted at the correct position (in other words, at the end of the line). No need to type end of line before typing ";".
About General > Editors > Text Editor
Print margin column: draw a line in the Xe characterShow line numbers: to display the line numbers in the left of the file
Shortcuts
From the most to the least used :
CTRL+leftClick: to go to the declaration of the item selected (instance, class...).F3would do the same.CTRL+SPACE: autocompletion, the only must !CTRL+SHIFT+T: open a classCTRL+SHIFT+R: open a resourceCTRL+Ton a method or a class X : displays the implementations of X and its childrenCTRL+SHIFT+/: put or remove comments on the selectionCTRL+D: delete the current lineCTRL+ALT+(up|down): copy the selected block up | down. Preserves whatever has been copied with CTRL+C before!ALT+(up|down): move the block up | downSHIFT+ALT+X, then T: run the tests of the current test classCTRL+O: to display the methods of the class and go to one of themCTRL+O(twice): to display the methods of the class and the super class and go thereCTRL+1: display the quick fixALT+SHIFT+A then SHIFT+up|down: to edit a block vertically (available since Eclipse 3.5)CTRL+L: to go to a specific line numberCTRL+SHIFT+F: autoformats a selection of code or the whole class if nothing is selectedCTRL+K: to go to the next occurence of the selectionCTRL+SHIFT+K: to go to the previous occurence of the selectionCTRL+H: search functionsSHIFT+ALT+S, then V: to oVerride a methodSHIFT+ALT+S, then R: to geneRate getters and settersCTRL+E: search in the open tab namesCTRL+J: incremental searchCTRL+M: make the window widerCTRL+SHIFT+(up|down): go to the next/previous methodCTRL+SHIFT+O: organize imports automatically. I don't use it anymore because these action is automatically done each time I save a file (thanks to the save actions module).
For refactoring :
ALT+SHIFT+R: rename a class/objectALT+SHIFT+L: extract local variableALT+SHIFT+M: extract method
Plugins
- Maven to have dependencies management
- Spring IDE to have autocompletion and bean references
- Subclipse to be able to synchronize versions easily.