Eclipse for Java Developers. Navigation and editing

Watching with their friends, who recently started to learn programming or switched to Eclipse from another IDE, I often notice that they almost do not use auxiliary tools in the development environment. They either do not know about them at all, or do not understand what practical benefits they can bring.
This article is intended mainly for beginners to work with Eclipse. But in the process of writing the article I learned about a few simple and convenient tools, which two years of active development never used.
In this article we will focus on navigation and editing.
Inside the screenshots.
The main benefit of these instruments is manifested when using hotkeys, I made the following table:
Navigation
![]() ![]() |
![]() |
Description |
Ctrl+F |
⌘+F |
Simple search/replace |
Ctrl+H |
Ctrl+H |
Advanced search/replace |
Ctrl+Shift+R |
⌘+⇧+R |
Open resource |
Ctrl+Shift+T |
⌘+⇧+T |
Open logical structure(Class) |
Ctrl+Shift+G |
⌘+⇧+G |
to Find the occurrences of a variable, method, class |
F4 |
F4 |
Open menu hierarchie |
Ctrl+LeftClick |
⌘+LeftClick |
move to the implementation or definition of a class, function, variable |
F3 |
F3 |
go to definition |
Ctrl+T |
⌘+T |
move to implement |
Ctrl+L |
⌘+L |
go to line number |
Alt+( left right ) |
⌘+( [ ] ) |
Move to previous/next viewing location in the editor |
Ctrl+Q |
Ctrl+Q |
go to last edit |
Ctrl+E |
⌘+E |
Show list of opened editor files |
Ctrl+F6 (Ctrl+Shift+F6) |
⌘+F6 (⌘+⇧+F6) |
Next/previous editor |
Ctrl+O |
⌘+O |
Show the fields and methods of class |
Ctrl+T |
⌘+T |
Display a class hierarchy |
F2 |
F2 |
View javadoc |
Ctrl+Shift+(up | down) |
Ctrl+option+(up | down) |
go to next/previous method |
![]() ![]() |
![]() |
Description |
Ctrl+Space |
Ctrl+Space |
Completion |
Ctrl+1 |
⌘+1 |
the Possible actions |
Ctrl+Shift+O |
⌘+⇧+O |
Organization of the import packages |
Ctrl+Shift+F |
⌘+⇧+F |
autoformatting of code |
Shift+Alt+S |
⇧+option+S |
Menu code generation |
Shift+Alt+T |
⇧+option+T |
Menu refactoring |
Shift+Alt+R |
⇧+option+R |
Rename a variable, method, class |
Shift+Alt+M |
⌘+option+M |
Highlighting of the code in a separate method |
Ctrl+Alt+(up|down) |
⌘+option+(up|down) |
Duplication |
Alt+(up|down) |
option+(up|down) |
Move line |
Ctrl+/ Ctrl+7 |
⌘+/ ⌘+7 |
single line comment |
Ctrl+Shift+/ |
⌘+⇧+/ |
Multiline comment |
Ctrl+D |
⌘+D |
Delete row, or a selection |
Let's review each tool in more detail:
the
Simple search/replace




This tool is present in many text editors. Provides the ability to find the desired occurrence of the text in the current document. And, if necessary, quickly replace with other text.
You can search using regular expressions, which can be used to create a complex search, however, is rarely used for searching on a single class.
If you select text and apply this tool — the selected text is immediately inserted in the search box.
Application:
— Quick jump to the desired part of the code;
— Replacing one word with another. If you need to write two functions that are identical in logical structure, but work with different collections, faster to write one function, to copy and make a replacement.
the
Advanced search/replace




This tool has expands the possibilities, which were discussed earlier.
Main features:
— search across all projects, not just one;
— possible full-text search and typed;
— when a large number of files for full text search takes a lot of time.
Application:
To find the occurrences of the text or in all projects.
the
edit resource




Application:
Rapid discovery of the data file or a class.
the
Open logical structure(Class)




You can enter only capital letters of the class. For example, to find class AbstractDogFactory enough to enter ADF.
You can also use *.
Application:
Quick opening the file with the class. Other files are ignored.
the
to Find the occurrences of a variable, method, class




For the selected item is use for all projects.
Application:
Much faster than a conventional search. Just select the item to apply the tool and on the screen the list of places where this element is used.
the
Open menu hierarchie




the
to Proceed to the implementation or definition of a class, function, variable



