Skip to content

ArchRule for methods which have at least one argument of a given type #1153

Answered by hankem
jbader548 asked this question in Q&A
Discussion options

You must be logged in to vote

You can implement a custom predicate:

static imports
import static com.tngtech.archunit.base.DescribedPredicate.describe;
import static com.tngtech.archunit.lang.conditions.ArchPredicates.have;
    ArchRule rule = methods()
            .that().areDeclaredInClassesThat().areAnnotatedWith(Controller.class)
            .and().arePublic()
            .and(have(describe("at least one String parameter", method ->
                    method.getRawParameterTypes().stream().anyMatch(parameter -> parameter.isEquivalentTo(String.class))
            )))
            .should().beAnnotatedWith(PreAuthorize.class);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jbader548
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants