AddMethod¶
addMethod:
method: "void setField();"
target: "parentClass"
Description¶
Sensei provides the addMethod
action to add a method to a class.
Configuration options¶
position¶
The position
option allows configuring the place where the method will be inserted. This can be
top
for at the top of the class, or before
or after
to place it before or after an element
that matches a given specification, respectively.
When using before
or after
, the fallback
property can be supplied to configure a fallback
behavior that will be used when the given specification does not match. Each fallback can have another
fallback.
availableFixes:
- name: "add method"
actions:
- addMethod:
method: "void setField();"
position:
after:
method:
name:
matches: "set.*"
fallback:
after:
field: {}
fallback:
top: {}
target: "parentClass"
When the position
option is not specified, or none of the given positions and fallbacks are
available, the most appropriate location will automatically be determined by sets of predefined default
positions as listed below.
Defaults¶
There are 3 sets of defaults, based on the detected type of the method to insert.
If the method to insert has a
static
modifier:
after the last static method
if none, before the first field
if none, before the first constructor or non-static method
if none, after the opening brace of the class
If the method to insert is a constructor:
after the last constructor
if none, before the first non-static method
if none, after the last field
if none, after the last static method
if none, after the opening brace of the class
If the method to insert is not a constructor and not
static
:
after the last non-static method or constructor
if none, after the last field
if none, after the last static method
if none, after the opening brace of the class