Package com.tonic.analysis.source.parser
Class ParseException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- com.tonic.analysis.source.parser.ParseException
-
- All Implemented Interfaces:
Serializable
public class ParseException extends RuntimeException
Unchecked failure to parse Java source, carrying the offending position and, when available, the source text so the message can show the line with a caret.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ParseException(String message, SourcePosition position)Creates a failure with no source text, so the message carries only the position.ParseException(String message, SourcePosition position, String source)Creates a failure with source text for context rendering.ParseException(String message, Token token)Creates a failure positioned at a token, with no source text.ParseException(String message, Token token, String source)Creates a failure positioned at a token, with source text for context rendering.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetColumn()StringgetFormattedMessage()Renders the message, the position when known, and - if the source text was supplied - the offending line with a caret under the column.intgetLine()SourcePositiongetPosition()StringgetSource()StringtoString()-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
-
-
-
Constructor Detail
-
ParseException
public ParseException(String message, SourcePosition position, String source)
Creates a failure with source text for context rendering.- Parameters:
message- what went wrongposition- where it went wrong, or nullsource- the full source text, or null to omit the context excerpt
-
ParseException
public ParseException(String message, SourcePosition position)
Creates a failure with no source text, so the message carries only the position.- Parameters:
message- what went wrongposition- where it went wrong, or null
-
ParseException
public ParseException(String message, Token token, String source)
Creates a failure positioned at a token, with source text for context rendering.- Parameters:
message- what went wrongtoken- the offending tokensource- the full source text, or null to omit the context excerpt- Throws:
NullPointerException- if the token is null
-
ParseException
public ParseException(String message, Token token)
Creates a failure positioned at a token, with no source text.- Parameters:
message- what went wrongtoken- the offending token- Throws:
NullPointerException- if the token is null
-
-
Method Detail
-
getPosition
public SourcePosition getPosition()
- Returns:
- the position
-
getSource
public String getSource()
- Returns:
- the source
-
getLine
public int getLine()
- Returns:
- the 1-based line, or 0 when no position was recorded
-
getColumn
public int getColumn()
- Returns:
- the 1-based column, or 0 when no position was recorded
-
getFormattedMessage
public String getFormattedMessage()
Renders the message, the position when known, and - if the source text was supplied - the offending line with a caret under the column.- Returns:
- the multi-line report
-
-