diff --git a/archunit/src/main/java/com/tngtech/archunit/core/domain/properties/CanBeAnnotated.java b/archunit/src/main/java/com/tngtech/archunit/core/domain/properties/CanBeAnnotated.java index 9a21d67350..b87748717a 100644 --- a/archunit/src/main/java/com/tngtech/archunit/core/domain/properties/CanBeAnnotated.java +++ b/archunit/src/main/java/com/tngtech/archunit/core/domain/properties/CanBeAnnotated.java @@ -35,21 +35,60 @@ import static com.tngtech.archunit.core.domain.properties.HasType.Functions.GET_RAW_TYPE; public interface CanBeAnnotated { + + /** + * Returns {@code true}, if this element is annotated with the given annotation type. + * + * @param annotationType The type of the annotation to check for + */ @PublicAPI(usage = ACCESS) boolean isAnnotatedWith(Class annotationType); + /** + * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} + * @see #isAnnotatedWith(Class) + */ @PublicAPI(usage = ACCESS) boolean isAnnotatedWith(String annotationTypeName); + /** + * Returns {@code true}, if this element is annotated with an annotation matching the given predicate. + * + * @param predicate Qualifies matching annotations + */ @PublicAPI(usage = ACCESS) boolean isAnnotatedWith(DescribedPredicate> predicate); + /** + * Returns {@code true}, if this element is meta-annotated with the given annotation type. + * A meta-annotation is an annotation that is declared on another annotation. + * + *

+ * This method also returns {@code true} if this element is directly annotated with the given annotation type. + *

+ * + * @param annotationType The type of the annotation to check for + */ @PublicAPI(usage = ACCESS) boolean isMetaAnnotatedWith(Class annotationType); + /** + * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} + * @see #isMetaAnnotatedWith(Class) + */ @PublicAPI(usage = ACCESS) boolean isMetaAnnotatedWith(String annotationTypeName); + /** + * Returns {@code true}, if this element is meta-annotated with an annotation matching the given predicate. + * A meta-annotation is an annotation that is declared on another annotation. + * + *

+ * This method also returns {@code true} if this element is directly annotated with an annotation matching the given predicate. + *

+ * + * @param predicate Qualifies matching annotations + */ @PublicAPI(usage = ACCESS) boolean isMetaAnnotatedWith(DescribedPredicate> predicate); @@ -57,6 +96,11 @@ final class Predicates { private Predicates() { } + /** + * Returns a predicate that matches elements that are annotated with the given annotation type. + * + * @param annotationType The type of the annotation to check for + */ @PublicAPI(usage = ACCESS) public static DescribedPredicate annotatedWith(final Class annotationType) { checkAnnotationHasReasonableRetention(annotationType); @@ -78,12 +122,21 @@ private static boolean isRetentionSource(Class annotationT && (annotationType.getAnnotation(Retention.class).value() == RetentionPolicy.SOURCE); } + /** + * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} + * @see #annotatedWith(Class) + */ @PublicAPI(usage = ACCESS) public static DescribedPredicate annotatedWith(final String annotationTypeName) { DescribedPredicate typeNameMatches = GET_RAW_TYPE.then(GET_NAME).is(equalTo(annotationTypeName)); return annotatedWith(typeNameMatches.as("@" + ensureSimpleName(annotationTypeName))); } + /** + * Returns a predicate that matches elements that are annotated with an annotation matching the given predicate. + * + * @param predicate Qualifies matching annotations + */ @PublicAPI(usage = ACCESS) public static DescribedPredicate annotatedWith(final DescribedPredicate> predicate) { return new AnnotatedPredicate(predicate); @@ -103,6 +156,16 @@ public boolean apply(CanBeAnnotated input) { } } + /** + * Returns a predicate that matches elements that are meta-annotated with the given annotation type. + * A meta-annotation is an annotation that is declared on another annotation. + * + *

+ * The returned predicate also matches elements that are directly annotated with the given annotation type. + *

+ * + * @param annotationType The type of the annotation to check for + */ @PublicAPI(usage = ACCESS) public static DescribedPredicate metaAnnotatedWith(final Class annotationType) { checkAnnotationHasReasonableRetention(annotationType); @@ -110,12 +173,25 @@ public static DescribedPredicate metaAnnotatedWith(final Class metaAnnotatedWith(final String annotationTypeName) { DescribedPredicate typeNameMatches = GET_RAW_TYPE.then(GET_NAME).is(equalTo(annotationTypeName)); return metaAnnotatedWith(typeNameMatches.as("@" + ensureSimpleName(annotationTypeName))); } + /** + * Returns a predicate that matches elements that are meta-annotated with an annotation matching the given predicate. + * A meta-annotation is an annotation that is declared on another annotation. + * + *

+ * The returned predicate also matches elements that are directly annotated with the given annotation type. + *

+ * + * @param predicate Qualifies matching annotations + */ @PublicAPI(usage = ACCESS) public static DescribedPredicate metaAnnotatedWith(final DescribedPredicate> predicate) { return new MetaAnnotatedPredicate(predicate); diff --git a/archunit/src/main/java/com/tngtech/archunit/lang/conditions/ArchConditions.java b/archunit/src/main/java/com/tngtech/archunit/lang/conditions/ArchConditions.java index 08d8eb56a8..ce5436ebb6 100644 --- a/archunit/src/main/java/com/tngtech/archunit/lang/conditions/ArchConditions.java +++ b/archunit/src/main/java/com/tngtech/archunit/lang/conditions/ArchConditions.java @@ -50,6 +50,7 @@ import com.tngtech.archunit.core.domain.JavaMethod; import com.tngtech.archunit.core.domain.JavaMethodCall; import com.tngtech.archunit.core.domain.JavaModifier; +import com.tngtech.archunit.core.domain.properties.CanBeAnnotated; import com.tngtech.archunit.core.domain.properties.HasAnnotations; import com.tngtech.archunit.core.domain.properties.HasModifiers; import com.tngtech.archunit.core.domain.properties.HasName; @@ -715,72 +716,108 @@ public static ArchCondition haveOnlyPrivateConstructors() { return new HaveOnlyModifiersCondition<>("private constructors", PRIVATE, GET_CONSTRUCTORS); } + /** + * @return a condition matching elements analogously to {@link CanBeAnnotated.Predicates#annotatedWith(Class)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition beAnnotatedWith( Class type) { return new IsConditionByPredicate<>(annotatedWith(type)); } + /** + * @return negation of {@link #beAnnotatedWith(Class)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition notBeAnnotatedWith( Class type) { return not(ArchConditions.beAnnotatedWith(type)); } + /** + * @return a condition matching elements analogously to {@link CanBeAnnotated.Predicates#annotatedWith(String)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition beAnnotatedWith( String typeName) { return new IsConditionByPredicate<>(annotatedWith(typeName)); } + /** + * @return negation of {@link #beAnnotatedWith(String)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition notBeAnnotatedWith( String typeName) { return not(ArchConditions.beAnnotatedWith(typeName)); } + /** + * @return a condition matching elements analogously to {@link CanBeAnnotated.Predicates#annotatedWith(DescribedPredicate)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition beAnnotatedWith( final DescribedPredicate> predicate) { return new IsConditionByPredicate<>(annotatedWith(predicate)); } + /** + * @return negation of {@link #beAnnotatedWith(DescribedPredicate)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition notBeAnnotatedWith( DescribedPredicate> predicate) { return not(ArchConditions.beAnnotatedWith(predicate)); } + /** + * @return a condition matching elements analogously to {@link CanBeAnnotated.Predicates#metaAnnotatedWith(Class)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition beMetaAnnotatedWith( Class type) { return new IsConditionByPredicate<>(metaAnnotatedWith(type)); } + /** + * @return negation of {@link #beMetaAnnotatedWith(Class)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition notBeMetaAnnotatedWith( Class type) { return not(ArchConditions.beMetaAnnotatedWith(type)); } + /** + * @return a condition matching elements analogously to {@link CanBeAnnotated.Predicates#metaAnnotatedWith(String)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition beMetaAnnotatedWith( String typeName) { return new IsConditionByPredicate<>(metaAnnotatedWith(typeName)); } + /** + * @return negation of {@link #beMetaAnnotatedWith(String)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition notBeMetaAnnotatedWith( String typeName) { return not(ArchConditions.beMetaAnnotatedWith(typeName)); } + /** + * @return a condition matching elements analogously to {@link CanBeAnnotated.Predicates#metaAnnotatedWith(DescribedPredicate)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition beMetaAnnotatedWith( final DescribedPredicate> predicate) { return new IsConditionByPredicate<>(metaAnnotatedWith(predicate)); } + /** + * @return negation of {@link #beMetaAnnotatedWith(DescribedPredicate)} + */ @PublicAPI(usage = ACCESS) public static & HasDescription & HasSourceCodeLocation> ArchCondition notBeMetaAnnotatedWith( DescribedPredicate> predicate) { diff --git a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShould.java b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShould.java index 5fc3c8b4b6..841281fc75 100644 --- a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShould.java +++ b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesShould.java @@ -342,6 +342,10 @@ public interface ClassesShould { * Asserts that classes are meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * The assertion is also successful if classes are directly annotated with the supplied annotation type. + *

+ * * @param annotationType Specific type of {@link Annotation} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -352,6 +356,10 @@ public interface ClassesShould { * Asserts that classes are not meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * The assertion also fails if classes are directly annotated with the supplied annotation type. + *

+ * * @param annotationType Specific type of {@link Annotation} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -362,6 +370,10 @@ public interface ClassesShould { * Asserts that classes are meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * The assertion is also successful if classes are directly annotated with the supplied annotation type. + *

+ * * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -372,6 +384,10 @@ public interface ClassesShould { * Asserts that classes are not meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * The assertion also fails if classes are directly annotated with the supplied annotation type. + *

+ * * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -382,6 +398,10 @@ public interface ClassesShould { * Asserts that classes are meta-annotated with a certain annotation, where matching meta-annotations are * determined by the supplied predicate. A meta-annotation is an annotation that is declared on another annotation. * + *

+ * The assertion is also successful if classes are directly annotated with an annotation matching the supplied predicate. + *

+ * * @param predicate A predicate defining matching {@link JavaAnnotation JavaAnnotations} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -392,6 +412,10 @@ public interface ClassesShould { * Asserts that classes are not meta-annotated with a certain annotation, where matching meta-annotations are * determined by the supplied predicate. A meta-annotation is an annotation that is declared on another annotation. * + *

+ * The assertion also fails if classes are directly annotated with an annotation matching the supplied predicate. + *

+ * * @param predicate A predicate defining matching {@link JavaAnnotation JavaAnnotations} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ diff --git a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesThat.java b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesThat.java index bbf656c5bc..34c5970c70 100644 --- a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesThat.java +++ b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/ClassesThat.java @@ -318,6 +318,10 @@ public interface ClassesThat { * Matches classes meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * This also matches classes that are directly annotated with the supplied annotation type. + *

+ * * @param annotationType Specific type of {@link Annotation} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -328,6 +332,10 @@ public interface ClassesThat { * Matches classes not meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * Matching classes may also not directly be annotated with the supplied annotation type. + *

+ * * @param annotationType Specific type of {@link Annotation} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -338,6 +346,10 @@ public interface ClassesThat { * Matches classes meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * This also matches classes that are directly annotated with the supplied annotation type. + *

+ * * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -348,6 +360,10 @@ public interface ClassesThat { * Matches classes not meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * Matching classes may also not directly be annotated with the supplied annotation type. + *

+ * * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -359,6 +375,10 @@ public interface ClassesThat { * determined by the supplied predicate. A meta-annotation is an annotation that is declared on * another annotation. * + *

+ * This also matches classes where a direct annotation matches the supplied predicate. + *

+ * * @param predicate A predicate defining matching {@link JavaAnnotation JavaAnnotations} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -370,6 +390,10 @@ public interface ClassesThat { * determined by the supplied predicate. A meta-annotation is an annotation that is declared on * another annotation. * + *

+ * Matching classes may also not be annotated with a direct annotation matching the supplied predicate. + *

+ * * @param predicate A predicate defining matching {@link JavaAnnotation JavaAnnotations} * @return A syntax conjunction element, which can be completed to form a full rule */ diff --git a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/MembersShould.java b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/MembersShould.java index 5a9da4f818..92ea05df23 100644 --- a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/MembersShould.java +++ b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/MembersShould.java @@ -299,6 +299,10 @@ public interface MembersShould> * Asserts that members are meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * The assertion is also successful if members are directly annotated with the supplied annotation type. + *

+ * * @param annotationType Specific type of {@link Annotation} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -309,6 +313,10 @@ public interface MembersShould> * Asserts that members are not meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * The assertion also fails if members are directly annotated with the supplied annotation type. + *

+ * * @param annotationType Specific type of {@link Annotation} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -319,6 +327,10 @@ public interface MembersShould> * Asserts that members are meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * The assertion is also successful if members are directly annotated with the supplied annotation type. + *

+ * * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -329,6 +341,10 @@ public interface MembersShould> * Asserts that members are not meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * The assertion also fails if members are directly annotated with the supplied annotation type. + *

+ * * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -339,6 +355,10 @@ public interface MembersShould> * Asserts that members are meta-annotated with an annotation matching the supplied predicate. * A meta-annotation is an annotation that is declared on another annotation. * + *

+ * The assertion is also successful if members are directly annotated with an annotation matching the supplied predicate. + *

+ * * @param predicate A predicate defining matching {@link JavaAnnotation JavaAnnotations} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ @@ -349,6 +369,10 @@ public interface MembersShould> * Asserts that members are not meta-annotated with an annotation matching the supplied predicate. * A meta-annotation is an annotation that is declared on another annotation. * + *

+ * The assertion also fails if members are directly annotated with an annotation matching the supplied predicate. + *

+ * * @param predicate A predicate defining matching {@link JavaAnnotation JavaAnnotations} * @return A syntax element that can either be used as working rule, or to continue specifying a more complex rule */ diff --git a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/MembersThat.java b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/MembersThat.java index c099751527..1e8370e634 100644 --- a/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/MembersThat.java +++ b/archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/MembersThat.java @@ -297,6 +297,10 @@ public interface MembersThat { * Matches members meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * This also matches members that are directly annotated with the supplied annotation type. + *

+ * * @param annotationType Specific type of {@link Annotation} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -307,6 +311,10 @@ public interface MembersThat { * Matches members not meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * Matching members may also not directly be annotated with the supplied annotation type. + *

+ * * @param annotationType Specific type of {@link Annotation} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -317,6 +325,10 @@ public interface MembersThat { * Matches members meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * This also matches members that are directly annotated with the supplied annotation type. + *

+ * * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -327,6 +339,10 @@ public interface MembersThat { * Matches members not meta-annotated with a certain type of annotation. A meta-annotation is * an annotation that is declared on another annotation. * + *

+ * Matching members may also not directly be annotated with the supplied annotation type. + *

+ * * @param annotationTypeName Fully qualified class name of a specific type of {@link Annotation} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -338,6 +354,10 @@ public interface MembersThat { * determined by the supplied predicate. A meta-annotation is an annotation that is declared on * another annotation. * + *

+ * This also matches members where a direct annotation matches the supplied predicate. + *

+ * * @param predicate A predicate defining matching {@link JavaAnnotation JavaAnnotations} * @return A syntax conjunction element, which can be completed to form a full rule */ @@ -349,6 +369,10 @@ public interface MembersThat { * determined by the supplied predicate. A meta-annotation is an annotation that is declared on * another annotation. * + *

+ * Matching members may also not be annotated with a direct annotation matching the supplied predicate. + *

+ * * @param predicate A predicate defining matching {@link JavaAnnotation JavaAnnotations} * @return A syntax conjunction element, which can be completed to form a full rule */