|
28 | 28 | import java.util.List; |
29 | 29 | import java.util.Objects; |
30 | 30 |
|
| 31 | +import org.slf4j.Logger; |
| 32 | +import org.slf4j.LoggerFactory; |
| 33 | + |
31 | 34 | /** Formatter which performs the full formatting. */ |
32 | 35 | public final class Formatter implements Serializable, AutoCloseable { |
33 | 36 | private static final long serialVersionUID = 1L; |
@@ -130,10 +133,22 @@ public String computeLineEndings(String unix, File file) { |
130 | 133 | public String compute(String unix, File file) { |
131 | 134 | ValuePerStep<Throwable> exceptionPerStep = new ValuePerStep<>(this); |
132 | 135 | String result = computeWithLint(unix, file, exceptionPerStep); |
133 | | - LintPolicy.legacyBehavior(this, file, exceptionPerStep); |
| 136 | + legacyErrorBehavior(this, file, exceptionPerStep); |
134 | 137 | return result; |
135 | 138 | } |
136 | 139 |
|
| 140 | + static void legacyErrorBehavior(Formatter formatter, File file, ValuePerStep<Throwable> exceptionPerStep) { |
| 141 | + for (int i = 0; i < formatter.getSteps().size(); ++i) { |
| 142 | + Throwable exception = exceptionPerStep.get(i); |
| 143 | + if (exception != null && exception != LintState.formatStepCausedNoChange()) { |
| 144 | + logger.error("Step '{}' found problem in '{}':\n{}", formatter.getSteps().get(i), file.getName(), exception.getMessage(), exception); |
| 145 | + throw ThrowingEx.asRuntimeRethrowError(exception); |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + private static final Logger logger = LoggerFactory.getLogger(Formatter.class); |
| 151 | + |
137 | 152 | /** |
138 | 153 | * Returns the result of calling all of the FormatterSteps, while also |
139 | 154 | * tracking any exceptions which are thrown. |
|
0 commit comments