Class Predicates

java.lang.Object
org.apache.flink.architecture.common.Predicates

public class Predicates extends Object
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 Type
    Method
    Description
    static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaClass>
     
    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 of fqClassName with the given modifiers.
    static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>
    Tests that the given field is public final, not static and has the given fully qualified type name of fqClassName.
    static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>
    arePublicFinalOfTypeWithAnnotation(String fqClassName, Class<? extends Annotation> annotationType)
    Tests that the field is public final, has the fully qualified type name of fqClassName and is annotated with the annotationType.
    static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>
    Tests that the given field is public static final and is assignable to the given type clazz .
    static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>
    Tests that the field is public static final and has the fully qualified type name of fqClassName.
    static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>
    arePublicStaticFinalOfTypeWithAnnotation(String fqClassName, Class<? extends Annotation> annotationType)
    Tests that the field is public static final, has the fully qualified type name of fqClassName and is annotated with the annotationType.
    static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>
    Tests that the given field is public static and has the fully qualified type name of fqClassName.
    static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField>
    areStaticFinalOfTypeWithAnnotation(String fqClassName, Class<? extends Annotation> annotationType)
    Tests that the field is static final, has the fully qualified type name of fqClassName and is annotated with the annotationType.
    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 a DescribedPredicate that returns true if one and only one of the given predicates match.
    static String
    Extracts the class name from the given fully qualified class name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 DescribedPredicate returning true, if and only if the predicate JavaField could be found in the JavaClass.
    • arePublicStaticOfType

      public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticOfType(String fqClassName)
      Tests that the given field is public static and has the fully qualified type name of fqClassName.

      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 of fqClassName with 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 is public final, not static and has the given fully qualified type name of fqClassName.
    • arePublicStaticFinalAssignableTo

      public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalAssignableTo(Class<?> clazz)
      Tests that the given field is public static final and is assignable to the given type clazz .
    • arePublicStaticFinalOfType

      public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalOfType(String fqClassName)
      Tests that the field is public static final and has the fully qualified type name of fqClassName.
    • 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 is public final, has the fully qualified type name of fqClassName and is annotated with the annotationType.
    • 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 is public static final, has the fully qualified type name of fqClassName and is annotated with the annotationType.
    • 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 is static final, has the fully qualified type name of fqClassName and is annotated with the annotationType. 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 a DescribedPredicate that returns true if one and only one of the given predicates match.
    • getClassSimpleNameFromFqName

      public static String getClassSimpleNameFromFqName(String fqClassName)
      Extracts the class name from the given fully qualified class name.

      Example:

           getClassFromFqName("com.example.MyClass");  // Returns: "MyClass"