From e220e5166d7adbdc968db8a322a00a1d55f33eae Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sat, 26 Jun 2021 09:04:08 +0700 Subject: [PATCH] Minor code clean-ups Add a bit more type safety and accept some minor refactorings suggested by the IDE. Signed-off-by: Alexander Kriegisch --- .../main/java/org/aspectj/tools/ajc/Main.java | 38 ++++++++++--------- .../test/java/org/aspectj/tools/ajc/Ajc.java | 5 ++- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/tools/ajc/Main.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/tools/ajc/Main.java index ffeadba95..93e777481 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/tools/ajc/Main.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/tools/ajc/Main.java @@ -98,7 +98,10 @@ public class Main { * @param usages the List sink, if any, for String usage messages * @return number of messages reported with level ERROR or above */ - public static int bareMain(String[] args, boolean useSystemExit, List fails, List errors, List warnings, List infos, List usages) { + public static int bareMain( + String[] args, boolean useSystemExit, + List fails, List errors, List warnings, List infos, List usages + ) { Main main = new Main(); MessageHandler holder = new MessageHandler(); main.setHolder(holder); @@ -115,7 +118,7 @@ public class Main { } /** Read messages of a given kind into a List as String */ - private static void readMessages(IMessageHolder holder, IMessage.Kind kind, boolean orGreater, List sink) { + private static void readMessages(IMessageHolder holder, IMessage.Kind kind, boolean orGreater, List sink) { if ((null == sink) || (null == holder)) { return; } @@ -157,7 +160,7 @@ public class Main { if (0 < sink.length()) { sink.append(", "); } - sink.append(numItems + " "); + sink.append(numItems).append(" "); if (!LangUtil.isEmpty(label)) { sink.append(label); } @@ -308,17 +311,16 @@ public class Main { /** * Run without using System.exit(..), putting all messages in holder: *
    - *
  • ERROR: compiler error
  • - *
  • WARNING: compiler warning
  • - *
  • FAIL: command error (bad arguments, exception thrown)
  • + *
  • ERROR: compiler error
  • + *
  • WARNING: compiler warning
  • + *
  • FAIL: command error (bad arguments, exception thrown)
  • *
* This handles incremental behavior: *
    - *
  • If args include "-incremental", repeat for every input char until 'q' is entered. - *
  • - *
  • If args include "-incrementalTagFile {file}", repeat every time we detect that {file} modification time has changed.
  • - *
  • Either way, list files recompiled each time if args includes "-verbose".
  • - *
  • Exit when the commmand/compiler throws any Throwable.
  • + *
  • If args include "-incremental", repeat for every input char until 'q' is entered. + *
  • If args include "-incrementalTagFile {file}", repeat every time we detect that {file} modification time has changed.
  • + *
  • Either way, list files recompiled each time if args includes "-verbose".
  • + *
  • Exit when the commmand/compiler throws any Throwable.
  • *
* When complete, this contains all the messages of the final run of the command and/or any FAIL messages produced in running * the command, including any Throwable thrown by the command itself. @@ -341,7 +343,7 @@ public class Main { fail(holder, "Couldn't open log file: " + logFileName, e); } Date now = new Date(); - logStream.println(now.toString()); + logStream.println(now); if (flagInArgs("-verbose", args)) { ourHandler.setInterceptor(new LogModeMessagePrinter(true, logStream)); } else { @@ -409,7 +411,6 @@ public class Main { } finally { if (logStream != null) { logStream.close(); - logStream = null; } if (fos != null) { try { @@ -417,7 +418,6 @@ public class Main { } catch (IOException e) { fail(holder, "unexpected exception", e); } - fos = null; } command = null; } @@ -503,7 +503,7 @@ public class Main { if (0 < sb.length()) { PrintStream out = (0 < (lastErrors + lastFails) ? System.err : System.out); out.println(""); // XXX "wrote class file" messages no eol? - out.println(sb.toString()); + out.println(sb); } } return result; @@ -576,7 +576,7 @@ public class Main { } int col = loc.getColumn(); if (0 < col) { - sb.append(":" + col); + sb.append(":").append(col); } sb.append(" "); } @@ -697,8 +697,10 @@ public class Main { public static long DEFAULT_DELAY = 1000 * 5; /** @see init(String[]) */ - private static String[][] OPTIONS = new String[][] { new String[] { INCREMENTAL_OPTION }, - new String[] { TAG_FILE_OPTION, null } }; + private static final String[][] OPTIONS = new String[][] { + new String[] { INCREMENTAL_OPTION }, + new String[] { TAG_FILE_OPTION, null } + }; /** true between init(String[]) and doRepeatCommand() that returns false */ private boolean running; diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java index 4cfc2fa47..ee49dc10a 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java @@ -311,9 +311,10 @@ public class Ajc { if ((args[i].equals("-aspectpath") || args[i].equals("-inpath") || args[i].equals("-injars") || args[i].equals("-outjar") || args[i].equals("-classpath") || args[i].equals("-sourceroots") || args[i].equals("-Xlintfile") || args[i].equals("-extdirs") || args[i].equals("-d")) - && args.length > (i + 1)) { + && args.length > (i + 1)) + { newArgs[i] = args[i]; - StringBuffer buff = new StringBuffer(); + StringBuilder buff = new StringBuilder(); boolean copyThisTime = doCopy; if (args[i].equals("-d")) { copyThisTime = false; -- 2.39.5