Pregunta

I have some Interfaces with custom annotations for adding metadata. In specific those interfaces represent tables in a database and the annotations say what table the interface should be mapped to and what columns the properties are.

I use annotation processing to generate code files that do some work such as loading the data from the database etc. I also have a ValidationProcessor that should validate the interfaces if all needed metadata are available and so on. When I validate the annotations I want to display warning and errors so that it is clear what is not correct and where that problem occurs.

For printing the messages I use the Messager API. Here is the code I use where kind is e.g. Kind.ERROR, msg is the message and element is the element on which the error occured (it is a Type that implements the Element interface).

processingEnv.getMessager().printMessage(kind, msg, element, null, null);

According to my internet research (including similar articles on stackoverflow) this should be the way to correctly display messages. Nevertheless the messages are not display.

My question is, does anyone have an idea what could be wrong?

¿Fue útil?

Solución

The way you create messages is correct, though you could just use

printMessage(kind, msg, element);

if you don't want to display messages on annotations or annotation values. When overriding the processor's init method, make sure to call super.init(processingEnv) so it is set up correctly.

It sounds like the processor fails due some error in the execution. The processor will fail silently if there is an uncatched exception and then it won't display any messages. To debug an annotation processor activate the error log view:

Window  loading= Show View > Error Log">

In this view you should see every message by the messager as well as any uncatched exceptions thrown by the processor. The stack trace should help you to locate the error.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top