isStructSame method
Returns true if this definition has the same structure as other.
Implementation
bool isStructSame(ValueDef other, {bool debug = false}) {
if (childrenDef is List<ValueDef> && other.childrenDef is List<ValueDef>) {
var thisList = childrenDef as List<ValueDef>;
var otherList = other.childrenDef as List<ValueDef>;
if (thisList.isEmpty || otherList.isEmpty) {
return thisList.isEmpty && otherList.isEmpty;
}
return thisList.first.isStructSame(otherList.first);
} else if (childrenDef is Map<String, ValueDef> &&
other.childrenDef is Map<String, ValueDef>) {
Iterable<MapEntry<String, ValueDef>> thisKeyList =
(childrenDef as Map<String, ValueDef>).entries;
Iterable<MapEntry<String, ValueDef>> otherKeyList =
(other.childrenDef as Map<String, ValueDef>).entries;
var isLengthSame = thisKeyList.length == otherKeyList.length;
if (isLengthSame) {
bool isSame = !thisKeyList.any((element) {
String thisKey = element.key;
ValueDef thisValue = element.value;
MapEntry<String, ValueDef>? findOther = otherKeyList.firstWhereOrNull(
(element) => element.key == thisKey,
);
if (findOther != null) {
bool isSame = thisValue.isStructSame(findOther.value);
return !isSame;
} else {
return true;
}
});
return isSame;
}
} else if (type == other.type && key == other.key) {
return true;
}
return false;
}