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 08:18
First Last is currently offline First Last
Messages: 11
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 + ' */')
}


Previous Topic:Problem with Enums in Xcore-XTEXT
Next Topic:ClassCastException & JobReconcilier
Goto Forum:
  


Current Time: Mon Oct 07 10:30:56 EDT 2013

Powered by FUDForum. Page generated in 0.04329 seconds