Class ConfigAnnotationUtil


  • public final class ConfigAnnotationUtil
    extends Object
    Common functions for resolving OSGi config test parameters.
    • Method Detail

      • findConfigTypeAnnotations

        public static Stream<Annotation> findConfigTypeAnnotations​(@NotNull
                                                                   @NotNull AnnotatedElement element)
        Find candidate OSGi config annotations on the given AnnotatedElement, returning a stream of only those matching one of the desired config types. An annotation matches a config type only if the annotation's own type is the same as the config type, or if the annotation is a ConfigType and its ConfigType.type() is the same as the config type. If the AnnotatedElement has a ConfigTypes annotation, its nested ConfigType annotations will be considered as well.
        Parameters:
        element - the annotated element
        Returns:
        a stream of annotations
      • findConfigTypeAnnotations

        public static Stream<Annotation> findConfigTypeAnnotations​(@NotNull
                                                                   @NotNull AnnotatedElement element,
                                                                   @Nullable
                                                                   @Nullable ConfigAnnotationUtil.ConfigTypePredicate configTypePredicate)
        Find candidate OSGi config annotations on the given AnnotatedElement, returning a stream of only those matching one of the desired config types. An annotation matches a config type only if the annotation's own type is the same as the config type, or if the annotation is a ConfigType and its ConfigType.type() is the same as the config type. If the AnnotatedElement has a ConfigTypes annotation, its nested ConfigType annotations will be considered as well.
        Parameters:
        element - the annotated element
        configTypePredicate - an optional subsequent predicate for the applicable configType
        Returns:
        a stream of annotations
      • findConfigTypeAnnotations

        public static Stream<Annotation> findConfigTypeAnnotations​(@NotNull
                                                                   @NotNull Collection<Annotation> annotations)
        Find candidate OSGi config annotations in the given collection, returning a stream of only those matching one of the desired config types. An annotation matches a config type only if the annotation's own type is the same as the config type, or if the annotation is a ConfigType and its ConfigType.type() is the same as the config type. If the collection has a ConfigTypes annotation, its nested ConfigType annotations will be considered as well.
        Parameters:
        annotations - a collection of annotations
        Returns:
        a stream of annotations
      • findConfigTypeAnnotations

        public static Stream<Annotation> findConfigTypeAnnotations​(@NotNull
                                                                   @NotNull Collection<Annotation> annotations,
                                                                   @Nullable
                                                                   @Nullable ConfigAnnotationUtil.ConfigTypePredicate configTypePredicate)
        Find candidate OSGi config annotations in the given collection, returning a stream of only those matching one of the desired config types. An annotation matches a config type only if the annotation's own type is the same as the config type, or if the annotation is a ConfigType and its ConfigType.type() is the same as the config type. If the collection has a ConfigTypes annotation, its nested ConfigType annotations will be considered as well.
        Parameters:
        annotations - a collection of annotations
        configTypePredicate - an optional subsequent predicate for the applicable configType
        Returns:
        a stream of annotations
      • findUpdateConfigAnnotations

        public static Stream<SetConfig> findUpdateConfigAnnotations​(@NotNull
                                                                    @NotNull Collection<Annotation> annotations)
        Find SetConfig annotations in the given collection. If the collection has an SetConfigs annotation, its nested SetConfig annotations will be included as well.
        Parameters:
        annotations - a collection of annotations
        Returns:
        a stream of annotations
      • isValidConfigType

        public static boolean isValidConfigType​(@NotNull
                                                @NotNull Class<?> configType)
        Utility function for filtering out component property types that can't be mapped to configurations.
        Parameters:
        configType - Config type
        Returns:
        true if the provided class is a valid config type
      • determineSupportedConfigType

        public static Optional<Class<?>> determineSupportedConfigType​(@NotNull
                                                                      @NotNull Class<?> type)
        Return the appropriate config type for the given test parameter type, if it supported for binding. If the provided type is an array, the array's component type will be returned if it is a supported type.
        Parameters:
        type - the candidate parameter type
        Returns:
        an optional containing a supported config type, or empty if not supported.
      • resolveParameterToArray

        public static <T> T[] resolveParameterToArray​(@NotNull
                                                      @NotNull ConfigCollection configCollection,
                                                      @NotNull
                                                      @NotNull Class<T> configType)
        Returns an array of configs matching the specified parameter config type.
        Type Parameters:
        T - the desired config type
        Parameters:
        configCollection - the config collection
        configType - the parameter config type class
        Returns:
        an array of matching configs
      • resolveParameterToTypedConfig

        public static <T> Optional<TypedConfig<T>> resolveParameterToTypedConfig​(@NotNull
                                                                                 @NotNull ConfigCollection configCollection,
                                                                                 @NotNull
                                                                                 @NotNull Class<T> parameterConfigType,
                                                                                 @NotNull
                                                                                 @NotNull Class<?>[] signatureParameterTypes,
                                                                                 int parameterIndex)
        Returns the first TypedConfig from the ConfigCollection, if present, after skipping the same number of values as there are matching signature parameter types with an index lower than the current parameterIndex. For example, if we are injecting values into a test method signature that accepts two MyConfig arguments, this method will be called twice for the same configCollection, parameterConfigType, and signatureParameterTypes array. The first call will specify a parameterIndex of 0, which will return the first value from the collection, and the second call will specify a parameterIndex of 1 which will return the second value from the collection. This method does not consider array or ConfigCollection parameter types when skipping values.
        Type Parameters:
        T - the parameter config type
        Parameters:
        configCollection - the config collection
        parameterConfigType - the parameter config type class (must be an interface or an annotation type)
        signatureParameterTypes - the types of the signature's parameters
        parameterIndex - the 0-based index of the parameter in the executable's signature
        Returns:
        a single parameter value if available, or empty
      • resolveParameterToValue

        public static <T> Optional<T> resolveParameterToValue​(@NotNull
                                                              @NotNull ConfigCollection configCollection,
                                                              @NotNull
                                                              @NotNull Class<T> parameterConfigType,
                                                              @NotNull
                                                              @NotNull Class<?>[] signatureParameterTypes,
                                                              int parameterIndex)
        Returns the first config value from the ConfigCollection, if present, after skipping the same number of values as there are matching signature parameter types with an index lower than the current parameterIndex. For example, if we are injecting values into a test method signature that accepts two MyConfig arguments, this method will be called twice for the same configCollection, parameterConfigType, and signatureParameterTypes array. The first call will specify a parameterIndex of 0, which will return the first value from the collection, and the second call will specify a parameterIndex of 1 which will return the second value from the collection. This method does not consider array or ConfigCollection parameter types when skipping values.
        Type Parameters:
        T - the parameter config type
        Parameters:
        configCollection - the config collection
        parameterConfigType - the parameter config type class (must be an interface or an annotation type)
        signatureParameterTypes - the types of the signature's parameters
        parameterIndex - the 0-based index of the parameter in the executable's signature
        Returns:
        a single parameter value if available, or empty
      • resolveParameterToConfigMap

        public static <T> Optional<Map<String,​Object>> resolveParameterToConfigMap​(@NotNull
                                                                                         @NotNull ConfigCollection configCollection,
                                                                                         @NotNull
                                                                                         @NotNull Class<T> parameterConfigType,
                                                                                         @NotNull
                                                                                         @NotNull Class<?>[] signatureParameterTypes,
                                                                                         int parameterIndex)
        Returns the first config map from the ConfigCollection, if present, after skipping the same number of values as there are matching signature parameter types with an index lower than the current parameterIndex. For example, if we are injecting values into a test method signature that accepts two MyConfig arguments, this method will be called twice for the same configCollection, parameterConfigType, and signatureParameterTypes array. The first call will specify a parameterIndex of 0, which will return the first value from the collection, and the second call will specify a parameterIndex of 1 which will return the second value from the collection. This method does not consider array or ConfigCollection parameter types when skipping values.
        Type Parameters:
        T - the parameter config type
        Parameters:
        configCollection - the config collection
        parameterConfigType - the parameter config type class (must be an interface or an annotation type)
        signatureParameterTypes - the types of the signature's parameters
        parameterIndex - the 0-based index of the parameter in the executable's signature
        Returns:
        a single parameter value if available, or empty