While holding the Ctrl key left click the mouse on the element produces goes to its definition or implementation.
Application:
— easy to detect where the declared variable.
— jump to the implementation class or method.
the
go to definition



Go to definition of item on which the cursor is positioned.
the
to Go to the implementation
The transition to the implementation of the element on which the cursor is positioned.
the
jump to line number



Go to the line with the given number.
Application:
At interaction programmers to specify where in the code — call file and line.
the
Move to previous/next viewing location in the editor



Returns to the previous/next place where you viewed the source code.
Application:
With the deepening of the implementation of one function or class, and return back.
the
go to last edit location



Returns to the previous place where the edited source code.
Application:
A quick return to the work place.
the
Show list of opened editor files




Application:
Quick switch between files.
the
Next/previous editor




These shortcuts are not always convenient, so it makes sense to reassign them for example on Ctrl+Tab / Ctrl+Shift+Tab
To quickly switch suitable: Ctrl+Page Up/Page Down — Linux/Windows. Ctrl+Fn+Up/Down — OS X
the
Show fields and class methods




Pressing hotkeys in the list add methods of parent class
Application:
— rapid assessment of the class structure;
— quick navigation to the desired method.
the
Show class hierarchy




Pressing: expands the hierarchy in the opposite direction and shows the implemented interfaces.
Application:
Jump to the parent class.
the
View javadoc




the
jump to next/previous method



the
Autocompletion



The tool allows not to write the full names of functions, classes and variables, and only part of them, the programmer chooses the completion of the proposed.
However, many do not know some of the features of auto-completion in eclipse:
— if you select autopanne press Ctrl+Enter instead of Enter, the word to the right of the cursor will be replaced with avtomobilnoe.
— auto-completion works for the new variables:
if you have written
the
Point2D
and call completion, you will receive
the
Point2D point2d
— in eclipse, there are templates to quickly write:
the
syso
get
the
System.out.println();
Most popular templates:
— syso
— for
— while
— switch
— catch
View all templates and add your own in the settings in the tab "Templates".
the
Possible actions



In my opinion the most useful tool in the process of writing code.
On the basis of what line the cursor is positioned and whether the text is selected, eclipse suggests possible changes and additions.
Examples of tools:
— create zagrosek to implement the interface methods or abstract class.
the
public class Run implements Runnable {
}
steps on line name of class
the
public class Run implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
}
}
— create new methods
If the current part of the code needed for a method, and it does not exist.
the
boolean success = isSuccess();
creates method
the
private boolean isSuccess() {
// TODO Auto-generated method stub
return false;
}
— declaring variables
If you want to use the result of function
the
isSuccess();
declares a variable with the correct name
the
boolean success = isSuccess();
— allocation of constants
If the code inside is the figure or the text that you want to make a constant, vedelem it and apply the tool:
the
String success = "success";
the
private static final String SUCCESS = "success";
the
Organization of the import packages



Remove imports of unused packages and add missing.
the
autoformatting of code



Bringing the code in readable form:
— making the right tab.
— adds/removes whitespace;
— removes excess indentation;
— limits the length of the string — wraps text to the next different row.
Works for just the selected piece of code or an entire class.
Application:
Sometimes faster to write poorly formatted function and press the hotkeys than to write beautifully.
the
Menu generation code



Auto — generate get and set methods.
placeholder for overridden and implemented functions;
— the hashcode and equals;
— toString;
constructor.
Application:
Do not waste time on standard methods if their implementation is not specific.
the
Menu refactoring




the
Renaming a variable, method, class



Rename the highlighted method. Thanks to the refactoring method will be renamed throughout the project.
the
reserving a portion of the code in a separate method




The allocation of the selected part to a new method. All possible duplicates of this pieces of code in this class is automatically replaced with the call to the new method.
the
Duplicate row



Application:
If the next line would be similar to current — faster to copy the current one and modify it than to write again.
the
Transport



Application:
Quick transfer of the code, without having to copy and paste.
the
single line comment



the
Multiline comment



When using the commented code, comments are removed.
the
to Delete a line or selection



UPDATE: Fixed and completed the article.
Many thanks arturphoenix,AgentSIB,mishadoff,mdcool,Lihonosov,Aivean,anoshenko,lany,abusalimov,bimeg, netslow,majus for comments and additions.
Some instruments are indirectly related to navigation and editing, so I did not include them in the article, but I will try to include them in the next.
Комментарии
Отправить комментарий