Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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?)
Display DSL code generation errors in Eclipse [message #1725613] Fri, 04 March 2016 23:59 Go to next message
Ben Oosthuysen is currently offline Ben OosthuysenFriend
Messages: 2
Registered: March 2016
Junior Member
Occasionally, my DSL code generation finds a problem and throw an exception. I would like this exception to be displayed in Eclipse (with the appropriate line highlighting) in the same way the validation errors are shown.
Is this possible?

My code generation exception has the filename (resource), offending line number, and a message. How do I add that message into the resource's diagnostics?

class MyDslGenerator extends AbstractGenerator {

/**
* main Generate hook
*/
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {

try {
// Generate the code
// ...

} catch (GenerateCodeException e) {
// logger.error("doGenerate failed {} line {}: {}", e.file, e.fromLine, e.toString)

println("*** Exception during code generation ***")
println(e);
// quietly ignore?
}
}

} // class MyDslGenerator

Re: Display DSL code generation errors in Eclipse [message #1725695 is a reply to message #1725613] Mon, 07 March 2016 04:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13930
Registered: July 2009
Senior Member
Have a look at how to create markers in eclipse. This is not xtext specific.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Display DSL code generation errors in Eclipse [message #1725696 is a reply to message #1725695] Mon, 07 March 2016 04:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13930
Registered: July 2009
Senior Member
http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_markers.htm

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Display DSL code generation errors in Eclipse [message #1725822 is a reply to message #1725696] Mon, 07 March 2016 22:01 Go to previous messageGo to next message
Ben Oosthuysen is currently offline Ben OosthuysenFriend
Messages: 2
Registered: March 2016
Junior Member
Thank you ... I'll use the information in the link you kindly provided. Much appreciated.
Re: Display DSL code generation errors in Eclipse [message #1838099 is a reply to message #1725822] Tue, 16 February 2021 04:24 Go to previous messageGo to next message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 104
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 #1838102 is a reply to message #1838099] Tue, 16 February 2021 07:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13930
Registered: July 2009
Senior Member
see the exceptional error handling and marker creation in org.eclipse.xtext.builder.BuilderParticipant.addMarkerAndLogError(URI, Throwable)

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Display DSL code generation errors in Eclipse [message #1838174 is a reply to message #1838102] Thu, 18 February 2021 07:21 Go to previous messageGo to next message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 104
Registered: July 2009
Location: New York City, NY
Senior Member
Thank you so much for the pointer, Christian. I had a look at that code, and unfortunately it's probably still too Eclipse-specific for my purposes. But it demonstrates nicely how exceptions can be turned into markers on the Eclipse side of things. I was thinking more of an Xtext/EMF-based solution that would work both in Eclipse and stand-alone. For example, I saw that XtextResource.doLinking() simply adds new Xtext Diagnostic objects to the resources's getErrors() and getWarnings(). Would diagnostics that were added in this fashion during the code generation phase automatically get translated into Eclipse markers?
Re: Display DSL code generation errors in Eclipse [message #1838188 is a reply to message #1838174] Thu, 18 February 2021 11:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13930
Registered: July 2009
Senior Member
there is no diagnostics facaility in the generator.
thus what is your usecase?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Display DSL code generation errors in Eclipse [message #1838231 is a reply to message #1838188] Fri, 19 February 2021 04:58 Go to previous messageGo to next message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 104
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.
Re: Display DSL code generation errors in Eclipse [message #1838233 is a reply to message #1838231] Fri, 19 February 2021 07:13 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13930
Registered: July 2009
Senior Member
if your usecase is maven you have to come up with something yourself

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtend template error:This expression is not allowed in this context, since it doesn't cause any side
Next Topic:Content assist edit positions and template variables
Goto Forum:
  


Current Time: Mon May 10 22:51:01 GMT 2021

Powered by FUDForum. Page generated in 0.02881 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top