ArchRule for methods which have at least one argument of a given type #1153
Answered
by
hankem
jbader-berner
asked this question in
Q&A
-
|
I looking for an ArchRule which reports all methods which have at least on String parameter ArchRule rule = methods()
.that()
.areDeclaredInClassesThat()
.areAnnotatedWith(Controller.class)
.and()
.arePublic()
.and()
// todo: search for methods which hase a String parameter (include methods which hase more then only string)
.haveRawParameterTypes(String.class)
.should()
.beAnnotatedWith(PreAuthorize.class);this method includes only methods that public void m1(String s)but the rule should also cover methods public void m1(String s1, String s2) or
public void m1(Model model, String s1)Any ideas? |
Beta Was this translation helpful? Give feedback.
Answered by
hankem
Aug 14, 2023
Replies: 1 comment
-
|
You can implement a custom predicate: static importsimport 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); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jbader-berner
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can implement a custom predicate:
static imports