Package mars.assembler.log
Class AssemblerLog
java.lang.Object
mars.assembler.log.AssemblerLog
A log for keeping track of errors occurring during the assembly process, whether during tokenizing, parsing,
or assembling. While simply throwing an
AssemblyError would be a valid way to report errors, using this
log allows multiple LogMessages with varying LogLevels to be recorded in a single pass.
The original version of this class, written by Pete Sanderson, was called ErrorList.
- Author:
- Pete Sanderson, August 2003; Sean Clarke, October 2024
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all messages from the log.intGet the maximum number of errors which can be produced by a single assembler run.intCount the total number of logged messages, regardless of level.intgetMessageCount(LogLevel level) Count the number of logged messages with a given level.Get the list of all logged messages, regardless of level, in chronological order.booleanDetermine whether the current number of errors logged exceeds the maximum error count, indicating that the assembler should exit as soon as possible.booleanhasMessages(LogLevel level) Determine whether at least one message has been logged with a given level.voidlog(LogLevel level, SourceLocation location, String content) voidlog(LogMessage message) Log a message for the current assembler run.voidlogError(SourceLocation location, String content) voidlogInfo(SourceLocation location, String content) voidlogWarning(SourceLocation location, String content) voidsetMaxErrorCount(int maxErrorCount) Set the maximum number of errors which can be produced by a single assembler run.voidsetOutput(Consumer<LogMessage> output)
-
Constructor Details
-
AssemblerLog
public AssemblerLog()Create a new, emptyAssemblerLog.
-
-
Method Details
-
clear
public void clear()Clear all messages from the log. -
getMessages
Get the list of all logged messages, regardless of level, in chronological order.- Returns:
- The list of logged messages.
-
getMessageCount
public int getMessageCount()Count the total number of logged messages, regardless of level.- Returns:
- The number of messages.
-
getMessageCount
Count the number of logged messages with a given level.- Parameters:
level- The level used to filter messages.- Returns:
- The number of messages whose level is
level.
-
hasMessages
Determine whether at least one message has been logged with a given level. This method is equivalent to the expressiongetMessageCount(level) > 0.- Parameters:
level- The level used to filter messages.- Returns:
trueif at least one message has been logged with levellevel, orfalseif no such messages have been logged.
-
getMaxErrorCount
public int getMaxErrorCount()Get the maximum number of errors which can be produced by a single assembler run.- Returns:
- The maximum number of messages with level
LogLevel.ERRORthat can be logged.
-
setMaxErrorCount
public void setMaxErrorCount(int maxErrorCount) Set the maximum number of errors which can be produced by a single assembler run.- Parameters:
maxErrorCount- The maximum number of messages with levelLogLevel.ERRORthat can be logged.
-
hasExceededMaxErrorCount
public boolean hasExceededMaxErrorCount()Determine whether the current number of errors logged exceeds the maximum error count, indicating that the assembler should exit as soon as possible.- Returns:
trueif the error count exceeds the maxiumm, orfalseotherwise.- See Also:
-
setOutput
-
log
Log a message for the current assembler run. After this call, the newly logged message is considered to be the last message in chronological order.- Parameters:
message- The message to log
-
log
-
logInfo
-
logWarning
-
logError
-