Klasse Main

java.lang.Object
org.aspectj.tools.ajc.Main
Bekannte direkte Unterklassen:
CompilerWrapper

public class Main extends Object
Programmatic and command-line interface to AspectJ compiler. The compiler is an ICommand obtained by reflection. Not thread-safe. By default, messages are printed as they are emitted; info messages go to the output stream, and warnings and errors go to the error stream.

Clients can handle all messages by registering a holder:

 Main main = new Main();
 IMessageHolder holder = new MessageHandler();
 main.setHolder(holder);
 
Clients can get control after each command completes by installing a Runnable:
 main.setCompletionRunner(new Runnable() {..});
 
  • Felddetails

    • THROWN_PREFIX

      public static final String THROWN_PREFIX
      Header used when rendering exceptions for users
    • controller

      protected Main.CommandController controller
      control iteration/continuation for command (compiler)
    • commandName

      protected String commandName
      ReflectionFactory identifier for command (compiler)
    • command

      protected ICommand command
    • ourHandler

      protected final MessageHandler ourHandler
      internally-set message sink
  • Konstruktordetails

    • Main

      public Main()
  • Methodendetails

    • main

      public static void main(String[] args) throws IOException
      Parameter:
      args - the String[] of command-line arguments
      Löst aus:
      IOException
    • bareMain

      public static int bareMain(String[] args, boolean useSystemExit, List<String> fails, List<String> errors, List<String> warnings, List<String> infos, List<String> usages)
      Convenience method to run ajc and collect String lists of messages. This can be reflectively invoked with the List collecting parameters supplied by a parent class loader. The String messages take the same form as command-line messages. This method does not catch unchecked exceptions thrown by the compiler.
      Parameter:
      args - the String[] args to pass to the compiler
      useSystemExit - if true and errors, return System.exit(errs)
      fails - the List sink, if any, for String failure (or worse) messages
      errors - the List sink, if any, for String error messages
      warnings - the List sink, if any, for String warning messages
      infos - the List sink, if any, for String info messages
      usages - the List sink, if any, for String usage messages
      Gibt zurück:
      number of messages reported with level ERROR or above
    • renderExceptionForUser

      public static String renderExceptionForUser(Throwable thrown)
      Gibt zurück:
      String rendering throwable as compiler error for user/console, including information on how to report as a bug.
      Löst aus:
      NullPointerException - if thrown is null
    • getMessageHandler

      public MessageHandler getMessageHandler()
    • setCommand

      public void setCommand(ICommand command)
    • runMain

      public void runMain(String[] args, boolean useSystemExit)
      Run without throwing exceptions but optionally using System.exit(..). This sets up a message handler which emits messages immediately, so report(boolean, IMessageHandler) only reports total number of errors or warnings.
      Parameter:
      args - the String[] command line for the compiler
      useSystemExit - if true, use System.exit(int) to complete unless one of the args is -noExit. and signal result (0 no exceptions/error, <0 exceptions, >0 compiler errors).
    • run

      public void run(String[] args, IMessageHolder holder)
      Run without using System.exit(..), putting all messages in holder:
      • 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.
      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.
      Parameter:
      args - the String[] command line for the compiler
      holder - the MessageHandler sink for messages.
    • quit

      public void quit()
      call this to stop after the next iteration of incremental compile
    • setHolder

      public void setHolder(IMessageHolder holder)
      Set holder to be passed all messages. When holder is set, messages will not be printed by default.
      Parameter:
      holder - the IMessageHolder sink for all messages (use null to restore default behavior)
    • getHolder

      public IMessageHolder getHolder()
    • setCompletionRunner

      public void setCompletionRunner(Runnable runner)
      Install a Runnable to be invoked synchronously after each compile completes.
      Parameter:
      runner - the Runnable to invoke - null to disable
    • systemExit

      protected void systemExit(IMessageHolder messages)
      Call System.exit(int) with values derived from the number of failures/aborts or errors in messages.
      Parameter:
      messages - the IMessageHolder to interrogate.
    • outMessage

      protected void outMessage(String message)
      Messages to the user
    • report

      protected boolean report(boolean pass, IMessageHolder holder)
      Report results from a (possibly-incremental) compile run. This delegates to any reportHandler or otherwise prints summary counts of errors/warnings to System.err (if any errors) or System.out (if only warnings). WARNING: this silently ignores other messages like FAIL, but clears the handler of all messages when returning true. XXX false This implementation ignores the pass parameter but clears the holder after reporting on the assumption messages were handled/printed already. (ignoring UnsupportedOperationException from holder.clearMessages()).
      Parameter:
      pass - true result of the command
      holder - IMessageHolder with messages from the command
      Gibt zurück:
      false if the process should abort
    • fail

      protected static void fail(IMessageHandler handler, String message, Throwable thrown)
      convenience API to make fail messages (without MessageUtils's fail prefix)