Package org.aspectj.tools.ajc
Class Main
java.lang.Object
org.aspectj.tools.ajc.Main
- Direct Known Subclasses:
CompilerWrapper
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() {..});
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
controller for repeatable command delays until input or file changed or removedstatic class
static class
interceptor IMessageHandler to print as we go. -
Field Summary
Modifier and TypeFieldDescriptionprotected ICommand
protected String
ReflectionFactory identifier for command (compiler)protected Main.CommandController
control iteration/continuation for command (compiler)protected MessageHandler
internally-set message sinkstatic String
Header used when rendering exceptions for users -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.protected static void
fail(IMessageHandler handler, String message, Throwable thrown)
convenience API to make fail messages (without MessageUtils's fail prefix)static void
protected void
outMessage(String message)
Messages to the uservoid
quit()
call this to stop after the next iteration of incremental compilestatic String
renderExceptionForUser(Throwable thrown)
protected boolean
report(boolean pass, IMessageHolder holder)
Report results from a (possibly-incremental) compile run.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.void
Run without throwing exceptions but optionally using System.exit(..).void
setCommand(ICommand command)
void
setCompletionRunner(Runnable runner)
Install a Runnable to be invoked synchronously after each compile completes.void
setHolder(IMessageHolder holder)
Set holder to be passed all messages.protected void
systemExit(IMessageHolder messages)
Call System.exit(int) with values derived from the number of failures/aborts or errors in messages.
-
Field Details
-
THROWN_PREFIX
Header used when rendering exceptions for users -
controller
control iteration/continuation for command (compiler) -
commandName
ReflectionFactory identifier for command (compiler) -
command
-
ourHandler
internally-set message sink
-
-
Constructor Details
-
Main
public Main()
-
-
Method Details
-
main
- Parameters:
args
- the String[] of command-line arguments- Throws:
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.- Parameters:
args
- the String[] args to pass to the compileruseSystemExit
- if true and errors, return System.exit(errs)fails
- the List sink, if any, for String failure (or worse) messageserrors
- the List sink, if any, for String error messageswarnings
- the List sink, if any, for String warning messagesinfos
- the List sink, if any, for String info messagesusages
- the List sink, if any, for String usage messages- Returns:
- number of messages reported with level ERROR or above
-
renderExceptionForUser
- Returns:
- String rendering throwable as compiler error for user/console, including information on how to report as a bug.
- Throws:
NullPointerException
- if thrown is null
-
getMessageHandler
-
setCommand
-
runMain
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.- Parameters:
args
- the String[] command line for the compileruseSystemExit
- 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
Run without using System.exit(..), putting all messages in holder:- ERROR: compiler error
- WARNING: compiler warning
- FAIL: command error (bad arguments, exception thrown)
- 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.
- Parameters:
args
- the String[] command line for the compilerholder
- the MessageHandler sink for messages.
-
quit
public void quit()call this to stop after the next iteration of incremental compile -
setHolder
Set holder to be passed all messages. When holder is set, messages will not be printed by default.- Parameters:
holder
- the IMessageHolder sink for all messages (use null to restore default behavior)
-
getHolder
-
setCompletionRunner
Install a Runnable to be invoked synchronously after each compile completes.- Parameters:
runner
- the Runnable to invoke - null to disable
-
systemExit
Call System.exit(int) with values derived from the number of failures/aborts or errors in messages.- Parameters:
messages
- the IMessageHolder to interrogate.
-
outMessage
Messages to the user -
report
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()).- Parameters:
pass
- true result of the commandholder
- IMessageHolder with messages from the command- Returns:
- false if the process should abort
-
fail
convenience API to make fail messages (without MessageUtils's fail prefix)
-