Skip to main content



      Home
Home » Modeling » TMF (Xtext) » XBase EMF(Xtext XBase EMF Ecore)
XBase EMF [message #1842239] Mon, 14 June 2021 04:11 Go to next message
Eclipse UserFriend
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 08:46 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: XBase EMF [message #1842250 is a reply to message #1842249] Mon, 14 June 2021 09:14 Go to previous messageGo to next message
Eclipse UserFriend
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 10:16 Go to previous messageGo to next message
Eclipse UserFriend
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)


Re: XBase EMF [message #1842269 is a reply to message #1842251] Tue, 15 June 2021 03:44 Go to previous messageGo to next message
Eclipse UserFriend
Works like a charm :)
Thanks a lot!

[Updated on: Tue, 15 June 2021 04:31] by Moderator

Re: XBase EMF [message #1842272 is a reply to message #1842269] Tue, 15 June 2021 04:31 Go to previous messageGo to next message
Eclipse UserFriend
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 04:41 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: XBase EMF [message #1842275 is a reply to message #1842274] Tue, 15 June 2021 04:57 Go to previous messageGo to next message
Eclipse UserFriend
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 05:04] by Moderator

Re: XBase EMF [message #1842278 is a reply to message #1842275] Tue, 15 June 2021 06:39 Go to previous messageGo to next message
Eclipse UserFriend
in this case you should look into subclassing
Re: XBase EMF [message #1842310 is a reply to message #1842278] Wed, 16 June 2021 04:42 Go to previous messageGo to next message
Eclipse UserFriend
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 05:41] by Moderator

Re: XBase EMF [message #1842318 is a reply to message #1842310] Wed, 16 June 2021 08:48 Go to previous message
Eclipse UserFriend
you can use NodeModelUtils to do so
Previous Topic:Code coverage for Xtend (outside of maven build)
Next Topic:What is the use of completeRuleCall
Goto Forum:
  


Current Time: Tue Apr 29 21:49:24 EDT 2025

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

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

Back to the top