org.aspectj.bridge
Class MessageUtil

java.lang.Object
  extended by org.aspectj.bridge.MessageUtil

public class MessageUtil
extends java.lang.Object

Convenience API's for constructing, printing, and sending messages.


Nested Class Summary
static interface MessageUtil.IMessageRenderer
          parameterize rendering behavior for messages
 
Field Summary
static IMessage ABORT_NOMESSAGE
           
static IMessage ABORT_NOTHING_TO_RUN
           
static IMessage ERROR_NOMESSAGE
           
static IMessage FAIL_INCOMPLETE
           
static IMessage FAIL_NOMESSAGE
           
static MessageUtil.IMessageRenderer MESSAGE_ALL
          render message without restriction, up to 10K, including throwable
static MessageUtil.IMessageRenderer MESSAGE_LABEL
          render message as label, i.e., less than 33 char
static MessageUtil.IMessageRenderer MESSAGE_LABEL_NOLOC
          render message as label, i.e., less than 33 char, with no source location
static MessageUtil.IMessageRenderer MESSAGE_LINE
          render message as line, i.e., less than 75 char, no internal line sep
static MessageUtil.IMessageRenderer MESSAGE_LINE_FORCE_LOC
          render message as line, i.e., less than 75 char, no internal line sep, trying to trim text as needed to end with a full source location
static MessageUtil.IMessageRenderer MESSAGE_MOST
          render message without restriction, except any Throwable thrown
static MessageUtil.IMessageRenderer MESSAGE_SCALED
          render message more verbosely if it is worse
static MessageUtil.IMessageRenderer MESSAGE_SHORT
          render message using toShortString(IMessage)"
static MessageUtil.IMessageRenderer MESSAGE_TOSTRING
          render message using its toString() or "((IMessage) null)"
static MessageUtil.IMessageRenderer MESSAGE_WIDELINE
          render message as wide line, i.e., less than 256 char, no internal line sep, except any Throwable thrown
static IMessageHandler PICK_ABORT
           
static IMessageHandler PICK_ABORT_PLUS
           
static IMessageHandler PICK_ALL
           
static IMessageHandler PICK_DEBUG
           
static IMessageHandler PICK_DEBUG_PLUS
           
static IMessageHandler PICK_ERROR
           
static IMessageHandler PICK_ERROR_PLUS
           
static IMessageHandler PICK_FAIL
           
static IMessageHandler PICK_FAIL_PLUS
           
static IMessageHandler PICK_INFO
           
static IMessageHandler PICK_INFO_PLUS
           
static IMessageHandler PICK_WARNING
           
static IMessageHandler PICK_WARNING_PLUS
           
static IMessage WARNING_NOMESSAGE
           
 
Method Summary
static boolean abort(IMessageHandler handler, java.lang.String message)
          handle abort message (ignored if handler is null)
static boolean abort(IMessageHandler handler, java.lang.String message, java.lang.Throwable t)
          create and handle exception message (ignored if handler is null)
static IMessage abort(java.lang.String message)
           
static IMessage abort(java.lang.String message, java.lang.Throwable thrown)
           
static java.lang.String addExtraSourceLocations(IMessage message, java.lang.String baseMessage)
           
static boolean debug(IMessageHandler handler, java.lang.String message)
          create and handle debug message (ignored if handler is null)
static IMessage debug(java.lang.String message)
           
static boolean error(IMessageHandler handler, java.lang.String message)
          create and handle error message (ignored if handler is null)
static IMessage error(java.lang.String message)
           
static IMessage error(java.lang.String message, ISourceLocation location)
           
static boolean fail(IMessageHandler handler, java.lang.String message)
          create and handle fail message (ignored if handler is null)
static boolean fail(IMessageHandler handler, java.lang.String message, java.lang.Throwable thrown)
          create and handle fail message (ignored if handler is null)
static IMessage fail(java.lang.String message)
           
static IMessage fail(java.lang.String message, java.lang.Throwable thrown)
          Create fail message.
static IMessage.Kind getKind(java.lang.String kind)
          Map to the kind of messages associated with this string key.
static java.util.List<IMessage> getMessages(IMessageHolder holder, IMessage.Kind kind, boolean orGreater, java.lang.String infix)
           
static java.util.List<IMessage> getMessages(java.util.List<IMessage> messages, IMessage.Kind kind)
          Extract messages of type kind from the input list.
static IMessage[] getMessagesExcept(IMessageHolder holder, IMessage.Kind kind, boolean orGreater)
          Select all messages in holder except those of the same kind (optionally or greater).
static boolean handleAll(IMessageHandler sink, IMessage[] sources, boolean fastFail)
          Handle messages in the sink.
static boolean handleAll(IMessageHandler sink, IMessageHolder source, boolean fastFail)
          Handle all messages in the second handler using the first
static boolean handleAll(IMessageHandler sink, IMessageHolder source, IMessage.Kind kind, boolean orGreater, boolean fastFail)
          Handle messages in the second handler using the first
static boolean handleAllExcept(IMessageHandler sink, IMessageHolder source, IMessage.Kind kind, boolean orGreater, boolean fastFail)
          Handle messages in the second handler using the first if they are NOT of this kind (optionally, or greater).
static java.io.PrintStream handlerPrintStream(IMessageHandler handler, IMessage.Kind kind, java.io.OutputStream overage, java.lang.String prefix)
          Factory for handler adapted to PrintStream XXX weak - only handles println(String)
static boolean info(IMessageHandler handler, java.lang.String message)
          create and handle info message (ignored if handler is null)
static IMessage info(java.lang.String message)
           
static IMessageHandler makeSelector(IMessage.Kind kind, boolean orGreater, java.lang.String infix)
          Make an IMessageHandler that handles IMessage if they have the right kind (or greater) and contain some infix String.
static int numMessages(java.util.List<IMessage> messages, IMessage.Kind kind, boolean orGreater)
           
static void print(java.io.PrintStream out, IMessageHolder messageHolder)
          Print all message to the print stream, starting each on a new line
static void print(java.io.PrintStream out, IMessageHolder holder, java.lang.String prefix)
          Print all message to the print stream, starting each on a new line, with a prefix.
static void print(java.io.PrintStream out, IMessageHolder holder, java.lang.String prefix, MessageUtil.IMessageRenderer renderer)
          Print all message to the print stream, starting each on a new line, with a prefix and using a renderer.
static void print(java.io.PrintStream out, IMessageHolder holder, java.lang.String prefix, MessageUtil.IMessageRenderer renderer, IMessageHandler selector)
          Print all message to the print stream, starting each on a new line, with a prefix and using a renderer.
static void print(java.io.PrintStream out, IMessageHolder holder, java.lang.String prefix, MessageUtil.IMessageRenderer renderer, IMessageHandler selector, boolean printSummary)
           
static void printMessageCounts(java.io.PrintStream out, IMessageHolder messageHolder)
          Print total counts message to the print stream, starting each on a new line
static void printMessageCounts(java.io.PrintStream out, IMessageHolder holder, java.lang.String prefix)
           
static java.lang.String renderCounts(IMessageHolder holder)
           
static java.lang.String renderMessage(IMessage message)
          This renders IMessage as String, ignoring empty elements and eliding any thrown stack traces.
static java.lang.String renderMessage(IMessage message, boolean elide)
          This renders IMessage as String, ignoring empty elements and eliding any thrown.
static java.lang.String renderMessageLine(IMessage message, int textScale, int locScale, int max)
          Render message in a line.
static java.lang.String renderSourceLocation(ISourceLocation loc)
          Render ISourceLocation to String, ignoring empty elements (null or ISourceLocation.NO_FILE or ISourceLocation.NO_COLUMN (though implementations may return 0 from getColumn() when passed NO_COLUMN as input)).
static java.lang.String toShortString(IMessage message)
           
static IMessage[] visitMessages(java.util.Collection<IMessage> messages, IMessageHandler visitor, boolean accumulate, boolean abortOnFail)
          Run visitor over a collection of messages, optionally accumulating those accepted by the visitor
static IMessage[] visitMessages(IMessage[] messages, IMessageHandler visitor, boolean accumulate, boolean abortOnFail)
          Run visitor over the set of messages in holder, optionally accumulating those accepted by the visitor
