Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 11:46 Go to next message
Alex Oli is currently offline Alex OliFriend
Messages: 19
Registered: May 2024
Junior Member
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 13:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
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.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865457 is a reply to message #1865448] Fri, 03 May 2024 17:55 Go to previous messageGo to next message
Alex Oli is currently offline Alex OliFriend
Messages: 19
Registered: May 2024
Junior Member
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 17:56]

Report message to a moderator

Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865478 is a reply to message #1865457] Sat, 04 May 2024 05:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
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/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865499 is a reply to message #1865478] Sat, 04 May 2024 11:43 Go to previous messageGo to next message
Alex Oli is currently offline Alex OliFriend
Messages: 19
Registered: May 2024
Junior Member
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 11:44]

Report message to a moderator

Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865502 is a reply to message #1865499] Sat, 04 May 2024 12:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
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.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865505 is a reply to message #1865502] Sat, 04 May 2024 12:31 Go to previous messageGo to next message
Alex Oli is currently offline Alex OliFriend
Messages: 19
Registered: May 2024
Junior Member
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 12:31]

Report message to a moderator

Re: Custom Validator on Xtext Project From Existing Ecore Model [message #1865508 is a reply to message #1865505] Sat, 04 May 2024 12:34 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
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 Oct 11 15:39:49 GMT 2024

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

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

Back to the top