Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotation processor-generated Errors/warnings not showing in Eclipse editor or Problems view

Tags:

I have written a customer annotation processor to generate various source files, wrapped in an Eclipse plugin. As part of this process it also logs various errors and warnings using the usual call ProcessingEnvironment#getMessager().printMesssage(Kind, String, Element).

I have been testing the processor by debugging the plugin in Eclipse. In the launched sub-instance of Eclipse the processor all works as expected - source files are generated, picked up and interpreted by the compiler as desired. Any compiler (i.e. non-custom) errors in the generated and non-generated appear in the editor, Problems view etc. as expected.

However I am seeing a lot of inconsistencies in terms of how custom errors and warnings appear. The behaviour I see is as follows:

  1. If no Element is specified all messages appear in the Error Log under type Info, regardless of the Kind specified when logging the error.
  2. If a message is of Kind NOTE it always appears in the Error Log under type Info, regardless of whether or not an Element is specified.
  3. Otherwise, if an Element is specified errors and warnings intermittently appear in the Problems view and in the editor; sometimes they don't appear anywhere. They never appear in the Error Log, whether the Kind is ERROR or WARNING

As per the emphasis above, the real issue is item 3 - that under certain situations I simply cannot get errors to appear in the editor despite being logged on valid elements. In fact, I have managed to reliably make errors appear and not appear by simply changing the name of a particular generated source file.

Of course the issue is not the filename itself, but it is certainly the case that generating the class with a name that matches references already in code causes errors to get hidden, whilst generating it with a different name (or not at all) causes errors to show (as well as all the regular compiler errors caused by a missing class). The strangest thing is that there is nothing fundamentally different about this generated class compared to any of the others (of which there are many), although it is unique in its structure and how it is referenced. It also reasonably long (around 400 methods), but artificially shortening it did not make any difference. Other generated classes also have existing references in the code and don't suppress errors.

Unfortunately I have also not yet had the time to test if this issue occurs when the Eclipse plugin is deployed (i.e. running in a 'real' instance of Eclipse), or indeed if the issue occurs when calling javac explicitly or invoking a Maven build.

Without posting the full code of the plugin I don't expect anyone to be able to help directly, but I am very open to any suggestions or advice if anybody has experience issues with annotation processor-generated errors. It seems to me like a bug in Eclipse, but I have not been able to find any reference to it online. I also cannot find any errors in the .metadata/.log files of either the underlying Eclipse instance or the launched sub-instance of Eclipse. Finally I have ensured that there are no Exceptions suppressed or reported in the annotation processor code.

Eclipse version details:

Version: Luna Service Release 1a (4.4.1) Build id: 20150109-0600 

Any help appreciated and many thanks in advance :)

like image 217
Overlord_Dave Avatar asked Mar 04 '15 17:03

Overlord_Dave


People also ask

Why is my Eclipse not showing errors?

You need to open the eclipse Markers view ( Window->Show View->Markers ), it will show all errors about your project, if you correct all the errors, your problem will most likely be solved.

How do I show errors in Eclipse?

From the main menu, select Window > Show view > Other. Then select General > Error Log. The error log is displayed, showing the following information for each error: The status of the error (for example, error or warning)

How do I change error warnings in Eclipse?

In eclipse if you right click on your Project in the Package Explorer, then go to properties -> Java Compiler -> Errors/Warnings. You can then manually change which compiler findings appear as warnings/errors/ignored etc...


1 Answers

If a problem/error has to be shown in the Eclipse Problems view, you need to create a Marker on the particular resource (file/folder/project). Please see the following links on how to create the Markers in an Eclipse Plugin:

https://wiki.eclipse.org/FAQ_How_do_I_create_problem_markers_for_my_compiler%3F https://www.eclipse.org/articles/Article-Mark%20My%20Words/mark-my-words.html

In terms of how the custom errors/warnings appear, the Problems view (or the generic MarkersView) is completely flexible to show/hide certain elements. Have a look at the "Configure Contents..." menu in the Problems view to get more idea.

like image 64
Prakash G. R. Avatar answered Oct 04 '22 07:10

Prakash G. R.