static IMessage[] visitMessages(IMessageHolder holder, IMessageHandler visitor, boolean accumulate, boolean abortOnFail)
          Run visitor over the set of messages in holder, optionally accumulating those accepted by the visitor
static boolean warn(IMessageHandler handler, java.lang.String message)
          create and handle warn message (ignored if handler is null)
static IMessage warn(java.lang.String message)
           
static IMessage warn(java.lang.String message, ISourceLocation location)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ABORT_NOTHING_TO_RUN

public static final IMessage ABORT_NOTHING_TO_RUN

FAIL_INCOMPLETE

public static final IMessage FAIL_INCOMPLETE

ABORT_NOMESSAGE

public static final IMessage ABORT_NOMESSAGE

FAIL_NOMESSAGE

public static final IMessage FAIL_NOMESSAGE

ERROR_NOMESSAGE

public static final IMessage ERROR_NOMESSAGE

WARNING_NOMESSAGE

public static final IMessage WARNING_NOMESSAGE

PICK_ALL

public static final IMessageHandler PICK_ALL

PICK_ABORT

public static final IMessageHandler PICK_ABORT

PICK_DEBUG

public static final IMessageHandler PICK_DEBUG

PICK_ERROR

public static final IMessageHandler PICK_ERROR

PICK_FAIL

public static final IMessageHandler PICK_FAIL

PICK_INFO

public static final IMessageHandler PICK_INFO

PICK_WARNING

public static final IMessageHandler PICK_WARNING

PICK_ABORT_PLUS

public static final IMessageHandler PICK_ABORT_PLUS

PICK_DEBUG_PLUS

public static final IMessageHandler PICK_DEBUG_PLUS

PICK_ERROR_PLUS

public static final IMessageHandler PICK_ERROR_PLUS

PICK_FAIL_PLUS

public static final IMessageHandler PICK_FAIL_PLUS

PICK_INFO_PLUS

public static final IMessageHandler PICK_INFO_PLUS

PICK_WARNING_PLUS

public static final IMessageHandler PICK_WARNING_PLUS

MESSAGE_SCALED

public static final MessageUtil.IMessageRenderer MESSAGE_SCALED
render message more verbosely if it is worse


MESSAGE_LABEL

public static final MessageUtil.IMessageRenderer MESSAGE_LABEL
render message as label, i.e., less than 33 char


MESSAGE_LABEL_NOLOC

public static final MessageUtil.IMessageRenderer MESSAGE_LABEL_NOLOC
render message as label, i.e., less than 33 char, with no source location


MESSAGE_LINE

public static final MessageUtil.IMessageRenderer MESSAGE_LINE
render message as line, i.e., less than 75 char, no internal line sep


MESSAGE_LINE_FORCE_LOC

public static final MessageUtil.IMessageRenderer MESSAGE_LINE_FORCE_LOC
render message as line, i.e., less than 75 char, no internal line sep, trying to trim text as needed to end with a full source location


MESSAGE_ALL

public static final MessageUtil.IMessageRenderer MESSAGE_ALL
render message without restriction, up to 10K, including throwable


MESSAGE_MOST

public static final MessageUtil.IMessageRenderer MESSAGE_MOST
render message without restriction, except any Throwable thrown


MESSAGE_WIDELINE

public static final MessageUtil.IMessageRenderer MESSAGE_WIDELINE
render message as wide line, i.e., less than 256 char, no internal line sep, except any Throwable thrown


MESSAGE_TOSTRING

public static final MessageUtil.IMessageRenderer MESSAGE_TOSTRING
render message using its toString() or "((IMessage) null)"


MESSAGE_SHORT

public static final MessageUtil.IMessageRenderer MESSAGE_SHORT
render message using toShortString(IMessage)"

Method Detail

abort

public static boolean abort(IMessageHandler handler,
                            java.lang.String message)
handle abort message (ignored if handler is null)


abort

public static boolean abort(IMessageHandler handler,
                            java.lang.String message,
                            java.lang.Throwable t)
create and handle exception message (ignored if handler is null)


fail

public static boolean fail(IMessageHandler handler,
                           java.lang.String message)
create and handle fail message (ignored if handler is null)


fail

public static boolean fail(IMessageHandler handler,
                           java.lang.String message,
                           java.lang.Throwable thrown)
create and handle fail message (ignored if handler is null)


error

public static boolean error(IMessageHandler handler,
                            java.lang.String message)
create and handle error message (ignored if handler is null)


warn

public static boolean warn(IMessageHandler handler,
                           java.lang.String message)
create and handle warn message (ignored if handler is null)


debug

public static boolean debug(IMessageHandler handler,
                            java.lang.String message)
create and handle debug message (ignored if handler is null)


info

public static boolean info(IMessageHandler handler,
                           java.lang.String message)
create and handle info message (ignored if handler is null)


abort

public static IMessage abort(java.lang.String message)
Returns:
ABORT_NOMESSAGE if message is empty or IMessage otherwise

abort

public static IMessage abort(java.lang.String message,
                             java.lang.Throwable thrown)
Returns:
abort IMessage with thrown and message o ABORT_NOMESSAGE if both are empty/null

fail

public static IMessage fail(java.lang.String message)
Returns:
FAIL_NOMESSAGE if message is empty or IMessage otherwise

fail

public static IMessage fail(java.lang.String message,
                            java.lang.Throwable thrown)
Create fail message. If message is empty but thrown is not, use thrown.getMessage() as the message. If message is empty and thrown is null, return FAIL_NOMESSAGE.

Returns:
FAIL_NOMESSAGE if thrown is null and message is empty or IMessage FAIL with message and thrown otherwise

error

public static IMessage error(java.lang.String message,
                             ISourceLocation location)
Returns:
ERROR_NOMESSAGE if message is empty or IMessage otherwise

warn

public static IMessage warn(java.lang.String message,
                            ISourceLocation location)
Returns:
WARNING_NOMESSAGE if message is empty or IMessage otherwise

error

public static IMessage error(java.lang.String message)
Returns:
ERROR_NOMESSAGE if message is empty or IMessage otherwise

warn

public static IMessage warn(java.lang.String message)
Returns:
WARNING_NOMESSAGE if message is empty or IMessage otherwise

debug

public static IMessage debug(java.lang.String message)
Returns:
IMessage.DEBUG message with message content

info

public static IMessage info(java.lang.String message)
Returns:
IMessage.INFO message with message content

printMessageCounts

public static void printMessageCounts(java.io.PrintStream out,
                                      IMessageHolder messageHolder)
Print total counts message to the print stream, starting each on a new line

Parameters:
messageHolder -
out -

printMessageCounts

public static void printMessageCounts(java.io.PrintStream out,
                                      IMessageHolder holder,
                                      java.lang.String prefix)

print

public static void print(java.io.PrintStream out,
                         IMessageHolder messageHolder)
Print all message to the print stream, starting each on a new line

Parameters:
messageHolder -
out -
See Also:
#print(PrintStream, String, IMessageHolder, IMessageRenderer, IMessageHandler)

print

public static void print(java.io.PrintStream out,
                         IMessageHolder holder,
                         java.lang.String prefix)
Print all message to the print stream, starting each on a new line, with a prefix.

Parameters:
messageHolder -
out -
See Also:
#print(PrintStream, String, IMessageHolder, IMessageRenderer, IMessageHandler)

print

public static void print(java.io.PrintStream out,
                         IMessageHolder holder,
                         java.lang.String prefix,
                         MessageUtil.IMessageRenderer renderer)
Print all message to the print stream, starting each on a new line, with a prefix and using a renderer.

Parameters:
messageHolder -
out -
renderer - IMessageRender to render result - use MESSAGE_LINE if null
See Also:
#print(PrintStream, String, IMessageHolder, IMessageRenderer, IMessageHandler)

print

public static void print(java.io.PrintStream out,
                         IMessageHolder holder,
                         java.lang.String prefix,
                         MessageUtil.IMessageRenderer renderer,
                         IMessageHandler selector)
Print all message to the print stream, starting each on a new line, with a prefix and using a renderer. The first line renders a summary: {prefix}MessageHolder: {summary} Each message line has the following form:
 {prefix}[{kind} {index}]: {rendering}
 
(where "{index}" (length 3) is the position within the set of like-kinded messages, ignoring selector omissions. Renderers are free to render multi-line output.

Parameters:
out - the PrintStream sink - return silently if null
messageHolder - the IMessageHolder with the messages to print
renderer - IMessageRender to render result - use MESSAGE_ALL if null
selector - IMessageHandler to select messages to render - if null, do all non-null

print

public static void print(java.io.PrintStream out,
                         IMessageHolder holder,
                         java.lang.String prefix,
                         MessageUtil.IMessageRenderer renderer,
                         IMessageHandler selector,
                         boolean printSummary)

toShortString

public static java.lang.String toShortString(IMessage message)

numMessages

public static int numMessages(java.util.List<IMessage> messages,
                              IMessage.Kind kind,
                              boolean orGreater)
Returns:
int number of message of this kind (optionally or greater) in list

getMessagesExcept

public static IMessage[] getMessagesExcept(IMessageHolder holder,
                                           IMessage.Kind kind,
                                           boolean orGreater)
Select all messages in holder except those of the same kind (optionally or greater). If kind is null, then all messages are rejected, so an empty list is returned.

Returns:
unmodifiable list of specified IMessage

getMessages

public static java.util.List<IMessage> getMessages(IMessageHolder holder,
                                                   IMessage.Kind kind,
                                                   boolean orGreater,
                                                   java.lang.String infix)
Returns:
unmodifiable list of IMessage complying with parameters

getMessages

public static java.util.List<IMessage> getMessages(java.util.List<IMessage> messages,
                                                   IMessage.Kind kind)
Extract messages of type kind from the input list.

Parameters:
messages - if null, return EMPTY_LIST
kind - if null, return messages
See Also:
MessageHandler#getMessages(Kind)

getKind

public static IMessage.Kind getKind(java.lang.String kind)
Map to the kind of messages associated with this string key.

Parameters:
kind - the String representing the kind of message (IMessage.Kind.toString())
Returns:
Kind the associated IMessage.Kind, or null if not found

visitMessages

public static IMessage[] visitMessages(IMessageHolder holder,
                                       IMessageHandler visitor,
                                       boolean accumulate,
                                       boolean abortOnFail)
Run visitor over the set of messages in holder, optionally accumulating those accepted by the visitor


visitMessages

public static IMessage[] visitMessages(IMessage[] messages,
                                       IMessageHandler visitor,
                                       boolean accumulate,
                                       boolean abortOnFail)
Run visitor over the set of messages in holder, optionally accumulating those accepted by the visitor


visitMessages

public static IMessage[] visitMessages(java.util.Collection<IMessage> messages,
                                       IMessageHandler visitor,
                                       boolean accumulate,
                                       boolean abortOnFail)
Run visitor over a collection of messages, optionally accumulating those accepted by the visitor

Parameters:
messages - if null or empty, return IMessage.RA_IMessage
visitor - run visitor.handleMessage(message) on each message - if null and messages not empty, IllegalArgumentException
accumulate - if true, then return accepted IMessage[]
abortOnFail - if true and visitor returns false, stop visiting
Returns:
IMessage.RA_IMessage if collection is empty, if not accumulate, or if visitor accepted no IMessage, or IMessage[] of accepted messages otherwise
Throws:
java.lang.IllegalArgumentException - if any in collection are not instanceof IMessage

makeSelector

public static IMessageHandler makeSelector(IMessage.Kind kind,
                                           boolean orGreater,
                                           java.lang.String infix)
Make an IMessageHandler that handles IMessage if they have the right kind (or greater) and contain some infix String.

Parameters:
kind - the IMessage.Kind required of the message
orGreater - if true, also accept messages with greater kinds, as defined by IMessage.Kind.COMPARATOR
infix - the String text to require in the message - may be null or empty to accept any message with the specified kind.
Returns:
IMessageHandler selector that works to param specs

renderMessage

public static java.lang.String renderMessage(IMessage message)
This renders IMessage as String, ignoring empty elements and eliding any thrown stack traces.

Returns:
"((IMessage) null)" if null or String rendering otherwise, including everything (esp. throwable stack trace)
See Also:
renderSourceLocation(ISourceLocation loc)

renderMessage

public static java.lang.String renderMessage(IMessage message,
                                             boolean elide)
This renders IMessage as String, ignoring empty elements and eliding any thrown.

Returns:
"((IMessage) null)" if null or String rendering otherwise, including everything (esp. throwable stack trace)
See Also:
renderSourceLocation(ISourceLocation loc)

addExtraSourceLocations

public static java.lang.String addExtraSourceLocations(IMessage message,
                                                       java.lang.String baseMessage)

renderSourceLocation

public static java.lang.String renderSourceLocation(ISourceLocation loc)
Render ISourceLocation to String, ignoring empty elements (null or ISourceLocation.NO_FILE or ISourceLocation.NO_COLUMN (though implementations may return 0 from getColumn() when passed NO_COLUMN as input)).

Returns:
"((ISourceLocation) null)" if null or String rendering
 {file:}line{:column}
 

renderMessageLine

public static java.lang.String renderMessageLine(IMessage message,
                                                 int textScale,
                                                 int locScale,
                                                 int max)
Render message in a line. IMessage.Kind is always printed, then any unqualified exception class, then the remainder of text and location according to their relative scale, all to fit in max characters or less. This does not render thrown except for the unqualified class name

Parameters:
max - the number of characters - forced to 32..10000
textScale - relative proportion to spend on message and/or exception message, relative to source location - if 0, message is suppressed
locScale - relative proportion to spend on source location suppressed if 0
Returns:
"((IMessage) null)" or message per spec

renderCounts

public static java.lang.String renderCounts(IMessageHolder holder)
Returns:
String of the form "{(# {type}) }.." for message kinds, skipping 0

handlerPrintStream

public static java.io.PrintStream handlerPrintStream(IMessageHandler handler,
                                                     IMessage.Kind kind,
                                                     java.io.OutputStream overage,
                                                     java.lang.String prefix)
Factory for handler adapted to PrintStream XXX weak - only handles println(String)

Parameters:
handler - the IMessageHandler sink for the messages generated
kind - the IMessage.Kind of message to create
overage - the OuputStream for text not captured by the handler (if null, System.out used)
Throws:
java.lang.IllegalArgumentException - if kind or handler is null

handleAll

public static boolean handleAll(IMessageHandler sink,
                                IMessageHolder source,
                                boolean fastFail)
Handle all messages in the second handler using the first

Parameters:
handler - the IMessageHandler sink for all messages in source
holder - the IMessageHolder source for all messages to handle
fastFail - if true, stop on first failure
Returns:
false if any sink.handleMessage(..) failed

handleAll

public static boolean handleAll(IMessageHandler sink,
                                IMessageHolder source,
                                IMessage.Kind kind,
                                boolean orGreater,
                                boolean fastFail)
Handle messages in the second handler using the first

Parameters:
handler - the IMessageHandler sink for all messages in source
holder - the IMessageHolder source for all messages to handle
kind - the IMessage.Kind to select, if not null
orGreater - if true, also accept greater kinds
fastFail - if true, stop on first failure
Returns:
false if any sink.handleMessage(..) failed

handleAllExcept

public static boolean handleAllExcept(IMessageHandler sink,
                                      IMessageHolder source,
                                      IMessage.Kind kind,
                                      boolean orGreater,
                                      boolean fastFail)
Handle messages in the second handler using the first if they are NOT of this kind (optionally, or greater). If you pass null as the kind, then all messages are ignored and this returns true.

Parameters:
handler - the IMessageHandler sink for all messages in source
holder - the IMessageHolder source for all messages to handle
kind - the IMessage.Kind to reject, if not null
orGreater - if true, also reject greater kinds
fastFail - if true, stop on first failure
Returns:
false if any sink.handleMessage(..) failed

handleAll

public static boolean handleAll(IMessageHandler sink,
                                IMessage[] sources,
                                boolean fastFail)
Handle messages in the sink.

Parameters:
handler - the IMessageHandler sink for all messages in source
sources - the IMessage[] messages to handle
fastFail - if true, stop on first failure
Returns:
false if any sink.handleMessage(..) failed
Throws:
java.lang.IllegalArgumentException - if sink is null