Strange difference between ModelInferrer and ModelGenerator [message #1441102] |
Thu, 09 October 2014 05:02  |
Eclipse User |
|
|
|
Hi,
because I'm wavered using ModelInferrer or the ModelGenerator I'm using at the moment both to determine the pros and cons of each way.
My grammar has the following passage to support inheritance:
(abstract='abstract')? 'entity' name=ID ('extends' superType=JvmTypeReference)? ('implements' interfaceTypes+=JvmTypeReference (',' interfaceTypes+=JvmTypeReference)*)?
The corresponding passage of my ModelGenerator is:
public «IF element?.methods.size > 0»abstract«ENDIF» class «element.name»«IF element.superType != null» extends «element.superType.type.identifier»«ENDIF»«IF element.interfaceTypes.size > 0» implements «FOR intfc : element.interfaceTypes SEPARATOR ','»«intfc.type.identifier»«ENDFOR»«ENDIF»
And in the ModelInferrer I'm setting superTypes by this:
if(element.superType != null) {
superTypes += element.superType
}
for(interface : element.interfaceTypes) {
superTypes += interface
}
I tested with this code-snippet:
entity Adresse extends Superclass implements Serializable
When I test this feature the code of the ModelInferrer works for the superType and creates the corresponding extends-Statement, but the ModelGenerator doesn't. I debugged my ModelGenerator and there is element.superType null.
Another problem is that the lines for adding the interfaces to superTypes in ModelInferrer results in java.util.ConcurrentModificationException.
Can anybody explain this in my opinion strange behaviour?
Why is element.superType in ModelInferrer != null but in ModelGenerator == null?
What is wrong that I get java.util.ConcurrentModificationExceptions when I'm adding interfaces to superTypes?
|
|
|
|
|
|
Re: Strange difference between ModelInferrer and ModelGenerator [message #1441412 is a reply to message #1441195] |
Thu, 09 October 2014 13:50  |
Eclipse User |
|
|
|
It's not an error in Xtend but you are modifying your model by accident
in both cases. The classic for-loop just hides the exception from you.
If you use the JvmTypesBuilder as an extension in your class, the +=
will do an implicit clone of your type references rather than moving it
out of place. Generally speaking, you should strictly avoid to modify
your source model in the model inferrer. Christian already tried to
suggest that you use
superTypes += intf.cloneWithProxies
rather than adding it directly as a supertype.
Hope that helps,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
Powered by
FUDForum. Page generated in 0.32483 seconds