Skip to content

Commit

Permalink
Add class type conveniences to Annotation matching
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Jul 10, 2024
1 parent 69addbf commit 78b97b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public AnnotationMatcher(String signature, @Nullable Boolean matchesMetaAnnotati
this.matchMetaAnnotations = Boolean.TRUE.equals(matchesMetaAnnotations);
}

public AnnotationMatcher(Class<?> annotationType) {
this("@" + annotationType.getName());
if (!annotationType.isAnnotation()) {
throw new IllegalArgumentException(annotationType.getName() + " is not an annotation.");
}
}

public AnnotationMatcher(String signature) {
this(signature, false);
}
Expand All @@ -88,7 +95,7 @@ private boolean matchesAnnotationOrMetaAnnotation(@Nullable JavaType.FullyQualif
return true;
} else if (matchMetaAnnotations) {
for (JavaType.FullyQualified annotation : fqn.getAnnotations()) {
if(seenAnnotations == null) {
if (seenAnnotations == null) {
seenAnnotations = new HashSet<>();
}
if (seenAnnotations.add(annotation.getFullyQualifiedName()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public Matcher(String signature) {
this.matcher = new AnnotationMatcher(signature);
}

public Matcher(Class<?> annotationType) {
this.matcher = new AnnotationMatcher(annotationType);
}

@Override
protected @Nullable Annotated test(Cursor cursor) {
Object value = cursor.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public static Annotated.Matcher annotated(AnnotationMatcher matcher) {
public static Annotated.Matcher annotated(String signature) {
return new Annotated.Matcher(signature);
}

public static Annotated.Matcher annotated(Class<?> annotationType) {
return new Annotated.Matcher(annotationType);
}
}

0 comments on commit 78b97b5

Please sign in to comment.