Swift: fix ParentChild generation

There was an issue in case multiple inheritance from classes with
children was involved, where indexes would overlap.

The generated code structure has been reshuffled a bit, with
`Impl::getImmediateChildOf<Class>` predicates giving 0-based children
for a given class, including those coming from bases, and the final
`Impl::getImmediateChild` disjuncting the above on final classes only.

This removes the need of `getMaximumChildrenIndex<Class>`, and also
removes the code scanning alerts.

Also, comments were fixed addressing the review.
This commit is contained in:
Paolo Tranquilli
2022-08-30 10:15:11 +02:00
parent 3f4a330658
commit beb0472811
7 changed files with 4823 additions and 1817 deletions

View File

@@ -78,9 +78,9 @@ def test_property_predicate_getter():
assert prop.getter == "prop"
def test_class_sorts_bases():
def test_class_processes_bases():
bases = ["B", "Ab", "C", "Aa"]
expected = ["Aa", "Ab", "B", "C"]
expected = [ql.Base("Aa"), ql.Base("Ab", prev="Aa"), ql.Base("B", prev="Ab"), ql.Base("C", prev="B")]
cls = ql.Class("Foo", bases=bases)
assert cls.bases == expected

View File

@@ -357,6 +357,13 @@ def test_class_dir(generate_classes):
}
def test_root_element_cannot_have_children(generate_classes):
with pytest.raises(qlgen.RootElementHasChildren):
generate_classes([
schema.Class(schema.root_class_name, properties=[schema.SingleProperty("x", is_child=True)])
])
def test_class_dir_imports(generate_import_list):
dir = pathlib.Path("another/rel/path")
assert generate_import_list([