Class Predicates
java.lang.Object
org.apache.flink.architecture.common.Predicates
Common predicates for architecture tests.
NOTE: it is recommended to use methods that accept fully qualified class names instead of
Class objects to reduce the risks of introducing circular dependencies between the
project submodules.
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaClass>areDirectlyAnnotatedWithAtLeastOneOf(Class<? extends Annotation>... annotations) static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>areFieldOfType(String fqClassName, com.tngtech.archunit.core.domain.JavaModifier... modifiers) Tests that the field has the fully qualified type offqClassNamewith the given modifiers.static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>arePublicFinalOfType(String fqClassName) Tests that the given field ispublic final, notstaticand has the given fully qualified type name offqClassName.static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>arePublicFinalOfTypeWithAnnotation(String fqClassName, Class<? extends Annotation> annotationType) Tests that the field ispublic final, has the fully qualified type name offqClassNameand is annotated with theannotationType.static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>arePublicStaticFinalAssignableTo(Class<?> clazz) Tests that the given field ispublic static finaland is assignable to the given typeclazz.static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>arePublicStaticFinalOfType(String fqClassName) Tests that the field ispublic static finaland has the fully qualified type name offqClassName.static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>arePublicStaticFinalOfTypeWithAnnotation(String fqClassName, Class<? extends Annotation> annotationType) Tests that the field ispublic static final, has the fully qualified type name offqClassNameand is annotated with theannotationType.static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>arePublicStaticOfType(String fqClassName) Tests that the given field ispublic staticand has the fully qualified type name offqClassName.static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>areStaticFinalOfTypeWithAnnotation(String fqClassName, Class<? extends Annotation> annotationType) Tests that the field isstatic final, has the fully qualified type name offqClassNameand is annotated with theannotationType.static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaClass>containAnyFieldsInClassHierarchyThat(com.tngtech.archunit.base.DescribedPredicate<? super com.tngtech.archunit.core.domain.JavaField> predicate) static <T> com.tngtech.archunit.base.DescribedPredicate<T>exactlyOneOf(com.tngtech.archunit.base.DescribedPredicate<? super T>... other) Returns aDescribedPredicatethat returns true if one and only one of the given predicates match.static StringgetClassSimpleNameFromFqName(String fqClassName) Extracts the class name from the given fully qualified class name.
-
Method Details
-
areDirectlyAnnotatedWithAtLeastOneOf
@SafeVarargs public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaClass> areDirectlyAnnotatedWithAtLeastOneOf(Class<? extends Annotation>... annotations) -
containAnyFieldsInClassHierarchyThat
public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaClass> containAnyFieldsInClassHierarchyThat(com.tngtech.archunit.base.DescribedPredicate<? super com.tngtech.archunit.core.domain.JavaField> predicate) - Returns:
- A
DescribedPredicatereturning true, if and only if the predicateJavaFieldcould be found in theJavaClass.
-
arePublicStaticOfType
public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticOfType(String fqClassName) Tests that the given field ispublic staticand has the fully qualified type name offqClassName.Attention: changing the description will add a rule into the stored.rules.
-
areFieldOfType
public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> areFieldOfType(String fqClassName, com.tngtech.archunit.core.domain.JavaModifier... modifiers) Tests that the field has the fully qualified type offqClassNamewith the given modifiers.Attention: changing the description will add a rule into the stored.rules.
-
arePublicFinalOfType
public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicFinalOfType(String fqClassName) Tests that the given field ispublic final, notstaticand has the given fully qualified type name offqClassName. -
arePublicStaticFinalAssignableTo
public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalAssignableTo(Class<?> clazz) Tests that the given field ispublic static finaland is assignable to the given typeclazz. -
arePublicStaticFinalOfType
public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalOfType(String fqClassName) Tests that the field ispublic static finaland has the fully qualified type name offqClassName. -
arePublicFinalOfTypeWithAnnotation
public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicFinalOfTypeWithAnnotation(String fqClassName, Class<? extends Annotation> annotationType) Tests that the field ispublic final, has the fully qualified type name offqClassNameand is annotated with theannotationType. -
arePublicStaticFinalOfTypeWithAnnotation
public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalOfTypeWithAnnotation(String fqClassName, Class<? extends Annotation> annotationType) Tests that the field ispublic static final, has the fully qualified type name offqClassNameand is annotated with theannotationType. -
areStaticFinalOfTypeWithAnnotation
public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> areStaticFinalOfTypeWithAnnotation(String fqClassName, Class<? extends Annotation> annotationType) Tests that the field isstatic final, has the fully qualified type name offqClassNameand is annotated with theannotationType. It doesn't matter if public, private or protected. -
exactlyOneOf
@SafeVarargs public static <T> com.tngtech.archunit.base.DescribedPredicate<T> exactlyOneOf(com.tngtech.archunit.base.DescribedPredicate<? super T>... other) Returns aDescribedPredicatethat returns true if one and only one of the given predicates match. -
getClassSimpleNameFromFqName
Extracts the class name from the given fully qualified class name.Example:
getClassFromFqName("com.example.MyClass"); // Returns: "MyClass"
-