Search in sources :

Example 1 with ConfigValue

use of org.apache.ignite.configuration.annotation.ConfigValue in project ignite-3 by apache.

the class Processor method getInterfaceGetMethodType.

/**
 * Get types for configuration classes generation.
 *
 * @param field Field.
 * @return Bundle with all types for configuration
 */
private static TypeName getInterfaceGetMethodType(VariableElement field) {
    TypeName interfaceGetMethodType = null;
    TypeName baseType = TypeName.get(field.asType());
    ConfigValue confAnnotation = field.getAnnotation(ConfigValue.class);
    if (confAnnotation != null) {
        interfaceGetMethodType = Utils.getConfigurationInterfaceName((ClassName) baseType);
    }
    NamedConfigValue namedConfigAnnotation = field.getAnnotation(NamedConfigValue.class);
    if (namedConfigAnnotation != null) {
        ClassName interfaceGetType = Utils.getConfigurationInterfaceName((ClassName) baseType);
        TypeName viewClassType = Utils.getViewName((ClassName) baseType);
        TypeName changeClassType = Utils.getChangeName((ClassName) baseType);
        interfaceGetMethodType = ParameterizedTypeName.get(ClassName.get(NamedConfigurationTree.class), interfaceGetType, viewClassType, changeClassType);
    }
    Value valueAnnotation = field.getAnnotation(Value.class);
    PolymorphicId polymorphicIdAnnotation = field.getAnnotation(PolymorphicId.class);
    InjectedName injectedNameAnnotation = field.getAnnotation(InjectedName.class);
    InternalId internalIdAnnotation = field.getAnnotation(InternalId.class);
    if (valueAnnotation != null || polymorphicIdAnnotation != null || injectedNameAnnotation != null || internalIdAnnotation != null) {
        // It is necessary to use class names without loading classes so that we won't
        // accidentally get NoClassDefFoundError
        ClassName confValueClass = ClassName.get("org.apache.ignite.configuration", "ConfigurationValue");
        TypeName genericType = baseType;
        if (genericType.isPrimitive()) {
            genericType = genericType.box();
        }
        interfaceGetMethodType = ParameterizedTypeName.get(confValueClass, genericType);
    }
    return interfaceGetMethodType;
}
Also used : NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) TypeName(com.squareup.javapoet.TypeName) WildcardTypeName(com.squareup.javapoet.WildcardTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) InternalId(org.apache.ignite.configuration.annotation.InternalId) InjectedName(org.apache.ignite.configuration.annotation.InjectedName) ClassName(com.squareup.javapoet.ClassName) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) Value(org.apache.ignite.configuration.annotation.Value)

Example 2 with ConfigValue

use of org.apache.ignite.configuration.annotation.ConfigValue in project ignite-3 by apache.

the class ConfigurationUtil method collectSchemas.

/**
 * Collect all configuration schemas with {@link ConfigurationRoot}, {@link Config} or {@link PolymorphicConfig} including all sub
 * configuration schemas for fields with {@link ConfigValue} or {@link NamedConfigValue}.
 *
 * @param schemaClasses Configuration schemas (starting points) with {@link ConfigurationRoot}, {@link Config} or {@link
 *                      PolymorphicConfig}.
 * @return All configuration schemas with {@link ConfigurationRoot}, {@link Config}, or {@link PolymorphicConfig}.
 * @throws IllegalArgumentException If the configuration schemas does not contain {@link ConfigurationRoot}, {@link Config} or {@link
 *                                  PolymorphicConfig}.
 */
public static Set<Class<?>> collectSchemas(Collection<Class<?>> schemaClasses) {
    if (schemaClasses.isEmpty()) {
        return Set.of();
    }
    Set<Class<?>> res = new HashSet<>();
    Queue<Class<?>> queue = new ArrayDeque<>(Set.copyOf(schemaClasses));
    while (!queue.isEmpty()) {
        Class<?> cls = queue.poll();
        if (!cls.isAnnotationPresent(ConfigurationRoot.class) && !cls.isAnnotationPresent(Config.class) && !cls.isAnnotationPresent(InternalConfiguration.class) && !cls.isAnnotationPresent(PolymorphicConfig.class) && !cls.isAnnotationPresent(PolymorphicConfigInstance.class)) {
            throw new IllegalArgumentException(String.format("Configuration schema must contain one of @%s, @%s, @%s, @%s, @%s: %s", ConfigurationRoot.class.getSimpleName(), Config.class.getSimpleName(), InternalConfiguration.class.getSimpleName(), PolymorphicConfig.class.getSimpleName(), PolymorphicConfigInstance.class.getSimpleName(), cls.getName()));
        } else {
            res.add(cls);
            for (Field f : cls.getDeclaredFields()) {
                if ((f.isAnnotationPresent(ConfigValue.class) || f.isAnnotationPresent(NamedConfigValue.class)) && !res.contains(f.getType())) {
                    queue.add(f.getType());
                }
            }
        }
    }
    return res;
}
Also used : PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) Config(org.apache.ignite.configuration.annotation.Config) PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) ArrayDeque(java.util.ArrayDeque) Field(java.lang.reflect.Field) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) HashSet(java.util.HashSet)

Aggregations

ConfigValue (org.apache.ignite.configuration.annotation.ConfigValue)2 NamedConfigValue (org.apache.ignite.configuration.annotation.NamedConfigValue)2 ClassName (com.squareup.javapoet.ClassName)1 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)1 TypeName (com.squareup.javapoet.TypeName)1 WildcardTypeName (com.squareup.javapoet.WildcardTypeName)1 Field (java.lang.reflect.Field)1 ArrayDeque (java.util.ArrayDeque)1 HashSet (java.util.HashSet)1 Config (org.apache.ignite.configuration.annotation.Config)1 ConfigurationRoot (org.apache.ignite.configuration.annotation.ConfigurationRoot)1 InjectedName (org.apache.ignite.configuration.annotation.InjectedName)1 InternalId (org.apache.ignite.configuration.annotation.InternalId)1 PolymorphicConfig (org.apache.ignite.configuration.annotation.PolymorphicConfig)1 PolymorphicId (org.apache.ignite.configuration.annotation.PolymorphicId)1 Value (org.apache.ignite.configuration.annotation.Value)1