From: Alexander Kriegisch Date: Tue, 24 Jan 2023 16:17:41 +0000 (+0100) Subject: Further improve indentation of compilation results on the console X-Git-Tag: V1_9_20~43 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fheads%2Fgh-217;p=aspectj.git Further improve indentation of compilation results on the console In CompilationResult.toString, no longer indent like this: [warning 1] warning at after() : execution(FooBar Blah.*()) { ^^^^^^ xxx FooBar [Xlint:invalidAbsoluteTypeName] Instead, always just indent by 2 spaces, saving screen real estate: [warning 1] warning at after() : execution(FooBar Blah.*()) { ^^^^^^ xxx FooBar [Xlint:invalidAbsoluteTypeName] Also further streamline/simplify the code a bit. Signed-off-by: Alexander Kriegisch --- diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/CompilationResult.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/CompilationResult.java index c0dc6a95b..cae187195 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/CompilationResult.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/CompilationResult.java @@ -153,13 +153,13 @@ public class CompilationResult { */ @Override public String toString() { - StringBuilder buff = new StringBuilder(); - buff.append("AspectJ Compilation Result:\n"); + StringBuilder buffer = new StringBuilder(); + buffer.append("AspectJ Compilation Result:\n"); int totalMessages = infoMessages.size() + warningMessages.size() + errorMessages.size() + failMessages.size() + weaveMessages.size(); - buff.append(totalMessages).append(" messages"); + buffer.append(totalMessages).append(" messages"); if (totalMessages > 0) { - buff + buffer .append(" (") .append(infoMessages.size()).append(" info, ") .append(warningMessages.size()).append(" warning, ") @@ -168,40 +168,28 @@ public class CompilationResult { .append(weaveMessages.size()).append(" weaveInfo") .append(")"); } - buff.append("\n"); + buffer.append("\n"); - int msgNo = 1; - for (IMessage failMessage : failMessages) - indentWithPrefix(buff, "[fail " + msgNo++ + "] ", failMessage.toString()); - msgNo = 1; - for (IMessage errorMessage : errorMessages) - indentWithPrefix(buff, "[error " + msgNo++ + "] ", errorMessage.toString()); - msgNo = 1; - for (IMessage warningMessage : warningMessages) - indentWithPrefix(buff, "[warning " + msgNo++ + "] ", warningMessage.toString()); - msgNo = 1; - for (IMessage infoMessage : infoMessages) - indentWithPrefix(buff, "[info " + msgNo++ + "] ", infoMessage.toString()); - msgNo = 1; - for (IMessage weaveMessage : weaveMessages) - indentWithPrefix(buff, "[weaveInfo " + msgNo++ + "] ", weaveMessage.toString()); + printMessagesToBuffer(buffer, "fail", failMessages); + printMessagesToBuffer(buffer, "error", errorMessages); + printMessagesToBuffer(buffer, "warning", warningMessages); + printMessagesToBuffer(buffer, "info", infoMessages); + printMessagesToBuffer(buffer, "weaveInfo", weaveMessages); - buff.append("\nCommand: 'ajc"); + buffer.append("\nCommand: 'ajc"); for (String arg : args) - buff.append(' ').append(arg); - buff.append("'\n"); + buffer.append(' ').append(arg); + buffer.append("'\n"); - return buff.toString(); + return buffer.toString(); } - private void indentWithPrefix(StringBuilder buffer, String prefix, String message) { - String[] lines = message.split("\n|\r\n|\r"); - boolean firstLine = true; - for (String line : lines) { - buffer.append(prefix); - if (firstLine) - prefix = prefix.replaceAll(".", " "); - buffer.append(line).append('\n'); - } + private void printMessagesToBuffer(StringBuilder buffer, String messageType, Iterable messages) { + int msgNo = 1; + for (IMessage message : messages) + buffer + .append("[").append(messageType).append(" ").append(msgNo++).append("] ") + .append(message.toString().replaceAll("\r\n|\n|\r", "\n ")) + .append('\n'); } }