Wednesday, October 04, 2006

Eclipse quick-fixes and such

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+1some 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 importsCS+Oremove unused or erroneous imports
Implement missing methodswhen 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 variablecreate a new variable (usually called "string") and assign the new object.
Assign statement to new fieldcreate a new field (usually called "string")
Refactoring AS+TChange various "bad smells" in Software
RenameAS+Rrename a variable, class, method across all usages; also for package names
MoveAS+Vmove 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 MethodAS+Mmake 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 VariableAS+Lextract a local variable from the currently selected expression. Other uses of the expression in the same context are also replaced.
Inline VariableAS+IThe contrary to Extract local variable. The uses of a variable are inlined.
Extract ConstantExtracts a constant (final static) from the currently selected value, usually a "String"
Introduce ParameterIntroduces another parameter the current method, and all calls of it.
Source AS+SSource helpers
Toggle CommentCS+7Comment (out) the current lines
Override/Implement Methods
Generate Getters and Setters
Generate Constructor using Fields
Generate Constructors from Superclass
Surround withCS+Zfrom 3.2rc6(?) onwards, was part of "Source" before
Surround with try/catch

P

No comments: