DartBlockProgramTreeNode class sealed
The tree-based representation of a DartBlock component (Statement, Function) as a node.
A node can have an optional parent node, as well as a list of child nodes.
The purpose of this tree representation is to primarily keep track of the variable scopes. As such, by traversing upward from a given node, we can determine the variables which have already been declared and which are usable in the current scope.
A second usage of this tree representation is to enable the evaluation schema DartBlockVariableCountEvaluationSchema.
Technical details:
- The root node, defined by the concrete DartBlockProgramTreeRootNode, has no parent. The root node is created by DartBlockProgram.buildTree.
- The child nodes of DartBlockProgramTreeRootNode are the main DartBlockFunction and any additional custom DartBlockFunction. The concrete implementation is given by DartBlockProgramTreeCustomFunctionNode.
- Each DartBlockProgramTreeCustomFunctionNode has as a singular child the first Statement in its body. The concrete implementation is given by DartBlockProgramTreeStatementNode.
- Compound Statements, such as WhileLoopStatement, again have the first Statement in their body as a singular child.
- Special cases include IfElseStatement and ForLoopStatement:
- IfElseStatement: it has a child for its if-body, another for its else-body and one for each additional else-if clause's body.
- ForLoopStatement: if its ForLoopStatement.initStatement is not null, it is its singular chilld. Otherwise, the starting child is the first statement of its body.
Properties
-
children
→ List<
DartBlockProgramTreeNode> -
The list of child nodes.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → int
-
A unique key which the node is associated with.
final
- parent → DartBlockProgramTreeNode?
-
The parent node.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
findAllVariableDefinitions(
) → List< DartBlockVariableDefinition> - Retrieve all variable definitions in the current node and its child nodes.
-
findNodeByKey(
int key) → DartBlockProgramTreeNode? -
Return this node if its
key
matches. Otherwise, perform downward traversal to find matches in the child nodes. -
findVariableDefinitions(
int key, {bool includeNode = false}) → List< DartBlockVariableDefinition> -
Retrieve the list of variables defined in the scope given by the starting node, based on its
key
. Based on the starting node, upward traversal is used to find all preceding variable definitions. -
getMaxDepth(
) → int - Get the depth of this node.
-
getStatementTypeUsageCount(
) → Map< StatementType, int> - Count the number of usage of each StatementType by way of downward traversal.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited