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;
}
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;
}
Aggregations