The Newsgroup Web Interface is deprecated, and can no longer be used to post. Please use the
Community Forums.
Eclipse NewsPortal - eclipse.modeling.tmf
[Xtext] Problem modifying enumeration in post processing (Xtend)
Subject: [Xtext] Problem modifying enumeration in post processing (Xtend)
From: developer@xxxxxxxxxxxx (Jens v.P.)
Newsgroups: eclipse.modeling.tmf
Organization: EclipseCorner
Date: Jun 30 2009 04:14:39
Hi all,
I'm trying to migrate from oAW Xtext to TMF Xtext. Since the handling of enumarations has been changed, I want to post process the ecore model in order to restore the original behaviour.
In my grammar, an enumeration is defined (actually this is only one example, I have severals. In the following case I might add a "package" as default NULL value, but I have cases in which this doesn't work):
------------------------
enum VisibilityModifier:
public | private;
------------------------
Now I want to add the NULL literal. Only adding a new literal doesn't help, as public becomes the default value (and its value is 0). That is, I have to increment the value for all defined literals and then add my NULL literal.
However, I don't get Xtend to do that. Adding a literal is working like that:
--------------------------------------------------------
Void addNullValue(ecore::EPackage p, String toEnum):
let e=(ecore::EEnum) p.getEClassifier(toEnum):
e.addLiteral("NULL", "NULL", 0);
--------------------------------------------------------
OK, but as explained, this does only solve half of the problem, I still have to increment the values for the existing literals. I tried several variations, the most simple one:
--------------------------------------------------------
Void addNullValue(ecore::EPackage p, String toEnum):
let e=(ecore::EEnum) p.getEClassifier(toEnum):
e.eLiterals.collect(lit|lit.setValue(lit.value+1)) ->
e.addLiteral("NULL", "NULL", 0);
--------------------------------------------------------
It does not work, the following error occurs:
--------------------------------------------------------
EvaluationException : Couldn't find property 'value' for type mitra::VisibilityModifier
de::feu::MitraPostProcessor.ext[4181,9] on line 100 'lit.value'
de::feu::MitraPostProcessor.ext[190,37] on line 11 'addNullValue(p,"VisibilityModifier")'
--------------------------------------------------------
I do not understand how this happens. "lit" is expected to be an intance of ecore::EEnumLiteral, that is a literal of VisibilityModifier, and not the enum itself. (Also, there are no errors "compiling" the Xtend source). OK, I tried it to manually iterate over the collection (I removed the let-expression as it caused lots of weird syntax errors I don't fully understand... I assume there is something wrong with let, e.g., code assist does not work within a let expression):
--------------------------------------------------------
Void addNullValue(ecore::EPackage p, String toEnum):
((ecore::EEnum)p.getEClassifier(toEnum)).eLiterals.incAllValues() ->
((ecore::EEnum)p.getEClassifier(toEnum)).addLiteral("NULL", "NULL", 0);
ecore::EEnumLiteral incValue(ecore::EEnumLiteral literal):
literal.setValue(literal.value+1) -> literal;
Void incAllValues(List[ecore::EEnumLiteral] list):
if list.size>0 then
list.first().incValue() ->
list.withoutFirst().incAllValues();
--------------------------------------------------------
But, again, the same error as above:
--------------------------------------------------------
EvaluationException : Couldn't find operation 'incValue()' for mitra::VisibilityModifier.
de::feu::MitraPostProcessor.ext[4540,23] on line 111 'list.first().incValue()'
de::feu::MitraPostProcessor.ext[4016,65] on line 98 '(ecore::EEnum)p.getEClassifier(toEnum).eLiterals.incAllValues()'
de::feu::MitraPostProcessor.ext[190,37] on line 11 'addNullValue(p,"VisibilityModifier")'
--------------------------------------------------------
At this point I assume it's a bug, as incAllValues is called without an error, which means the list must contain EEnumLiterals -- but then how does the enumeration sneaks into this collection again?
Do you have any solutions for my problem? (In the worst case, I'll try to write a Java extension, but I assume this problem should be solvable within Xtend).
Cheers
Jens
| Date | Subject | | Author |
| 31.12. | | | |