Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Access Ecore class Attribute with multiplicity 0..1 (Optional parameter)(Ecore/xtext/xtend treats optional EString attrribute as String.)
Access Ecore class Attribute with multiplicity 0..1 (Optional parameter) [message #1863312] Thu, 25 January 2024 14:15 Go to next message
Anders Ishoey is currently offline Anders IshoeyFriend
Messages: 1
Registered: January 2024
Junior Member
My class should have an attribute which is an optional string.
I define it in the Ecore file as EString with lower bound 0 and upper bound 1. (Fine)!
The generated java source ends up with a String definition.(bad)
Therefore, xtend can't query if the attribute is set. xtext correctly makes the attribute optional in the default grammar.

I would expect an EString which could be queried eIsSet().
Without being able to see if it is set (e.g. query EObject.eIsSet()), I can't treat it as optional in xtend.(bad)

If I define it as with bounds 0..2, I get an EList (String) in generated java.
In principle I could accept that two attributes could be added, but then the generated Xtext grammar expects the string to be in brackets "[ "S" ]". Worse, I need to type "[]" in the mydsl editor, even if the optional string is not there. (not really a good solution)

What is the most effortless way implement the optional string?
1) I overlook some mechanism that is right in my face
2) modification of how Ecore generates the java
3) modification to the Ecore generated java
4) modification to the xtext grammar

Newbie to Java.
Newbie to EMF. Please advice on which project folder to work in, if relevant.
Re: Access Ecore class Attribute with multiplicity 0..1 (Optional parameter) [message #1863322 is a reply to message #1863312] Fri, 26 January 2024 08:15 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
I suspect there is some misunderstanding here. You can always query any feature, regardless of the upper bound, via eIsSet. If the String feature has no default value, then null means it's not set. I suspect you might be better to ask on the Xtext forum. E.g., I don't know if the grammar makes the feature optional, but your question seems to be more about the grammar because an optional String feature with lower bound 0 is allowed to be null while one with lower bound 1 must be some non-null value...

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Genmodel code generation via Maven build
Next Topic:Multiple editors
Goto Forum:
  


Current Time: Thu May 02 04:18:39 GMT 2024

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

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

Back to the top