Class LineNumberingNodeFactory
java.lang.Object
com.singularsys.jep.NodeFactory
com.singularsys.jep.misc.lineNumbering.LineNumberingNodeFactory
- All Implemented Interfaces:
JepComponent,Serializable
A NodeFactory which adds line numbering information to nodes.
The method
setCurrentPosition(int,int) is used to set the position before calling one of the
buildConstantNode(Object value) methods.
This stores the line and column numbers in the created node using the
Node.setHook(Node.HookKey,Object) method.
The getLineNumber(Node) and getColumn(Node) class methods can be used to retrieve
this information from a given node.
By convention, numbering starts from line 1 column 1.- Since:
- 3.4.0
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class com.singularsys.jep.NodeFactory
ev, j, vt -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor which decorates a NodeFactory.Decorating constructor -
Method Summary
Modifier and TypeMethodDescriptionbuildConstantNode(Operator op, Node... children) Creates a ASTConstant whose value of applying the operator to its arguments.buildConstantNode(ASTConstant node) Create an ASTConstant with same value as argument.buildConstantNode(PostfixMathCommandI pfmc, Node... children) Creates a constant node whose result is the given function applied to the children.buildConstantNode(Object value) Creates an ASTConstant node with specified value.buildFunctionNode(ASTFunNode node, Node... arguments) Builds a function with n arguments and same fun as specified in arguments.buildFunctionNode(String name, PostfixMathCommandI pfmc, Node... arguments) Builds a function with n arguments.buildOperatorNode(Operator op, Node... arguments) Builds an operator node with n arguments This method should be sub-classed.An unfinished node.buildVariableNode(ASTVarNode node) creates a new ASTVarNode with the same name as argument.creates a new ASTVarNode with a given variable.buildVariableNode(String name) Build a variable node when just the name is known.Build a variable node checking for the undeclared status.static intConvenience method to get the column number of a node.intGets the current column used when a node is created.intGets the current line used when a node is created.Gets a light-weight instance suitable for using in multiple threads.static intgetLineNumber(Node node) Convenience method to get the line number of a node.getRoot()voidInitialize the component.voidsetCurrentPosition(int line, int col) Sets the current position which will be used the next time a node is created.static voidsetPosition(Node node, int line, int col) Convenience method to set the line and column numbers for a node.Methods inherited from class com.singularsys.jep.NodeFactory
copyChildren
-
Constructor Details
-
LineNumberingNodeFactory
Decorating constructor- Parameters:
root-
-
LineNumberingNodeFactory
public LineNumberingNodeFactory()Default constructor which decorates a NodeFactory.
-
-
Method Details
-
getLineNumber
Convenience method to get the line number of a node.- Parameters:
node-- Returns:
- the line number
-
getColumn
Convenience method to get the column number of a node.- Parameters:
node-- Returns:
- the column number
-
setPosition
Convenience method to set the line and column numbers for a node.- Parameters:
node- whose position will be setline- line numbercol- column number
-
setCurrentPosition
public void setCurrentPosition(int line, int col) Sets the current position which will be used the next time a node is created.- Parameters:
line-col-
-
getCurrentLine
public int getCurrentLine()Gets the current line used when a node is created.- Returns:
- the current line
-
getCurrentColumn
public int getCurrentColumn()Gets the current column used when a node is created.- Returns:
- the current column
-
buildConstantNode
Description copied from class:NodeFactoryCreate an ASTConstant with same value as argument. *- Overrides:
buildConstantNodein classNodeFactory- Throws:
ParseException
-
buildConstantNode
Description copied from class:NodeFactoryCreates an ASTConstant node with specified value. This method should be overwritten by subclasses.- Overrides:
buildConstantNodein classNodeFactory- Throws:
ParseException
-
buildConstantNode
Description copied from class:NodeFactoryCreates a ASTConstant whose value of applying the operator to its arguments.- Overrides:
buildConstantNodein classNodeFactory- Throws:
ParseException
-
buildConstantNode
public ASTConstant buildConstantNode(PostfixMathCommandI pfmc, Node... children) throws ParseException Description copied from class:NodeFactoryCreates a constant node whose result is the given function applied to the children. This method replaces non varargs methods in Jep 3.4- Overrides:
buildConstantNodein classNodeFactory- Parameters:
pfmc- the function to applychildren- the arguments to the function, each argument should be a constant node.- Returns:
- a new constant node
- Throws:
ParseException
-
buildFunctionNode
Description copied from class:NodeFactoryBuilds a function with n arguments and same fun as specified in arguments.- Overrides:
buildFunctionNodein classNodeFactory- Parameters:
node- the properties (name and pfmc) of this node will be copied.arguments- the arguments to the function.- Returns:
- top Node of expression
- Throws:
ParseException
-
buildFunctionNode
public ASTFunNode buildFunctionNode(String name, PostfixMathCommandI pfmc, Node... arguments) throws ParseException Description copied from class:NodeFactoryBuilds a function with n arguments. Subclasses should override this method.- Overrides:
buildFunctionNodein classNodeFactory- Parameters:
name- of function.pfmc- PostfixMathCommand for function.arguments- the arguments to the function.- Returns:
- top Node of expression
- Throws:
ParseException
-
buildOperatorNode
Description copied from class:NodeFactoryBuilds an operator node with n arguments This method should be sub-classed. This varargs method replaces corresponding non varargs methods from Jep 3.4- Overrides:
buildOperatorNodein classNodeFactory- Parameters:
op- the operator to usearguments- the arguments to the function.- Returns:
- top Node of expression
- Throws:
ParseException
-
buildUnfinishedOperatorNode
Description copied from class:NodeFactoryAn unfinished node. Caller has responsibility for filling in the children.- Overrides:
buildUnfinishedOperatorNodein classNodeFactory
-
buildVariableNode
Description copied from class:NodeFactorycreates a new ASTVarNode with the same name as argument.- Overrides:
buildVariableNodein classNodeFactory- Throws:
ParseException
-
buildVariableNode
Description copied from class:NodeFactoryBuild a variable node when just the name is known.- Overrides:
buildVariableNodein classNodeFactory- Parameters:
name- the name of the variable- Returns:
- the node created
- Throws:
ParseException
-
buildVariableNode
Description copied from class:NodeFactorycreates a new ASTVarNode with a given variable. This method should be sub-classed- Overrides:
buildVariableNodein classNodeFactory- Throws:
ParseException
-
buildVariableNodeCheckUndeclared
Description copied from class:NodeFactoryBuild a variable node checking for the undeclared status.- Overrides:
buildVariableNodeCheckUndeclaredin classNodeFactory- Parameters:
name- name of the variable- Returns:
- a new node
- Throws:
ParseException- if undeclared variables are not allowed and the variable does not exist
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Overrides:
getLightWeightInstancein classNodeFactory- Returns:
- new NodeFactory()
-
init
Description copied from interface:JepComponentInitialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Overrides:
initin classNodeFactory- Parameters:
jep- the current Jep instance
-
getRoot
-