use of com.tickaroo.tikxml.processor.ProcessingException in project tikxml by Tickaroo.
the class TikXmlAutoValueExtension method applicable.
@Override
public boolean applicable(Context context) {
ProcessingEnvironment environment = context.processingEnvironment();
try {
Xml xmlAnnotation = context.autoValueClass().getAnnotation(Xml.class);
if (xmlAnnotation == null) {
// Auto value class not annotated with @Xml annotation
return false;
}
if (!xmlAnnotation.inheritance()) {
throw new ProcessingException(context.autoValueClass(), "Inheritance in TikXml can't be disabled via @" + Xml.class.getSimpleName() + "(inheritance = false) in class " + context.autoValueClass().getQualifiedName());
}
List<AnnotatedMethod<?>> annotatedMethods = AutoValueScannerKt.extractAutoValueProperties(context.autoValueClass(), context.properties(), context.processingEnvironment().getTypeUtils(), context.processingEnvironment().getElementUtils());
// generate code
AutoValueAnnotatedClass annotatedClass = new AutoValueAnnotatedClass(context.packageName(), context.autoValueClass(), xmlAnnotation, annotatedMethods);
try {
Filer filer = context.processingEnvironment().getFiler();
JavaFile.builder(context.packageName(), AutoValueTypeAdapterCodeGeneratorKt.generateValueHolder(annotatedClass, context.processingEnvironment().getElementUtils())).build().writeTo(filer);
JavaFile.builder(context.packageName(), AutoValueTypeAdapterCodeGeneratorKt.generateTypeAdapter(annotatedClass)).build().writeTo(filer);
} catch (IOException e) {
throw new ProcessingException(annotatedClass.getAutoValueClass(), "Error while generating code for " + annotatedClass.getAutoValueClass().getQualifiedName() + ": " + e.getMessage());
}
} catch (ProcessingException exception) {
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, exception.getMessage(), exception.getElement());
}
// We don't generate code as an autovalue extension
return false;
}
Aggregations