Class Debugger
java.lang.Object
org.apache.commons.jexl3.parser.ParserVisitor
org.apache.commons.jexl3.internal.Debugger
- All Implemented Interfaces:
JexlInfo.Detail
- Direct Known Subclasses:
TemplateDebugger
Helps pinpoint the cause of problems in expressions that fail during evaluation.
It rebuilds an expression string from the tree and the start/end offsets of the cause in that string. This implies that exceptions during evaluation do always carry the node that's causing the error.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
Arrow symbol.protected final StringBuilder
The builder to compose messages.protected JexlNode
The cause of the issue to debug.protected int
accept() relative depth.protected int
The ending character location offset of the cause in the builder.protected int
Perform indentation?.protected int
The indentation level.protected String
EOL.protected boolean
Pragmas out.protected static final Pattern
Checks identifiers that contain spaces or punctuation (but underscore, at-sign, sharp-sign and dollar).protected int
The starting character location offset of the cause in the builder. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
Checks if a child node is the cause to debug & adds its representation to the rebuilt expression.protected Object
acceptStatement
(JexlNode child, Object data) Adds a statement node to the rebuilt expression.protected Object
additiveNode
(JexlNode node, String op, Object data) Rebuilds an additive expression.protected Object
Checks if a terminal node is the cause to debug & adds its representation to the rebuilt expression.Rebuilds an expression from a JEXL node.boolean
debug
(JexlExpression jscript) Position the debugger on the root of an expression.boolean
debug
(JexlScript jscript) Position the debugger on the root of a script.boolean
Seeks the location of an error cause (a node) in an expression.boolean
Seeks the location of an error cause (a node) in an expression.depth
(int rdepth) Sets this debugger relative maximum depth.int
end()
protected JexlFeatures
getFeatures
(JexlNode node) Tries (hard) to find the features used to parse a node.indentation
(int level) Sets the indentation level.protected Object
infixChildren
(JexlNode node, String infix, boolean paren, Object data) Checks if the children of a node using infix notation is the cause to debug, adds their representation to the rebuilt expression.private static boolean
isLambdaExpr
(ASTJexlLambda lambda) private static boolean
isStatement
(JexlNode child) Whether a node is a statement (vs an expression).Sets this debugger line-feed string.protected boolean
needQuotes
(String str) Checks whether an identifier should be quoted or not.outputPragmas
(boolean flag) Lets the debugger write out pragmas if any.protected Object
postfixChild
(JexlNode node, String prefix, Object data) Postfix operators.protected Object
prefixChild
(JexlNode node, String prefix, Object data) Checks if the child of a node using prefix notation is the cause to debug, adds their representation to the rebuilt expression.void
reset()
Resets this debugger state.private static boolean
Whether a script or expression ends with a semicolumn.protected void
setArrowSymbol
(JexlNode node) Sets the arrow style (fat or thin) depending on features.void
setIndentation
(int level) Sets the indentation level.int
start()
toString()
protected Object
visit
(ASTAddNode node, Object data) protected Object
visit
(ASTAndNode node, Object data) protected Object
visit
(ASTAnnotatedStatement node, Object data) protected Object
visit
(ASTAnnotation node, Object data) protected Object
visit
(ASTArguments node, Object data) protected Object
visit
(ASTArrayAccess node, Object data) protected Object
visit
(ASTArrayLiteral node, Object data) protected Object
visit
(ASTAssignment node, Object data) protected Object
visit
(ASTBitwiseAndNode node, Object data) protected Object
visit
(ASTBitwiseComplNode node, Object data) protected Object
visit
(ASTBitwiseOrNode node, Object data) protected Object
visit
(ASTBitwiseXorNode node, Object data) protected Object
protected Object
protected Object
visit
(ASTConstructorNode node, Object data) protected Object
visit
(ASTContinue node, Object data) protected Object
visit
(ASTDecrementGetNode node, Object data) protected Object
visit
(ASTDefineVars node, Object data) protected Object
visit
(ASTDivNode node, Object data) protected Object
visit
(ASTDoWhileStatement node, Object data) protected Object
visit
(ASTEmptyFunction node, Object data) protected Object
protected Object
protected Object
protected Object
visit
(ASTExtendedLiteral node, Object data) protected Object
visit
(ASTFalseNode node, Object data) protected Object
visit
(ASTForeachStatement node, Object data) protected Object
visit
(ASTFunctionNode node, Object data) protected Object
protected Object
visit
(ASTGetDecrementNode node, Object data) protected Object
visit
(ASTGetIncrementNode node, Object data) protected Object
protected Object
visit
(ASTIdentifierAccess node, Object data) protected Object
visit
(ASTIdentifier node, Object data) protected Object
visit
(ASTIfStatement node, Object data) protected Object
visit
(ASTIncrementGetNode node, Object data) protected Object
visit
(ASTJexlScript node, Object arg) protected Object
visit
(ASTJxltLiteral node, Object data) protected Object
protected Object
protected Object
visit
(ASTMapEntry node, Object data) protected Object
visit
(ASTMapLiteral node, Object data) protected Object
visit
(ASTMethodNode node, Object data) protected Object
visit
(ASTModNode node, Object data) protected Object
visit
(ASTMulNode node, Object data) protected Object
protected Object
visit
(ASTNEWNode node, Object data) protected Object
visit
(ASTNotNode node, Object data) protected Object
protected Object
visit
(ASTNSWNode node, Object data) protected Object
visit
(ASTNullLiteral node, Object data) protected Object
visit
(ASTNullpNode node, Object data) protected Object
visit
(ASTNumberLiteral node, Object data) protected Object
protected Object
visit
(ASTQualifiedIdentifier node, Object data) protected Object
visit
(ASTRangeNode node, Object data) protected Object
visit
(ASTReferenceExpression node, Object data) protected Object
visit
(ASTReference node, Object data) protected Object
visit
(ASTRegexLiteral node, Object data) protected Object
visit
(ASTReturnStatement node, Object data) protected Object
visit
(ASTSetAddNode node, Object data) protected Object
visit
(ASTSetAndNode node, Object data) protected Object
visit
(ASTSetDivNode node, Object data) protected Object
visit
(ASTSetLiteral node, Object data) protected Object
visit
(ASTSetModNode node, Object data) protected Object
visit
(ASTSetMultNode node, Object data) protected Object
visit
(ASTSetOrNode node, Object data) protected Object
visit
(ASTSetShiftLeftNode node, Object data) protected Object
visit
(ASTSetShiftRightNode node, Object data) protected Object
visit
(ASTSetShiftRightUnsignedNode node, Object data) protected Object
visit
(ASTSetSubNode node, Object data) protected Object
visit
(ASTSetXorNode node, Object data) protected Object
visit
(ASTShiftLeftNode node, Object data) protected Object
visit
(ASTShiftRightNode node, Object data) protected Object
visit
(ASTShiftRightUnsignedNode node, Object data) protected Object
visit
(ASTSizeFunction node, Object data) protected Object
visit
(ASTStringLiteral node, Object data) protected Object
visit
(ASTSubNode node, Object data) protected Object
protected Object
visit
(ASTTernaryNode node, Object data) protected Object
visit
(ASTTrueNode node, Object data) protected Object
visit
(ASTUnaryMinusNode node, Object data) protected Object
visit
(ASTUnaryPlusNode node, Object data) protected Object
protected Object
visit
(ASTWhileStatement node, Object data) protected String
visitParameter
(String p, Object data) A pseudo visitor for parameters.private static void
writePragmas
(StringBuilder builder, Map<String, Object> pragmas) Stringifies the pragmas.Methods inherited from class org.apache.commons.jexl3.parser.ParserVisitor
visit, visit
-
Field Details
-
builder
The builder to compose messages. -
cause
The cause of the issue to debug. -
start
protected int startThe starting character location offset of the cause in the builder. -
end
protected int endThe ending character location offset of the cause in the builder. -
indentLevel
protected int indentLevelThe indentation level. -
indent
protected int indentPerform indentation?. -
depth
protected int depthaccept() relative depth. -
arrow
Arrow symbol. -
lf
EOL. -
outputPragmas
protected boolean outputPragmasPragmas out. -
QUOTED_IDENTIFIER
Checks identifiers that contain spaces or punctuation (but underscore, at-sign, sharp-sign and dollar).
-
-
Constructor Details
-
Debugger
public Debugger()Creates a Debugger.
-
-
Method Details
-
reset
public void reset()Resets this debugger state. -
getFeatures
Tries (hard) to find the features used to parse a node.- Parameters:
node
- the node- Returns:
- the features or null
-
setArrowSymbol
Sets the arrow style (fat or thin) depending on features.- Parameters:
node
- the node to start seeking features from.
-
debug
Position the debugger on the root of an expression.- Parameters:
jscript
- the expression- Returns:
- true if the expression was a
Script
instance, false otherwise
-
debug
Position the debugger on the root of a script.- Parameters:
jscript
- the script- Returns:
- true if the script was a
Script
instance, false otherwise
-
debug
Seeks the location of an error cause (a node) in an expression.- Parameters:
node
- the node to debug- Returns:
- true if the cause was located, false otherwise
-
debug
Seeks the location of an error cause (a node) in an expression.- Parameters:
node
- the node to debugr
- whether we should actively find the root node of the debugged node- Returns:
- true if the cause was located, false otherwise
-
toString
- Specified by:
toString
in interfaceJexlInfo.Detail
- Overrides:
toString
in classObject
- Returns:
- The rebuilt expression
-
data
Rebuilds an expression from a JEXL node.- Parameters:
node
- the node to rebuilt from- Returns:
- the rebuilt expression
- Since:
- 3.0
-
start
public int start()- Specified by:
start
in interfaceJexlInfo.Detail
- Returns:
- The starting offset location of the cause in the expression
-
end
public int end()- Specified by:
end
in interfaceJexlInfo.Detail
- Returns:
- The end offset location of the cause in the expression
-
outputPragmas
Lets the debugger write out pragmas if any.- Parameters:
flag
- turn on or off- Returns:
- this debugger instance
-
setIndentation
public void setIndentation(int level) Sets the indentation level.- Parameters:
level
- the number of spaces for indentation, none if less or equal to zero
-
indentation
Sets the indentation level.- Parameters:
level
- the number of spaces for indentation, none if less or equal to zero- Returns:
- this debugger instance
-
depth
Sets this debugger relative maximum depth.- Parameters:
rdepth
- the maximum relative depth from the debugged node- Returns:
- this debugger instance
-
lineFeed
Sets this debugger line-feed string.- Parameters:
lf
- the string used to delineate lines (usually "\" or "")- Returns:
- this debugger instance
-
accept
Checks if a child node is the cause to debug & adds its representation to the rebuilt expression.- Parameters:
node
- the child nodedata
- visitor pattern argument- Returns:
- visitor pattern value
-
isStatement
Whether a node is a statement (vs an expression).- Parameters:
child
- the node- Returns:
- true if node is a statement
-
semicolTerminated
Whether a script or expression ends with a semicolumn.- Parameters:
cs
- the string- Returns:
- true if a semicolumn is the last non-whitespace character
-
acceptStatement
Adds a statement node to the rebuilt expression.- Parameters:
child
- the child nodedata
- visitor pattern argument- Returns:
- visitor pattern value
-
check
Checks if a terminal node is the cause to debug & adds its representation to the rebuilt expression.- Parameters:
node
- the child nodeimage
- the child node token image (may be null)data
- visitor pattern argument- Returns:
- visitor pattern value
-
infixChildren
Checks if the children of a node using infix notation is the cause to debug, adds their representation to the rebuilt expression.- Parameters:
node
- the child nodeinfix
- the child node tokenparen
- whether the child should be parenthesizeddata
- visitor pattern argument- Returns:
- visitor pattern value
-
prefixChild
Checks if the child of a node using prefix notation is the cause to debug, adds their representation to the rebuilt expression.- Parameters:
node
- the nodeprefix
- the node tokendata
- visitor pattern argument- Returns:
- visitor pattern value
-
postfixChild
Postfix operators.- Parameters:
node
- a postfix operatorprefix
- the postfixdata
- visitor pattern argument- Returns:
- visitor pattern value
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
additiveNode
Rebuilds an additive expression.- Parameters:
node
- the nodeop
- the operatordata
- visitor pattern argument- Returns:
- visitor pattern value
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
needQuotes
Checks whether an identifier should be quoted or not.- Parameters:
str
- the identifier- Returns:
- true if needing quotes, false otherwise
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visitParameter
A pseudo visitor for parameters.- Parameters:
p
- the parameter namedata
- the visitor argument- Returns:
- the parameter name to use
-
isLambdaExpr
-
writePragmas
Stringifies the pragmas.- Parameters:
builder
- where to stringifypragmas
- the pragmas, may be null
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-
visit
- Specified by:
visit
in classParserVisitor
-