There are many refactoring and fixing tools in the eclipse environment. It really helps to have a look at them once, and find out when and how to best use them.
The most important:
Strg+1 Quickfix - shows a list of solutions when a warning (yellow line) or an error (red line) is selected.
This also works when no error/warning is shown, but experience-based process support shows that, in most cases, the developer wants a certain task.
Also: Press Strg+Space to complete any "name" - variables, functions, types, imports etc. Often, this also has some nice side effects - such as automatically importing a class when the name is completed this way.
Others functions that should be looked at:
(C-Control, S-Shift, A-Alt: CS+T -> "Ctrl+Shift T")
Quick fix | C+1 | some of the possibilities offered |
|
varname = value; // where "varname" does exist |
Create field "varname" | create varname as a field of the current class |
Create local variable "varname" | create varname as a local variable |
|
''varname.methodname(param); // where methodname does not exist |
Create Method "methodname" (in ...) | create a method with the name and parameters in the appropriate class |
Add Parameter in methodname (and others) | Adjust the the formal parameters of methodname to conform to the given actual parameters. Includes removing, adding parameters, or creating a new method with the given ones. |
|
Class errors: |
Organize imports | CS+O | remove unused or erroneous imports |
Implement missing methods | when a class does not yet implement methods required by an interface or an abstract base class |
|
new String("Hallo"); // no variable assignment |
Assign statement to new local variable | create a new variable (usually called "string") and assign the new object. |
Assign statement to new field | create a new field (usually called "string") |
Refactoring | AS+T | Change various "bad smells" in Software |
Rename | AS+R | rename a variable, class, method across all usages; also for package names |
Move | AS+V | move a method from one class to another, adjusting the calls (esp. for moving into member field classes, and for static methods). A delegate can be left. |
Extract Method | AS+M | make a method of the currently selected code fragment. Parameters and possibly return value are automatically determined; often other places of the same code fragment are also replaced. |
Extract Local Variable | AS+L | extract a local variable from the currently selected expression. Other uses of the expression in the same context are also replaced. |
Inline Variable | AS+I | The contrary to Extract local variable. The uses of a variable are inlined. |
Extract Constant | Extracts a constant (final static) from the currently selected value, usually a "String" |
Introduce Parameter | Introduces another parameter the current method, and all calls of it. |
Source | AS+S | Source helpers |
Toggle Comment | CS+7 | Comment (out) the current lines |
Override/Implement Methods |
|
Generate Getters and Setters |
|
Generate Constructor using Fields |
|
Generate Constructors from Superclass |
|
Surround with | CS+Z | from 3.2rc6(?) onwards, was part of "Source" before |
Surround with try/catch |
|
P
No comments:
Post a Comment