How should an inferrer fail correctly? [message #1125348] |
Fri, 04 October 2013 12:18 |
First Last 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 + ' */')
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03498 seconds