25

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 :)

Overlord_Dave
  • 894
  • 10
  • 27
  • One thing that I've noticed is that Eclipse has it's own classloaders (and also bytecode modification utilties?) which sometimes have unexpected behaviour, mostly in order to make the user experience in the IDE better. You've probably already thought of this, but adding `new Throwable("debug message").printStackTrace()` as a debug statement in various parts of the code is usually where I start when I can't figure out anything else. – Marco Oct 21 '15 at 10:56

1 Answers1

2

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.

Prakash G. R.
  • 4,746
  • 1
  • 24
  • 35