Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XBase EMF(Xtext XBase EMF Ecore)
XBase EMF [message #1842239] Mon, 14 June 2021 08:11 Go to next message
Frä Fröhlich is currently offline Frä FröhlichFriend
Messages: 18
Registered: June 2021
Junior Member
I am trying to use EMF with Xbase Expressions.
for that I have a model (Genmodel)

 <genClasses ecoreClass="cbcmodel.ecore#//JavaStatement">
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute cbcmodel.ecore#//JavaStatement/name"/>
    </genClasses>


And the corresponding ecore:

  <eClassifiers xsi:type="ecore:EClass" name="JavaStatement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="name" eType="ecore:EClass http://www.eclipse.org/xtext/xbase/Xbase#//XExpression"/>
  </eClassifiers>


And my DSL:

JavaStatement returns JavaStatement:
	name=XPrimaryExpression
;



The ecore doesn't show any errors- However, I can not generate the model, because I get the error :
The package 'http://www.eclipse.org/xtext/common/JavaVMTypes#/' is needed but is not accessible from the Generator model

I already added org.eclipse.xtext.common.types to my required-bundle in the manifest file, but this didn't help.

Can You help me or reference a working project with Xtext and EMF?
Re: XBase EMF [message #1842249 is a reply to message #1842239] Mon, 14 June 2021 12:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
hi did you add a referenceResource="platform:/resource//org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel" to the language section ?
if this does not help, can you provide a complete reproducible example?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XBase EMF [message #1842250 is a reply to message #1842249] Mon, 14 June 2021 13:14 Go to previous messageGo to next message
Frä Fröhlich is currently offline Frä FröhlichFriend
Messages: 18
Registered: June 2021
Junior Member
I am not sure what you mean by the language section.
However, I tried adding it to Genmodel and ecore header and it didn't help.

You can check my repo https://github.com/Babwenbiber/CorC (folder: de.tu-bs.cs.isf.cbc.model not taxonomy).
Re: XBase EMF [message #1842251 is a reply to message #1842250] Mon, 14 June 2021 14:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
in you grammar you have

JavaStatement returns JavaStatement:
	name+=XExpression (name+=XExpression)*
;


but in metamodel conainment=false.

with consistent use of platform:/resource in ecore and genmodel
it works fine for me

From 26506b4209ab80cf0f27fce2748ff649386930eb Mon Sep 17 00:00:00 2001
From: Christian Dietrich <christian.dietrich@itemis.de>
Date: Mon, 14 Jun 2021 16:14:38 +0200
Subject: [PATCH]  fix problem

Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
---
 .../model/cbcmodel.ecore                      |  4 ++--
 .../model/cbcmodel.genmodel                   | 19 +++++++++----------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/de.tu-bs.cs.isf.cbc.model/model/cbcmodel.ecore b/de.tu-bs.cs.isf.cbc.model/model/cbcmodel.ecore
index 59d5caf..f48f6eb 100644
--- a/de.tu-bs.cs.isf.cbc.model/model/cbcmodel.ecore
+++ b/de.tu-bs.cs.isf.cbc.model/model/cbcmodel.ecore
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-referenceResource="platform:/resource//org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel"
     xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="cbcmodel" nsURI="http://www.example.org/cbcmodel" nsPrefix="cbcmodel">
   <eClassifiers xsi:type="ecore:EClass" name="CbCFormula">
     <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
@@ -39,7 +38,8 @@ referenceResource="platform:/resource//org.eclipse.xtext.common.types/model/Java
   </eClassifiers>
   <eClassifiers xsi:type="ecore:EClass" name="SkipStatement" eSuperTypes="#//AbstractStatement"/>
   <eClassifiers xsi:type="ecore:EClass" name="JavaStatement">
-    <eStructuralFeatures xsi:type="ecore:EReference" name="name" upperBound="-1" eType="ecore:EClass http://www.eclipse.org/xtext/xbase/Xbase#//XExpression"/>
+    <eStructuralFeatures xsi:type="ecore:EReference" name="name" upperBound="-1" eType="ecore:EClass ../../org.eclipse.xtext.xbase/model/Xbase.ecore#//XExpression"
+        containment="true"/>
     <eStructuralFeatures xsi:type="ecore:EReference" name="postCondition" eType="#//Condition"
         containment="true"/>
     <eStructuralFeatures xsi:type="ecore:EReference" name="preCondition" eType="#//Condition"
diff --git a/de.tu-bs.cs.isf.cbc.model/model/cbcmodel.genmodel b/de.tu-bs.cs.isf.cbc.model/model/cbcmodel.genmodel
index 7532928..3236146 100644
--- a/de.tu-bs.cs.isf.cbc.model/model/cbcmodel.genmodel
+++ b/de.tu-bs.cs.isf.cbc.model/model/cbcmodel.genmodel
@@ -2,10 +2,10 @@
 <genmodel:GenModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
     xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/de.tu-bs.cs.isf.cbc.model/src-gen" editDirectory="/de.tu-bs.cs.isf.cbc.model.edit/src-gen"
     editorDirectory="/de.tu-bs.cs.isf.cbc.model.editor/src-gen" modelPluginID="de.tu-bs.cs.isf.cbc.model"
-    referenceResource="platform:/resource//org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel"
     forceOverwrite="true" modelName="Cbcmodel" rootExtendsClass="org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container"
     testsDirectory="/de.tu-bs.cs.isf.cbc.model.tests/src-gen" importerID="org.eclipse.emf.importer.ecore"
-    complianceLevel="8.0" copyrightFields="false" operationReflection="true" importOrganizing="true">
+    complianceLevel="8.0" copyrightFields="false" usedGenPackages="platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel#//xbase platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel#//types"
+    operationReflection="true" importOrganizing="true">
   <foreignModel>cbcmodel.ecore</foreignModel>
   <genPackages prefix="Cbcmodel" basePackage="de.tu_bs.cs.isf.cbc" disposableProviderFactory="true"
       ecorePackage="cbcmodel.ecore#/">
@@ -44,21 +44,21 @@
       <genFeatures createChild="false" ecoreFeature="ecore:EAttribute cbcmodel.ecore#//AbstractStatement/comment"/>
     </genClasses>
     <genClasses ecoreClass="cbcmodel.ecore#//SkipStatement"/>
-    <genClasses ecoreClass="cbcmodel.ecore#//JMLAnnotation">
-      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//JMLAnnotation/requires"/>
-      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//JMLAnnotation/assignable"/>
-      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//JMLAnnotation/ensures"/>
-    </genClasses>
     <genClasses ecoreClass="cbcmodel.ecore#//JavaStatement">
-      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute cbcmodel.ecore#//JavaStatement/name"/>
+      <genFeatures createChild="false" ecoreFeature="ecore:EReference cbcmodel.ecore#//JavaStatement/name"/>
       <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//JavaStatement/postCondition"/>
       <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//JavaStatement/preCondition"/>
       <genFeatures createChild="false" ecoreFeature="ecore:EAttribute cbcmodel.ecore#//JavaStatement/proven"/>
       <genFeatures createChild="false" ecoreFeature="ecore:EAttribute cbcmodel.ecore#//JavaStatement/comment"/>
     </genClasses>
+    <genClasses ecoreClass="cbcmodel.ecore#//JMLAnnotation">
+      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EAttribute cbcmodel.ecore#//JMLAnnotation/requires"/>
+      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EAttribute cbcmodel.ecore#//JMLAnnotation/assignable"/>
+      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EAttribute cbcmodel.ecore#//JMLAnnotation/ensures"/>
+    </genClasses>
     <genClasses ecoreClass="cbcmodel.ecore#//BlockStatement">
-      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//BlockStatement/jmlAnnotation"/>
       <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//BlockStatement/javaStatement"/>
+      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//BlockStatement/jmlAnnotation"/>
     </genClasses>
     <genClasses ecoreClass="cbcmodel.ecore#//CompositionStatement">
       <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//CompositionStatement/firstStatement"/>
@@ -135,7 +135,6 @@
       <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//StrengthWeakStatement/weakPreCondition"/>
       <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//StrengthWeakStatement/strongPostCondition"/>
     </genClasses>
-    
     <genClasses ecoreClass="cbcmodel.ecore#//MethodRefinements">
       <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference cbcmodel.ecore#//MethodRefinements/productvariants"/>
     </genClasses>
-- 
2.30.1 (Apple Git-130)




Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XBase EMF [message #1842269 is a reply to message #1842251] Tue, 15 June 2021 07:44 Go to previous messageGo to next message
Frä Fröhlich is currently offline Frä FröhlichFriend
Messages: 18
Registered: June 2021
Junior Member
Works like a charm :)
Thanks a lot!

[Updated on: Tue, 15 June 2021 08:31]

Report message to a moderator

Re: XBase EMF [message #1842272 is a reply to message #1842269] Tue, 15 June 2021 08:31 Go to previous messageGo to next message
Frä Fröhlich is currently offline Frä FröhlichFriend
Messages: 18
Registered: June 2021
Junior Member
One last question which is not really related to the topic title.
I migrated from xtext 2.10 to 2.25 and have trouble getting the "Resource" on generation when using jvmModel.

Before I could use the DslGenerator.doGenerate and had the Resource as a param already.
Now, I use DslJvmModelInferrer.infer and don't know how to get the resource or URI of the file I am currently working on.
Re: XBase EMF [message #1842274 is a reply to message #1842272] Tue, 15 June 2021 08:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
if you use xbase the generator that will be used is JvmModelGenerator
so if you want to customize it you need to subclass it
and override org.eclipse.xtext.xbase.DefaultXbaseRuntimeModule.bindIGenerator()
in youe runtime module.

but the usual way is to do all in the inferrer and not to touch JvmModelGenerator
so i wonder what your exact usecase is


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XBase EMF [message #1842275 is a reply to message #1842274] Tue, 15 June 2021 08:57 Go to previous messageGo to next message
Frä Fröhlich is currently offline Frä FröhlichFriend
Messages: 18
Registered: June 2021
Junior Member
I want to create a File/Folder right next to the analyzed file.
E.g. if the analyzed file is /folder/bla.foo
I want to create /folder/folder2/bla.foo2

[Updated on: Tue, 15 June 2021 09:04]

Report message to a moderator

Re: XBase EMF [message #1842278 is a reply to message #1842275] Tue, 15 June 2021 10:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
in this case you should look into subclassing

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XBase EMF [message #1842310 is a reply to message #1842278] Wed, 16 June 2021 08:42 Go to previous messageGo to next message
Frä Fröhlich is currently offline Frä FröhlichFriend
Messages: 18
Registered: June 2021
Junior Member
Really helpful, thanks.
Is it possible to receive the original text from an xtext object?
E.g. I have coded:
if(i>j) {
  i++;
} else {
  j++;
}


In the doGenerate I get an XExpression Element.
I want to have the originally typed String "if(I>j) { i++;} else { j++;}" from it.
But the toString Method gives me XIfExpressionImpl@Address

Any ideas to retrieve this String?

I found this article https://jevopisdeveloperblog.blogspot.com/2011/03/implement-tostring-with-xtexts.html but it is from 2011 and works with the old Xtext

[Updated on: Wed, 16 June 2021 09:41]

Report message to a moderator

Re: XBase EMF [message #1842318 is a reply to message #1842310] Wed, 16 June 2021 12:48 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
you can use NodeModelUtils to do so

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Code coverage for Xtend (outside of maven build)
Next Topic:xtext 2.25.0 + jdk 11.0.11
Goto Forum:
  


Current Time: Thu Jul 29 00:35:39 GMT 2021

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

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

Back to the top