Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Custom Validator on Xtext Project From Existing Ecore Model
Custom Validator on Xtext Project From Existing Ecore Model [message #1865436] Fri, 03 May 2024 07:46 Go to next message
Eclipse UserFriend
Hello,

I created an Xtext grammar from an existing ecore model in my workspace. I noticed that Xtext doesn't generate these packages inside src-gen when the grammar is created through an ecore model: packageName, packageName.impl and packageName.util.

Without these, I can't build custom validation for my grammar, since Xtext didn't generate Literals (java interfaces).

Is there a way to have custom validation in Xtext projects from Ecore models?

Thanks in advance,
Alex
Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865448 is a reply to message #1865436] Fri, 03 May 2024 09:56 Go to previous messageGo to next message
Eclipse UserFriend
then you should create genmodel file and generate the java artifacts (model) for it. (normally this is already done if you have another project with the ecore)
there is also e EcoreGenerator workflow component for that.
Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865457 is a reply to message #1865448] Fri, 03 May 2024 13:55 Go to previous messageGo to next message
Eclipse UserFriend
I already have a genmodel file in my Modelling Project, so I use that file to generate those java artifacts in Generator.xtend class?

Sorry, but I'm kind of lost

[Updated on: Fri, 03 May 2024 13:56] by Moderator

Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865478 is a reply to message #1865457] Sat, 04 May 2024 01:40 Go to previous messageGo to next message
Eclipse UserFriend
no you open the genmodel file. select the root in the editor. and select "Generate Model Code"
this will produce the java classes for the ecore of the genmodel is for

index.php/fa/44250/0/
Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865499 is a reply to message #1865478] Sat, 04 May 2024 07:43 Go to previous messageGo to next message
Eclipse UserFriend
I don't think I expressed myself correctly. I have a modelling project (CircleCI_metamodel) that has the src-gen folder with the packages I mentioned. The problem is that I created an Xtext project (org.xtext.example.circleci) from this ecore model and Xtext doesn't generate these packages when I run the .mwe2 file. I want to have these packages in the Xtext project to perform customised validations. I copied the .genmodel file from my modelling project to the Xtext project, selected the root and generated model code but it didn't create the packages in the Xtext project. I think it just updated the code generated in my modelling project.

index.php/fa/44253/0/
index.php/fa/44259/0/

[Updated on: Sat, 04 May 2024 07:44] by Moderator

Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865502 is a reply to message #1865499] Sat, 04 May 2024 08:09 Go to previous messageGo to next message
Eclipse UserFriend
why do you expect the xtext project to generate
simply add your CircleCI_metamodel project to the required bundles in the manifest of
org.xtext.example.circleci
and the classes will be available
no need to copy genmodel and ecore.
Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865505 is a reply to message #1865502] Sat, 04 May 2024 08:31 Go to previous messageGo to next message
Eclipse UserFriend
I recognise that I didn't explain myself in the best way, because my problem was that the validator didn't know how to have the Literals interface available for the editor to return the error associated with the feature. As I created the Xtext project using the ecore model, I already had access to the java classes. I eventually found the solution by returning the EStructuralFeature and when I tested it, it worked. Thanks for your time Christian.

[Updated on: Sat, 04 May 2024 08:31] by Moderator

Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865508 is a reply to message #1865505] Sat, 04 May 2024 08:34 Go to previous message
Eclipse UserFriend
the literals interface wont be generated if the metamodel is "too big". also if the metamodel is derived/generated by Xtext

then you can Use MyPackage.eINSTANCE.getMyMetaClass_myFeature() instead
Previous Topic:Context-specific scopeFor method dispatched without entering IScopeProvider.getScope
Next Topic:Xtext 2.35.0.M2 for Eclipse 2024-06 M3 is available
Goto Forum:
  


Current Time: Fri Apr 25 13:05:04 EDT 2025

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

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

Back to the top