findVariableDefinitions method
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.
If includeNode
is true, the starting node's own variable definitions are also included.
Otherwise, the search starts from the parent node of the starting node.
Implementation
List<DartBlockVariableDefinition> findVariableDefinitions(
int key, {
bool includeNode = false,
}) {
var containingNode = findNodeByKey(key);
if (!includeNode) {
containingNode = containingNode?.parent;
}
if (containingNode != null) {
/// We pass _getInherentVariableDefinitions() as an argument, as we want to include the inherent variable definitions
/// of the current (this) node as well.
return containingNode
._findVariableDefinitions(_getInherentVariableDefinitions())
.toSet()
.toList();
} else {
/// If the node based on the given [key] does not exist, simply return the inherent variable definitions
/// of the current (this) node, if [includeNode] is true.
if (includeNode) {
return _getInherentVariableDefinitions();
} else {
return [];
}
}
}