Home » Modeling » TMF (Xtext) » Display DSL code generation errors in Eclipse(How do I add errors (that result from code generation, not validation) to the error list in Eclipse?)
| | | |
Re: Display DSL code generation errors in Eclipse [message #1838099 is a reply to message #1725822] |
Tue, 16 February 2021 04:24   |
Mirko Raner Messages: 123 Registered: July 2009 Location: New York City, NY |
Senior Member |
|
|
I was wondering if there have been any new developments in the 5 years since this question was originally asked (new error handling APIs, for example). I'm struggling with very much the same question, but in my case the language needs to work outside of Eclipse as well (e.g., in a Maven plug-in or in a stand-alone compiler tool), so generating Eclipse markers would only solve half of the problem. Furthermore, moving all the validation functionality from the code generator into an AbstractDeclarativeValidator (or some other type of validator) would create a huge amount of duplicate code. Also, there would be a lot of intermediate results that are costly to calculate that would have to be calculated in the validator and then again in the code generator.
I realize that the code generation phase is a somewhat "out-of-order" location for generating error messages (i.e., after parsing, model generation and linking/cross-referencing have already completed successfully). If there are no new APIs for adding/generating Diagnostic objects during code generation, I'd be grateful for any pointers for implementing such a mechanism (in other words, where are the "hooks" for adding it, and which other classes would have to be modified).
|
|
| | | |
Re: Display DSL code generation errors in Eclipse [message #1838231 is a reply to message #1838188] |
Fri, 19 February 2021 04:58   |
Mirko Raner Messages: 123 Registered: July 2009 Location: New York City, NY |
Senior Member |
|
|
Fair question, Christian :-)
And, yes, I realize that there is no diagnostics facility in the generator. In a way, that is exactly the shortcoming that I'm trying to overcome here (I think).
Xtext has great facilities for detecting parsing and cross-referencing problems. So far, I have not had to write a single line of code that deals with Eclipse markers or with error messages that are printed on the console. My Xtext language has nice error messages inside Eclipse, as well as when running in its Maven plug-in (based on AbstractXtextGeneratorMojo). It all works out of the box. From writing unit tests, I understand that all parsing and linking errors end up in a Resource's EList<Diagnostic> for warnings and errors (Resource.getErrors()/getWarnings()). From there, they (apparently) get transformed into Eclipse markers and error messages printed by Maven. I want to use that same facility for errors that I discover during code generation. Right now, the code throws an exception and brings everything to a halt. Instead of an exception I would like a Diagnostic (I think) that then gets (hopefully automatically) transformed into an Eclipse marker or a Maven error message (as the case may be).
Maybe to add some more context here: a lot of these late-discovered error conditions in my case have to do with type inference around lambda-like expressions. All the individual parts of the expression are fully resolved and linked, but it is complicated to determine the overall type of that expression and, for example, choose the right method signature according to that type. Sometimes there are ambiguities, and the code generator is unable to find the right method. In those cases, I would like to produce an error message or an Eclipse marker that describes the problem. Diagnostics seem to be that common denominator before things get transformed to (Maven) error messages or (Eclipse) markers, but I may be wrong on that.
|
|
| |
Goto Forum:
Current Time: Mon Mar 27 05:42:45 GMT 2023
Powered by FUDForum. Page generated in 0.02319 seconds
|