Eclipse - notsojug/jug-material GitHub Wiki
This section will explore tips an tricks regarding the ever-famous Java IDE: Eclipse!
Eclipse lets you complete what you thought about with a Ctrl-space
and some characters.
This image shows you how the shortcut helped turning so
into some
by triggering the auto-complete. After we pressed Enter, the first suggestion is entered. You can also choose the suggestion using the arrow keys.
Auto complete also triggers itself after you press .
near an object, exploring the method you can call on that object. That's why after getting some.
the user does not need to press Ctrl-space
to trigger auto-complete again.
Where: Everywhere
Shortcut: Ctrl-Shift-L
If you don't know the shortcuts, learn this! Then type some characters to search for specific shortcuts
Where: On errors and warnings, with cursor in the affected line or variable.
Shortcut: Ctrl-1
Fixes common errors by selecting the suggested entry and pressing <Enter>
Where: On lines, variables, method calls, selected code
Shortcut: Ctrl-2 (wait) {F,L,M,R}
Example:
Type new Thing()
, then Ctrl-2 + L
, the, at the cursor, type myThing
. The result should be Thing myThing = new Thing()
Animation:
Where: Almost everywhere, with cursor on the item
Shortcut: Alt-shift-R
Where: In a (test) class
Shortcut: test<ctrl-space><enter>
Where: In test classes
Shortcut: Alt-shift-X T
Running tests should not be painful, this shortcut runs the current test class. If your cursor is over a method name, it runs just the current test method.
Where: In test classes
Shortcut: Alt-shift-D T
Same as above, but in debug mode.
Where: In classes with main method
Shortcut: Alt-shift-X J
Running classes with a main
method is of course easy with this shortcut.
Where: In classes with main method
Shortcut: Alt-shift-D J
Same as above, but in debug mode.
Where: In test classes
Shortcut: Alt-shift-E T
If you're into test coverage, this shortcut runs the coverage test for the current test class or method.
Tip: you can see what path are covered by subsequently running single test methods and seeing how coverage changes in the tested classes.
Where: Everywhere
Shortcut: Ctrl-shift-T
This opens a dialog to open types and classes. This dialog has no fuzzy search, but accepts *
as a wildcard.
Where: Everywhere
Shortcut: Ctrl-shift-R
Like the above, but for all file types.
Where: Java classes
Shortcut: Ctrl-shift-O
This command will reorder your import, remove the unused imports, and turn the whole-package imports into class imports.
Where: Java classes
Shortcut: Ctrl-O
Where: All known file types
Shortcut: Ctrl-shift-F
This shortcut indents the current file. If you use Java and you have configured the checkstyle plugin, this command will oblige the rules of the plugin.
Where: Variables, methods, method's calls, classes
Shortcut: Alt-Shift-T
This menu offer a way to quickly do some refactoring action like renaming, moving methods and classes, etc.
Where: Classes, mainly
Shortcut: Alt-Shift-S
This menu lets you use the IDE to do some routine source action, like generating getters and setters from fields, using a delegate class, etc...
Where: Selecting objects or return values
Shortcut: Alt-Shift-L
This is the same as Ctrl-2 L
, but in a single shortcut.
Where: Every text file
Shortcut: Ctrl-J <start typing few characters>
This works faster than the usual search dialog: it is a search-as-you-type facility that helps you find the right spot.
If you need to jump to the next location, just press again Ctrl-J
.
Where: Every code file
Shortcut Ctrl-Shift-B
Toggles a breakpoint for the current line
Where: During debug sessions: in code and in Display dialog
Shortcut: Ctrl-shift-I
This shortcut helps you inspect the value of variables or expressions during debug sessions
Where: During debug sessions: in code and in display dialog
Shortcut: Ctrl-U
Just select some piece code from the running code, or just write something in the display dialog, hit the shortcut, and execute the selected lines!
Where: During debug session
Shortcut: Alt-Shift-F
You can force the currently debugged method to return with this shortcuts. It works on void method simply by pressing the shortcut. It also works on methods that return objects, and you can also provide a different object to be returned: just create that object in the display dialog, select it, and press the shortcut!
Where: Everywhere
Shortcut: Ctrl-3
You can jump to a special searchbox from everywhere by pressing this shortcut. The search box lets you navigate between dialogs, files, and perspectives, just type some letters.
Where: In text files
Shortcut: Ctrl-L
This opens a dialog window to let you jump to a given code line.
Where: Selecting lines
Shortcut: Alt-shift-Z
Provides a menu to surround portions of code with common code snippets, such as try-catches, or loops.
Where: Inline the method in the calling site(s)
Shortcut: Alt-shift-I
You can inline a called method with a shortcut, either from the call site(s) or from the method itself. If possible, you can also choose to remove the original method after the refactoring.
Where: Statically import a static method or a constant, if possible
Shortcut: Ctrl-shift-M
The IDE knows that you can statically import classes' methods. A shortcut helps you switch from class import to static (method) import.
E.g. when using EasyMock, you can stumble upon the occasional EasyMock.createMock(...)
, if you hit the shortcut with the cursor over the createMock
, the IDE enables the static import for the method, allowing you to just use createMock(...)
.
Where: In code
Shortcut: Alt-{left, right arrow}
If you edit multiple files or you are just exploring code, you will need to go back-and-forth between them. These shortcuts will help you avoid using the mouse to navigate the code.
Where: from code
Shortcut: F4
Select a type and press the shortcut to see its hierarchy.
Where: From places where a method is used
Shortcut: F3
It teleports you to the declaration of a method.
This is not bounded to a shortcut by default, but you can bind it to a shortcut of your choice.
This is useful in java 8, where some methods are defined in an interface, rather than in a class.
Where: Over things
Shortcut: F2
Where: Over method call
Shortcut: Ctrl-alt-H
Where: Over strings (not only literal strings)
Shortcut: Ctrl-alt-G
Where: Over lines or selected lines
Shortcut: Ctrl-D
JBoss studio provides application server integration in the IDE, CDI support (producers discovery, scoped beans, beans.xml parsing and modeling, suggestion) and more.
It really makes your Java EE development easier.
Code recommenders provide fuzzy method name search in auto complete mode.
For example, if you have a method named getVar()
, you would get the suggestion only after typing getv
, while with recommenders you can just type var
and only getVar
and setVar
will come.
If you turn the option on, you also get automatic code snippet suggestion and most frequently used method suggestion.
This plugin provides git support in Eclipse.
During debug session, while pausing, the Display dialog gives you a sort of scratchpad within the current context. You can reference variables, classes, and even execute methods. You can even force a return on the current method, if you wish.
This dialog shows a list the TODOs and other configurable comments along your code. You can use it to see where you left your work on previous sessions.
In this list you can put your most favorite classes. This will come very useful to avoid clumsy code writing in case of static import.
For example, if you frequently write tests with EasyMock, you stumble upon the class EasyMock.createMock()
or EasyMock.expect()
, which does not work unless you pre-import all the class' static methods.
With favorite classes, you just type createMock
and a Ctrl-space
will import just the required method statically for you.
Pro tip: use it for java 8 Collectors
class, for assertj's Assertions
, EasyMock
, javaslang.API
, and javaslang.Predicates
for maximum productivity boost.
You can create context-sensitive snippets and have the IDE type them for you.
E.g. Find yourself writing the TODOs in a particular way? Save it as a template! All your classes have a special method you always write? Give it a name, and the next time you just have to write the few letters to trigger the template, and a Ctrl-space
will generate the code for you.