Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How should an inferrer fail correctly?
How should an inferrer fail correctly? [message #1125348] Fri, 04 October 2013 12:18 Go to next message
First Last is currently offline First LastFriend
Messages: 17
Registered: March 2013
Junior Member
What is the proper way for an inferrer to fail? There are a number of cases where it simply isn't possible to produce correct code, but it's not clear what the right way is to indicate failure at this layer, which apparently has to succeed in order for the validator to run. These seem to be the options:


  • Throw an uncaught exception (any particular one?)
  • Catch an exception at the top of the inferrer and just return
  • Generate syntactically invalid Java
  • Generate valid Java with semantically invalid content


I have tried each of these, and none of them seems perfect. For example, if I want to add an annotation to the generated code, and the annotation has a parameter of a type that does not exist, it is unclear what should be done.

Generating the annotation without the parameter might simply "work", but produce incorrect code. Not generating the annotation at all might be the same -- working, but wrong.

I have tried substituting invalid types (e.g. MissingType.class), but that seems to lead to conditions where Xtext can't figure out what is going wrong. I have also tried overriding parts of the ModelGenerator to produce invalid, commented code, but that's somewhat problematic to accomplish and doesn't seem to be encouraged & well-supported by Xtext either.

For example, using my own subclass of JvmTypeAnnotationValueImpl to put a comment in saying what type is missing and then generating a blank:

def dispatch void toJavaLiteral(FooJvmAnnotationValueImpl it,
      ITreeAppendable appendable, GeneratorConfig config) {
  val tracedAppendable = appendable.trace(it)
  tracedAppendable.append('/* ' + comment + ' */')
}


Re: How should an inferrer fail correctly? [message #1130577 is a reply to message #1125348] Wed, 09 October 2013 18:25 Go to previous messageGo to next message
First Last is currently offline First LastFriend
Messages: 17
Registered: March 2013
Junior Member
This seemed like a question that would get a quick answer, so I am not sure why it hasn't. It's basically the same question that was asked in "[IJvmModelInferrer] Referencing not yet existing classes".

Surely the right answer would not be that the Validator must re-do all the processing of the Inferrer and report errors that the Inferrer itself just hides? There must be some "appropriate" way for the the Inferrer to deal with situations where code generation cannot complete properly.
Re: How should an inferrer fail correctly? [message #1130598 is a reply to message #1130577] Wed, 09 October 2013 18:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi I don't know of such ways. Maybe you can find something in the
Xtend code.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How should an inferrer fail correctly? [message #1143799 is a reply to message #1125348] Fri, 18 October 2013 12:34 Go to previous message
First Last is currently offline First LastFriend
Messages: 17
Registered: March 2013
Junior Member
Seemingly the correct answer is: Catch any exceptions and just return, logging an error if desired.

Significant re-processing could be needed in the validator to ensure code generation was complete.
Previous Topic:Limiting the scope to elements in the same resource
Next Topic:Documenting the Grammar to use it in the DSL-Editor
Goto Forum:
  


Current Time: Tue Apr 23 17:21:47 GMT 2024

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

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

Back to the top