Extract method errors
When you attempt to extract a method, you may get one
or more of the following common errors:
-
Selected block references a local type declared outside the selection
A local type declaration is not part of the selection but is referenced
by one of the statements selected for extraction. Either extend the selection
that it includes the local type declaration or reduce the selection that
no reference to the local type declaration is selected.
-
A local type declared in the selected block is referenced outside the
selection
The selection covers a local type declaration but the type is also
referenced outside the selected statements. Either extend the selection
that is includes all references to the local type or reduce the selection
that the local type declaration isn't selected.
-
Ambiguous return value: selected block contains more than one assignment
to local variable
More than one assignment to a local variable was found inside the selected
block. Either reduce the selection that only one assignment is selected
or extend the selection that at least all reference except of one to the
local variables are covered by the selection too.
-
Ambiguous return value: expression access to local and return statement
selected
The selected statement generates more than one return value. This is
for example the case if an expression is selected and an expression's argument
is modified as well. To remedy this problem extend the selection to cover
the read access of the modified argument as well.
-
Selection contains a break statement but the corresponding break target
isn't selected
To remedy the problem either extend the selection to include the break
/ continue target or reduce the selection that the break / continue statement
isn't covered by the selection.
-
Selection contains a continue statement but the corresponding continue
target isn't selected
To remedy the problem either extend the selection to include the break
/ continue target or reduce the selection that the break / continue statement
isn't covered by the selection.
-
Cannot extract new method from selection. Only statements from the
body of a top level method can be extracted
This is a generic error message shown whenever the selection does not
spawn a valid set of statements. Typical scenarios where this error message
is shown are:
-
a whole method is selected not only parts of a method body
-
the selection only covers parts of a statement. Statements in the extract
method sense are separated by semicolons. Below a few examples where the
selection doesn't mark a set of statements and therefore can't be extracted:
-
foo().bar().baz();
to remedy the problem select whole message send chain
-
int i= foo();
extend the selection to cover the whole declaration
The users can extend the selection to a valid range using the Expand
Selection to in the Edit menu.
-
Selection starts inside a comment
Parts of a comment cannot be extracted. Either extend the selection
that it covers the whole comment or reduce the selection that the comment
isn't covered at all.
-
Selection ends inside a comment
Parts of a comment can't be extracted. Either extend the selection
that it covers the whole comment or reduce the selection that the comment
isn't covered at all.
-
Cannot extract selection that ends in the middle of a statement
Adjust selection so that it fully covers a set of statements. Statements
in the extract method sense are separated by semicolons.
Java development tools (JDT)
Refactoring support
Extracting a method
Using
Structured Selection
Source menu
Refactor Menu