use of com.datastax.oss.driver.internal.mapper.processor.util.ResolvedAnnotation in project java-driver by datastax.
the class DefaultEntityFactory method buildCqlNameGenerator.
private CqlNameGenerator buildCqlNameGenerator(Set<TypeElement> typeHierarchy) {
Optional<ResolvedAnnotation<NamingStrategy>> annotation = AnnotationScanner.getClassAnnotation(NamingStrategy.class, typeHierarchy);
if (!annotation.isPresent()) {
return CqlNameGenerator.DEFAULT;
}
NamingStrategy namingStrategy = annotation.get().getAnnotation();
// Safe cast because the annotation can only be used on types:
TypeElement classElement = (TypeElement) annotation.get().getElement();
if (namingStrategy == null) {
return CqlNameGenerator.DEFAULT;
}
NamingConvention[] conventions = namingStrategy.convention();
TypeMirror[] customConverterClasses = readCustomConverterClasses(classElement);
if (conventions.length > 0 && customConverterClasses.length > 0) {
context.getMessager().error(classElement, "Invalid annotation configuration: %s must have either a 'convention' " + "or 'customConverterClass' argument, but not both", NamingStrategy.class.getSimpleName());
// Return a generator anyway, so that the processor doesn't crash downstream
return new CqlNameGenerator(conventions[0]);
} else if (conventions.length == 0 && customConverterClasses.length == 0) {
context.getMessager().error(classElement, "Invalid annotation configuration: %s must have either a 'convention' " + "or 'customConverterClass' argument", NamingStrategy.class.getSimpleName());
return CqlNameGenerator.DEFAULT;
} else if (conventions.length > 0) {
if (conventions.length > 1) {
context.getMessager().warn(classElement, "Too many naming conventions: %s must have at most one 'convention' " + "argument (will use the first one: %s)", NamingStrategy.class.getSimpleName(), conventions[0]);
}
return new CqlNameGenerator(conventions[0]);
} else {
if (customConverterClasses.length > 1) {
context.getMessager().warn(classElement, "Too many custom converters: %s must have at most one " + "'customConverterClass' argument (will use the first one: %s)", NamingStrategy.class.getSimpleName(), customConverterClasses[0]);
}
return new CqlNameGenerator(customConverterClasses[0]);
}
}
Aggregations