Automated and Manual Refactorings

In our case, the answer local variable doesn’t clarify the code, and it’s used only once. Inline (remove) the variable by replacing its use with the answerMatching(criterion) expression:

for​ (Criterion criterion: criteria) {
boolean​ match = criterion.matches(answerMatching(criterion));
if​ (!match && criterion.getWeight() == Weight.MustMatch) {
kill = true;
if​ (match) {
score += criterion.getWeight().getValue();
anyMatches |= match;

You could manually inline answer, but your IDE most likely automates the inline refactoring. In Eclipse, select Refactor Inline… from the main menu to inline.

The very existence of automated IDE automated ...

Get Pragmatic Unit Testing in Java 8 with JUnit now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.