AddField¶
addField:
field: "private int x"
target: "parentClass"
Description¶
Sensei provides the addField
action to add a field to a class.
Configuration options¶
field¶
This is simply the code for the field to add. When the action is executed, Sensei does a quick parse to see if a field with the same name already exists. If that is the case, the action will have no effects.
A trailing semicolon does not have to be included in this code.
position¶
The position
option allows configuring the place where the field 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 field"
actions:
- addField:
field: "private int example;"
position:
after:
field:
name: "logger"
fallback:
top: {}
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 2 sets of defaults, based on the detected type of the field to insert.
If the field to insert has a
static
modifier:
after the last static field
if none, before the first static method
if none, before the first field
if none, before the first method or constructor
if none, after the opening brace of the class
If the field to insert does not have a
static
modifier:
after the last non-static field
if none, before the first constructor or non-static method
if none, after the last static field
if none, after the last static method
if none, after the opening brace of the class