[Xcore] EcorePackage version issue (in Xtext validator) [message #1751039] |
Tue, 03 January 2017 15:20  |
Eclipse User |
|
|
|
Hi all,
I have an Xtext-based language where in the language I can I reference elements from an Ecore or Xcore model.
When referencing elements from an Xcore model, there seems to be an issue with different version of the EcorePackage. For example, in a validator function, when I say
if (operand.expressionType == EcorePackage.Literals.EBOOLEAN) ...
the check returns an erroneous result because
expression.expressionType.EPackage
is not the same as
EcorePackage.eINSTANCE
(using Xtend syntax here)
They are both ecore packages, but one is an instance of ECorePackageImpl, while the other is an instance of EPackageImpl.
The problem does not occur when I reference elements from a plain Ecore model.
Any ideas of how to solve this issue?
Thanks
Joel
|
|
|
Re: [Xcore] EcorePackage version issue (in Xtext validator) [message #1751056 is a reply to message #1751039] |
Wed, 04 January 2017 01:43  |
Eclipse User |
|
|
|
It's best not to assume that EcorePackage.eINSTANCE will necessarily be the only one used. The serialized Ecore.ecore can be loaded as a resource into any resource set. Even the Sample Ecore Editor the Load Resource... gives you a choice, i.e., Browse Target Platform Packages... will load the serialized Ecore.ecore into a resource. Xcore tries to consistently use EPackages from the target platform in all cases; I say tries, because an Ecore model may reference either one which is why GenPackageImpl has a method like this:
public boolean isEcorePackage()
{
return (EcorePackage.eNS_URI.equals(getNSURI()));
} I don't know the full context of your application, perhaps you should be testing that operand.expressionType.instanceClass is the class for "boolean" or that operand.expressionType.instanceClassName is the value "boolean". After all, XMLTypePackage.Literals.BOOLEAN is also an EDataType that wraps "boolean" and of course any model could provide a different wrapper (and even serialize the instance value differently).
|
|
|
Powered by
FUDForum. Page generated in 0.05615 seconds