childInstanceRefOf method
The instance reference of the last of elements, with the repeat
instances given by multiplicities (other steps at multiplicity 0);
null if the controls and binds are inconsistent.
Implementation
TreeReference? childInstanceRefOf(
List<FormElement> elements,
List<int> multiplicities,
) {
if (elements.isEmpty) return null;
var ref = elements.last.bind!;
for (var i = 0; i < ref.size; i++) {
if (ref.multiplicityAt(i) != TreeReference.indexAttribute) {
ref = ref.withMultiplicity(i, 0);
}
}
for (var i = 0; i < elements.length; i++) {
final element = elements[i];
if (element is GroupDef && element.isRepeat) {
final repeatRef = element.bind!;
if (!repeatRef.isAncestorOf(ref)) return null;
ref = ref.withMultiplicity(repeatRef.size - 1, multiplicities[i]);
}
}
return ref;
}