Package Torello.JavaDoc.Messager
Class Messager
- java.lang.Object
-
- Torello.JavaDoc.Messager.Messager
-
public class Messager extends java.lang.Object
The Messager class is the top-level interface for emitting structured messages, warnings, and assertion failures to the user terminal. It exposes a static API (e.g.,Messager.userError(...)) that can be called from anywhere in the application without requiring an explicit instance.Thread-Local Field for Global, Thread-Safe, Accessibility
Internally, theMessagerclass uses aThreadLocal<Messager>field to enable thread-isolated behavior while preserving global accessibility. This design allows for safe use in multi-threaded environments (such as future parallel tools), without requiring developers to pass around explicitMessagerinstances just to emit error messages.
This internal infrastructure delegates responsibility to three supporting classes:PrintRecord— Maintains reusable buffers and context-statePrintHeading— Renders headers, including information about program-execution locatonPrintMessage— Assembles and prints complete message blocks to the terminal
The Messager was not originally designed to be thread-safe. However, the introduction ofThreadLocalisolation now ensures thread safety without altering its programming model.
A future release may introduce an explicitMsgInstanceclass for direct instancing, but such a design has not yet been implemented.
The following table lists all Method Parameters accepted by the core messaging functions provided by this class:assertFailassertFailContinueuserErrorHaltuserErrorContinueuserErrorContinueSTwarning
Method Parameters
Parameter Explanation String messageA human-readable explanation describing the problem or warning condition being reported. String signatureA textual representation of the method, field, or program element where the issue occurred. This parameter is especially useful in situations where no formal Entityinstance is available. It may include a fully qualified method signature or field reference, as needed.Throwable tIf the failure or warning is caused (or partially caused) by a caught ExceptionorError, the relevantThrowableinstance may be passed here. Its message and/or stack trace will be included in the terminal output.Where_Am_I WHERE_AM_IAn instance of the Where_Am_Ienumeration, indicating the current execution-path location in the application.
This value is typically consumed byPrintHeading, which renders visual banners that mark positional context within terminal output.
Hi-Lited Source-Code:- View Here: Torello/JavaDoc/Messager/Messager.java
- Open New Browser-Tab: Torello/JavaDoc/Messager/Messager.java
File Size: 17,185 Bytes Line Count: 478 '\n' Characters Found
-
-
Field Summary
Fields Modifier and Type Field static booleanDEFAULT_SHOW_STACK_TRACE_ON_ASSERT_FAIL
-
Method Summary
Initialize a Thread-Local Messager Instance Modifier and Type Method static voidinitializeThreadLocalInstance(int verbosityLevel, Appendable logAppendable)Print Text to Terminal Modifier and Type Method static voidprint(String s)static voidprintln()static voidprintln(String s)Print Text for Lower Verbosity Settings Modifier and Type Method static voidprintQuiet(String s)static voidprintSilent(boolean dotOrNewLine)Set Current Program Location Modifier and Type Method static voidsetCurrentFileName(String fName, String fNameKind)static voidsetDeclaration(Declaration declaration)static voidsetTopDescriptionSection()Report User Error Modifier and Type Method static voiduserErrorContinue(String message, String signature, Where_Am_I WHERE_AM_I)static voiduserErrorContinue(String message, Where_Am_I WHERE_AM_I)static voiduserErrorContinue(Throwable t, String message, Where_Am_I WHERE_AM_I)static voiduserErrorContinueST(Throwable t, String message, Where_Am_I WHERE_AM_I)Report User Error and Exit Modifier and Type Method static ErroruserErrorHalt(String message, Where_Am_I WHERE_AM_I)static ErroruserErrorHalt(Throwable t, String message, Where_Am_I WHERE_AM_I)Report Warning Modifier and Type Method static voidwarning(String message, Where_Am_I WHERE_AM_I)Report Assertion Failure and Exit Modifier and Type Method static ErrorassertFail(String message, String signature, Where_Am_I WHERE_AM_I)static ErrorassertFail(String message, Where_Am_I WHERE_AM_I)static ErrorassertFail(Throwable t, String message, String signature, Where_Am_I WHERE_AM_I)static ErrorassertFail(Throwable t, String message, Where_Am_I WHERE_AM_I)Report Assertion Failure (Non-Fatal) Modifier and Type Method static voidassertFailContinue(String message, Where_Am_I WHERE_AM_I)static voidassertFailContinue(Throwable t, String message, Where_Am_I WHERE_AM_I)Error State Query Modifier and Type Method static booleanhadErrors()Conditional Output Checkpoint Modifier and Type Method static voidifLogCheckPointLog()static voidifVerboseAppendVerbose()
-
-
-
Field Detail
-
DEFAULT_SHOW_STACK_TRACE_ON_ASSERT_FAIL
public static boolean DEFAULT_SHOW_STACK_TRACE_ON_ASSERT_FAIL
WhenTRUE, requests that the stack trace be printed to terminl output for any Assertion-Failure Error-Message which contains an Exception-Throw- Code:
- Exact Field Declaration Expression:
public static boolean DEFAULT_SHOW_STACK_TRACE_ON_ASSERT_FAIL = true;
-
-
Method Detail
-
initializeThreadLocalInstance
public static void initializeThreadLocalInstance (int verbosityLevel, java.lang.Appendable logAppendable)
Initializes theThreadLocal<Messager>instance for the current thread.
This method must be called exactly once per thread, before any of the staticMessagerprinting methods (such asuserError,assertionFailure, etc.) are invoked. It constructs and wires together the internal helper classesPrintRecord,PrintHeading, andPrintMessage, and binds the resultingMessagerobject to the current thread usingThreadLocal.set().
This design avoids the need to explicitly pass aroundMessagerinstances across the application and enables safe, isolated message formatting per thread. This is particularly useful for tools that may one day process multiple source files or build artifacts in parallel (e.g., future parallelization of the JDU tool).
This method must not be called more than once on the same thread. Doing so will result in anInternalError, as re-initialization would overwrite the existingMessagerinstance and compromise internal state.- Parameters:
verbosityLevel- The verbosity level for message output (must be between 0 and 3 inclusive). Higher levels enable more verbose diagnostic output.logAppendable- TheAppendableto which log output should be written. May benullif no log file output is needed. If so, Output-Text is not saved to disk.- Throws:
java.lang.InternalError- if this method is called more than once per thread and different assigned values to'verbosityLevel'or'logAppendable'are provided on the separate invocations.
ThisErrorwill also throw if theverbosityLevelis out of range- Code:
- Exact Method Body:
Messager m = tlInstance.get(); // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Newer Addition: This method may be invoked multiple times // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // // In order to facilitate calling some of the JDU's Features before the Upgrader has // started running - which in the partiular case that forced this new addition was // handling an Error by the File-HiLiter inside the "MoreHiliting" Class - the Messager // has to be initialized before the Upgrader even starts it's primary "upgrade()" Method. // // The default solution is to allow this method to be called as many times as are needed, // with the minor caveat that if the input values change in any way shape or form, then // an InternalError shall throw. if (m != null) { final boolean eqV = (m.printRecord.verbosityLevel == verbosityLevel); final boolean eqL = m.printRecord.checkEqualsLogAppendable(logAppendable); if (eqV && eqL) return; final String vStr = eqV ? "" : "The input Verbosity-Level [" + verbosityLevel + "], does not equal the " + "previously assigned Verbosity-Level [" + m.printRecord.verbosityLevel + "]\n"; final String lStr = eqL ? "" : "The input Log-Appendable is a different instance / reference Object than " + "the previously assigned Log-Appendable.\n"; throw new InternalError( "Messager.initializeThreadLocalInstance(int, Appendable) has been called " + "multiple times. On this invocation:\n" + vStr + lStr ); } if ((verbosityLevel < 0) || (verbosityLevel > 3)) throw new InternalError( "verbosityLevel=" + verbosityLevel + ", " + "but it must be between 0 and 3." ); final PrintRecord printRecord = new PrintRecord(verbosityLevel, logAppendable); final PrintHeading printHeading = new PrintHeading(printRecord); final PrintMessage printMessage = new PrintMessage(printRecord, printHeading); final Messager messager = new Messager(printRecord, printMessage); tlInstance.set(messager);
-
print
public static void print(java.lang.String s)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); if (m.printRecord.verbosityLevel >= 2) m.printRecord.screenWriterSW.print(s);
-
println
public static void println(java.lang.String s)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); if (m.printRecord.verbosityLevel >= 2) m.printRecord.screenWriterSW.println(s);
-
println
public static void println()
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); if (m.printRecord.verbosityLevel >= 2) m.printRecord.screenWriterSW.println();
-
printQuiet
public static void printQuiet(java.lang.String s)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); if (m.printRecord.verbosityLevel == 1) m.printRecord.screenWriterSW.print(s);
-
printSilent
public static void printSilent(boolean dotOrNewLine)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); if (m.printRecord.verbosityLevel == 0) m.printRecord.screenWriterSW.print(dotOrNewLine ? '.' : '\n');
-
ifVerboseAppendVerbose
public static void ifVerboseAppendVerbose()
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); if (m.printRecord.verbosityLevel == 3) m.printRecord.screenWriterSW.print(MsgVerbose.getAndClear());
-
warning
public static void warning(java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.WARNING(message, WHERE_AM_I); m.printRecord.writeSBToScreen();
-
assertFail
public static java.lang.Error assertFail(java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( message, null, // signature true, // FATAL WHERE_AM_I ); m.printRecord.writeSBToScreen(); throw new AssertFail();
-
assertFail
public static java.lang.Error assertFail(java.lang.String message, java.lang.String signature, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( message, signature, true, // FATAL WHERE_AM_I ); m.printRecord.writeSBToScreen(); throw new AssertFail();
-
assertFail
public static java.lang.Error assertFail(java.lang.Throwable t, java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( t, message, null, // signature true, // FATAL DEFAULT_SHOW_STACK_TRACE_ON_ASSERT_FAIL, WHERE_AM_I ); m.printRecord.writeSBToScreen(); throw new AssertFail();
-
assertFail
public static java.lang.Error assertFail(java.lang.Throwable t, java.lang.String message, java.lang.String signature, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( t, message, signature, true, // FATAL DEFAULT_SHOW_STACK_TRACE_ON_ASSERT_FAIL, WHERE_AM_I ); m.printRecord.writeSBToScreen(); throw new AssertFail();
-
assertFailContinue
public static void assertFailContinue(java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( message, null, // signature false, // NON-FATAL WHERE_AM_I ); m.printRecord.writeSBToScreen();
-
assertFailContinue
public static void assertFailContinue(java.lang.Throwable t, java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( t, message, null, // signature false, // NON-FATAL false, // Don't Show Stack-Trace WHERE_AM_I ); m.printRecord.writeSBToScreen();
-
userErrorHalt
public static java.lang.Error userErrorHalt(java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( message, null, // signature true, // FATAL WHERE_AM_I ); m.printRecord.writeSBToScreen(); throw new MessagerGeneratedError();
-
userErrorHalt
public static java.lang.Error userErrorHalt(java.lang.Throwable t, java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( t, // Exception that was thrown message, // THE MESSAGE null, // signature true, // FATAL true, // Show Stack-Trace WHERE_AM_I ); m.printRecord.writeSBToScreen(); throw new MessagerGeneratedError();
-
userErrorContinue
public static void userErrorContinue(java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( message, null, // signature false, // NON-FATAL WHERE_AM_I ); m.printRecord.writeSBToScreen();
-
userErrorContinue
public static void userErrorContinue(java.lang.String message, java.lang.String signature, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( message, signature, false, // NON-FATAL WHERE_AM_I ); m.printRecord.writeSBToScreen();
-
userErrorContinue
public static void userErrorContinue(java.lang.Throwable t, java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( t, message, null, // signature false, // NON-FATAL false, // Don't Show Stack-Trace WHERE_AM_I ); m.printRecord.writeSBToScreen();
-
userErrorContinueST
public static void userErrorContinueST(java.lang.Throwable t, java.lang.String message, Where_Am_I WHERE_AM_I)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printMessage.ERROR( t, message, null, // signature false, // NON-FATAL true, // SHOW STACK TRACE WHERE_AM_I ); m.printRecord.writeSBToScreen();
-
setCurrentFileName
public static void setCurrentFileName(java.lang.String fName, java.lang.String fNameKind)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printRecord.setCurrentFileName(fName, fNameKind);
-
setTopDescriptionSection
public static void setTopDescriptionSection()
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printRecord.setTopDescriptionSection();
-
setDeclaration
public static void setDeclaration(Declaration declaration)
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); m.printRecord.setDeclaration(declaration);
-
hadErrors
public static boolean hadErrors()
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); return m.printRecord.hadErrors();
-
ifLogCheckPointLog
public static void ifLogCheckPointLog()
- Code:
- Exact Method Body:
final Messager m = tlInstance.get(); if (! m.printRecord.hasLogAppendable) return; m.printRecord.checkPointLog();
-
-