explodeReference method

List<TreeElement>? explodeReference(
  1. TreeReference ref
)

The elements along ref, excluding the base and the final node; null if any step can't be resolved.

Implementation

List<TreeElement>? explodeReference(TreeReference ref) {
  if (!ref.isAbsolute) return null;
  final nodes = <TreeElement>[];
  var current = base;
  for (var i = 0; i < ref.size; i++) {
    final name = ref.nameAt(i);
    var multiplicity = ref.multiplicityAt(i);
    if (!identical(current, base)) nodes.add(current);
    if (multiplicity == TreeReference.indexAttribute) {
      final attribute = current.getAttribute(null, name);
      if (attribute == null) return nodes;
      current = attribute;
      continue;
    }
    if (multiplicity == TreeReference.indexUnbound) {
      if (current.childMultiplicity(name) != 1) return null;
      multiplicity = 0;
    }
    final child = current.getChild(name, multiplicity);
    if (child == null) return null;
    current = child;
  }
  return nodes;
}