diff --git a/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java b/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java index e6ddbc51ea32..3bcff72601a7 100644 --- a/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java +++ b/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java @@ -48,22 +48,17 @@ public void printSummary(Context ctx) { public void doReport(Diagnostic dia, Context ctx) { Severity severity = severityOf(dia.level()); Position position = positionOf(dia.pos().nonInlined()); - - StringBuilder rendered = new StringBuilder(); - rendered.append(messageAndPos(dia, ctx)); Message message = dia.msg(); - StringBuilder messageBuilder = new StringBuilder(); - messageBuilder.append(message.message()); + String text; + if (Diagnostic.shouldExplain(dia, ctx) && !message.explanation().isEmpty()) + text = message.message() + System.lineSeparator() + explanation(message, ctx); + else + text = message.message(); + String rendered = messageAndPos(dia, ctx); String diagnosticCode = String.valueOf(message.errorId().errorNumber()); - boolean shouldExplain = Diagnostic.shouldExplain(dia, ctx); List actions = CollectionConverters.asJava(message.actions(ctx)); - if (shouldExplain && !message.explanation().isEmpty()) { - rendered.append(explanation(message, ctx)); - messageBuilder.append(System.lineSeparator()).append(explanation(message, ctx)); - } - - delegate.log(new Problem(position, messageBuilder.toString(), severity, rendered.toString(), diagnosticCode, actions, - lookupVirtualFileId)); + Problem problem = new Problem(position, text, severity, rendered, diagnosticCode, actions, lookupVirtualFileId); + delegate.log(problem); } public void reportBasicWarning(String message) {