Hy, I want to check that the name of all method who call some other method "post" aren't prefixed with "get", but I can only reach to method who directly call the said "post", not the ones who call one (or more) intermediate method.
Any idea?
my code so far:
methods().that().haveNameStartingWith("post")
.should()
.onlyBeCalled()
.byMethodsThat(
not(
HasName.Predicates.nameStartingWith("post")
)
).check(classes
I think that ArchUnit currently (as of ArchUnit 1.2.1) does not offer a predefined API for such a rule, but you can implement a custom
ArchConditionfor your needs.A naive solution (which may lead to duplicates and even
StackOverflowErrors) could look like this:For a proper solution, you should track which code units were already visited, similarly as done in
JavaClassTransitiveDependenciesfrom PR #401.