From cfca79182c48f18065860caa7ca51b48570460d7 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sat, 4 Mar 2023 21:11:14 +0100 Subject: [PATCH] Added relationship exclusion to context filter --- src/common/model/diagram_filter.cc | 8 ++++++-- tests/t00041/.clang-uml | 4 +++- tests/t00041/t00041.cc | 4 ++++ tests/t00041/test_case.h | 2 ++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/common/model/diagram_filter.cc b/src/common/model/diagram_filter.cc index a4bd4ec2..8e04e573 100644 --- a/src/common/model/diagram_filter.cc +++ b/src/common/model/diagram_filter.cc @@ -301,6 +301,8 @@ tvl::value_t context_filter::match(const diagram &d, const element &e) const if (d.type() != diagram_t::kClass) return {}; + // Running this filter makes sense only after the entire diagram is + // generated - i.e. during diagram generation if (!d.complete()) return {}; @@ -319,11 +321,13 @@ tvl::value_t context_filter::match(const diagram &d, const element &e) const // relationship with any of the context_root's for (const relationship &rel : context_root.value().relationships()) { - if (rel.destination() == e.id()) + if (d.should_include(rel.type()) && + rel.destination() == e.id()) return true; } for (const relationship &rel : e.relationships()) { - if (rel.destination() == context_root.value().id()) + if (d.should_include(rel.type()) && + rel.destination() == context_root.value().id()) return true; } diff --git a/tests/t00041/.clang-uml b/tests/t00041/.clang-uml index e40ae69b..502eba3f 100644 --- a/tests/t00041/.clang-uml +++ b/tests/t00041/.clang-uml @@ -17,4 +17,6 @@ diagrams: - clanguml::t00041::ns1::N exclude: namespaces: - - clanguml::t00041::detail \ No newline at end of file + - clanguml::t00041::detail + relationships: + - dependency \ No newline at end of file diff --git a/tests/t00041/t00041.cc b/tests/t00041/t00041.cc index 5204c843..b7373f6b 100644 --- a/tests/t00041/t00041.cc +++ b/tests/t00041/t00041.cc @@ -22,10 +22,14 @@ namespace detail { struct G { }; } // namespace detail +struct H { }; + struct RR : public R { E *e; F *f; detail::G *g; + + void foo(H *h) { } }; struct RRR : public RR { }; diff --git a/tests/t00041/test_case.h b/tests/t00041/test_case.h index 465c255b..d474e870 100644 --- a/tests/t00041/test_case.h +++ b/tests/t00041/test_case.h @@ -48,6 +48,7 @@ TEST_CASE("t00041", "[test-case][class]") REQUIRE_THAT(puml, IsClass(_A("RR"))); REQUIRE_THAT(puml, IsClass(_A("RRR"))); REQUIRE_THAT(puml, !IsClass(_A("detail::G"))); + REQUIRE_THAT(puml, !IsClass(_A("H"))); REQUIRE_THAT(puml, IsBaseClass(_A("R"), _A("RR"))); REQUIRE_THAT(puml, IsBaseClass(_A("RR"), _A("RRR"))); @@ -55,6 +56,7 @@ TEST_CASE("t00041", "[test-case][class]") REQUIRE_THAT(puml, IsAssociation(_A("D"), _A("RR"), "+rr")); REQUIRE_THAT(puml, IsAssociation(_A("RR"), _A("E"), "+e")); REQUIRE_THAT(puml, IsAssociation(_A("RR"), _A("F"), "+f")); + REQUIRE_THAT(puml, !IsDependency(_A("RR"), _A("H"))); REQUIRE_THAT(puml, IsClass(_A("ns1::N"))); REQUIRE_THAT(puml, IsClass(_A("ns1::NN")));