Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Accessing Enum from imported ECore model
Accessing Enum from imported ECore model [message #1860231] Mon, 24 July 2023 13:16 Go to next message
Eclipse UserFriend
Hello,

I have an imported ECore model into my xtext grammar. I'm trying to maintain one list of Enum types for both my ECore model and my Xtext grammar. What I'm currently struggling with is how to create rules using my Enum types from my ECore model.
grammar org.mcmaster.pfcsm.operation.actiondsl.Actiondsl with org.eclipse.xtext.common.Terminals

generate actiondsl "http://www.mcmaster.org/pfcsm/operation/actiondsl/Actiondsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.example.org/pfcsm" as pfcsm

Domainmodel:
    (elements+=AbstractElement)*;
 
AbstractElement:
    PackageDeclaration | Type;

PackageDeclaration:
    'package' name=QualifiedName '{'
        (elements+=AbstractElement)*
    '}';
   
QualifiedName:
    ID ('.' ID)*;
    
Type:
	DataType | Value | Variable
;

DataType:
	type = [pfcsm|PrimitiveType]
;

Value:
	STRING | INT
;

Variable:
	'var' name=ID ' ' type=[DataType] '=' Value
;


Any instructions on how to reach the enum 'PrimitiveType' would be appreciated.
Re: Accessing Enum from imported ECore model [message #1860233 is a reply to message #1860231] Mon, 24 July 2023 13:48 Go to previous messageGo to next message
Eclipse UserFriend
I can't follow you.
Enums are not cross refs
So you need to define and use a enum

DataType: type= PrimitiveType

enum PrimitiveType returns pfcsm::PrimitiveType: ..

[Updated on: Mon, 24 July 2023 13:48] by Moderator

Re: Accessing Enum from imported ECore model [message #1860236 is a reply to message #1860233] Mon, 24 July 2023 14:03 Go to previous messageGo to next message
Eclipse UserFriend
This is the enum from ECore:
index.php/fa/43345/0/

So I'm essentially building a local copy of it in my xtext grammar.

enum PrimitiveType returns pfcsm::PrimitiveType:
	String | Int | Double | Boolean
;


I'm assuming since they aren't cross refs this is the only way to maintain the 'same' enums in both abstract syntaxes?
Re: Accessing Enum from imported ECore model [message #1860237 is a reply to message #1860236] Mon, 24 July 2023 14:11 Go to previous messageGo to next message
Eclipse UserFriend
I've also run into this error trying to generate the xtext artifacts:
445  [main] ERROR xt.generator.XtextGeneratorLanguage  - [XtextLinkingDiagnostic: null:5 Couldn't resolve reference to EPackage 'http://www.example.org/pfcsm'., XtextLinkingDiagnostic: null:29 Couldn't resolve reference to EClassifier 'PrimitiveType'., TransformationDiagnostic: null:29 Cannot create type without declared package. (ErrorCode: UnknownMetaModelAlias)]
446  [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Problems running workflow org.mcmaster.pfcsm.operation.actiondsl.GenerateActiondsl: Problem parsing 'file:/C:/Users/sirch/eclipse-workspace/org.mcmaster.pfcsm.operation.actiondsl/../org.mcmaster.pfcsm.operation.actiondsl/src/org/mcmaster/pfcsm/operation/actiondsl/Actiondsl.xtext':
XtextLinkingDiagnostic: null:5 Couldn't resolve reference to EPackage 'http://www.example.org/pfcsm'.
XtextLinkingDiagnostic: null:29 Couldn't resolve reference to EClassifier 'PrimitiveType'.
TransformationDiagnostic: null:29 Cannot create type without declared package. (ErrorCode: UnknownMetaModelAlias)


How do I add my ECore model to path?

[Updated on: Mon, 24 July 2023 14:13] by Moderator

Re: Accessing Enum from imported ECore model [message #1860238 is a reply to message #1860237] Mon, 24 July 2023 14:25 Go to previous messageGo to next message
Eclipse UserFriend
yes you need to replicate in grammar. synatax could be different from ecore.
referencedResource in the workflow file to genmodel should solve this

[Updated on: Mon, 24 July 2023 14:25] by Moderator

Re: Accessing Enum from imported ECore model [message #1860239 is a reply to message #1860238] Mon, 24 July 2023 14:29 Go to previous messageGo to next message
Eclipse UserFriend
Does that mean I add the ecore model here?
index.php/fa/43346/0/

Not really sure how to do this "referencedResource in the workflow file to genmodel should solve this"
Re: Accessing Enum from imported ECore model [message #1860240 is a reply to message #1860239] Mon, 24 July 2023 14:30 Go to previous messageGo to next message
Eclipse UserFriend
no, the workflow file.
and the manifest.mf

(dont know where your ecores are)
Re: Accessing Enum from imported ECore model [message #1860241 is a reply to message #1860240] Mon, 24 July 2023 14:35 Go to previous messageGo to next message
Eclipse UserFriend
Currently my ecores and my xtext are all in my current workspace.

In my xtext manifest I've added my main ecore folder (not the generated ones) to my dependencies as required plug-ins and imported packages. And then in runtime I've also added the same main ecore project to class path, shown in the image above.

Is the workflow file the MWE2 file? Do I add something like:

module org.mcmaster.pfcsm.operation.actiondsl.GenerateActiondsl

import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*

var rootPath = ".."

import org.mcmaster.pfcsm
Re: Accessing Enum from imported ECore model [message #1860242 is a reply to message #1860241] Mon, 24 July 2023 14:41 Go to previous messageGo to next message
Eclipse UserFriend
isnt there a referencedResource already in this file?

also: dont mess with classpaths folders etc.

go to manifest
go to dependencies
add plugin that contains ecore to the required bundles

[Updated on: Mon, 24 July 2023 14:43] by Moderator

Re: Accessing Enum from imported ECore model [message #1860243 is a reply to message #1860242] Mon, 24 July 2023 14:56 Go to previous messageGo to next message
Eclipse UserFriend
I just added the reference but I'm still getting the same error.

I've removed the ecore model from the classpath, but left it in the dependencies as you said:
index.php/fa/43347/0/

Still getting the
Couldn't resolve reference to EPackage 'http://www.example.org/pfcsm'.
error. Is the MWE2 file the correct file to be editing or is there another one that I should be looking for?

[Updated on: Mon, 24 July 2023 15:15] by Moderator

Re: Accessing Enum from imported ECore model [message #1860244 is a reply to message #1860243] Mon, 24 July 2023 14:59 Go to previous messageGo to next message
Eclipse UserFriend
can you please share your project layouts, where the ecore and genmodels are etc, the workflow file etc.
there are 100000 possible combinations i cannot guess

e.g.

add

referencedResource="platform:/resource/org.mcmaster.pfcsm/model/whatever.genmodel"
to the language section of the workflow

[Updated on: Mon, 24 July 2023 15:01] by Moderator

Re: Accessing Enum from imported ECore model [message #1860245 is a reply to message #1860244] Mon, 24 July 2023 15:08 Go to previous messageGo to next message
Eclipse UserFriend
Here is an image of the project explorer
index.php/fa/43348/0/

I've also zipped up the projects together if it helps.
Re: Accessing Enum from imported ECore model [message #1860246 is a reply to message #1860245] Mon, 24 July 2023 15:12 Go to previous messageGo to next message
Eclipse UserFriend
adjusting workflow to

language = StandardLanguage {
referencedResource="platform:/resource/org.mcmaster.pfcsm/model/pfcsm.genmodel"


works perfectly fine for me
Re: Accessing Enum from imported ECore model [message #1860247 is a reply to message #1860246] Mon, 24 July 2023 15:17 Go to previous message
Eclipse UserFriend
Ok I didn't understand that it wasn't in the import section of the MWE2 file that needed to be changed. I've added that to the same spot and it works now too for me.

Thanks for the help and sorry for the confusion.

Also for anyone else reading this later workflow file is the MWE2 file for the dsl.
Previous Topic:Vscode plugin issue (OutPutStream issue)
Next Topic:Arithmetic defined in xtext
Goto Forum:
  


Current Time: Wed Mar 19 03:25:43 EDT 2025

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

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

Back to the top