Similarly to #325, but for writes, when we have for example
if (a) {
array[0] = some complex expression;
} else if (b) {
array[0] = some other complex expression;
} else if (c) {
array[0] = some other complex expression;
} else {
array[0] = some other complex expression;
}
It makes sense to introduce a variable that is assigned to in the conditions, so that when one changes the target (from array[0] to for example a method call), one must not change many lines.
this should trigger if there are more than 3 assignments
for ifs and switch
with array writes
with method calls (only one argument?), what about side effects? Like list.add
not variable assignments
Motivation:
int index = cell.getMemoryPosition();
if (isNextAiCommand(nextAi, index)) {
memoryArray[index] = nextAiSymbol;
} else if (isNextCommandOfAnyAi(nextAis, index)) {
memoryArray[index] = otherAisSymbol;
} else if (isAiBomb(cell)) {
memoryArray[index] = cell.getCommand().getOwnerAi().orElseThrow().getAiBombSymbol();
} else if (isAiCommandFromAi(cell)) {
memoryArray[index] = cell.getCommand().getOwnerAi().orElseThrow().getAiSymbol();
} else {
memoryArray[index] = unchangedSymbol;
}
Description
Similarly to #325, but for writes, when we have for example
It makes sense to introduce a variable that is assigned to in the conditions, so that when one changes the target (from array[0] to for example a method call), one must not change many lines.
Motivation: