Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » References to UML elements
References to UML elements [message #1720458] Mon, 18 January 2016 18:32 Go to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 359
Registered: March 2011
Senior Member
Hi. I'm developing a language that supports references to UML elements, but I'm having trouble building with Xtext 2.9.1.

The abstract syntax for the language is an Ecore model that has an EClass called "UMLProtocol" with a single 'collaboration' attribute that is a reference to a UML Collaboration.

The relevant parts of the Xtext grammar are the following:

grammar org.eclipse.papyrusrt.xtumlrt.xtext.Umlrt with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.eclipse.org/papyrusrt/xtumlrt/common"
import "http://www.eclipse.org/papyrusrt/xtumlrt/umlrt"
import "http://www.eclipse.org/uml2/5.0.0/UML" as uml   // (1)

Import returns AbstractImport:
    'import' 'ns' {Import} importedNamespace=QualifiedName ('.*')?
    | 'import' 'uri' {URIImport} importURI=STRING
;

QualifiedName:
    ID ('.' ID)*
;

// ...

fragment ProtocolReferenceFragment returns RTPort:
    ':' type=[Protocol | QualifiedName]
    | ':' 'uml' type=[UMLProtocol | QualifiedName]
;


The workflow is this:

module org.eclipse.papyrusrt.xtumlrt.xtext.GenerateTumlrt

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

var rootPath = ".."

Workflow {
	
	component = XtextGenerator {
		configuration = {
			project = StandardProjectConfig {
				baseName = "org.eclipse.papyrusrt.xtumlrt.xtext"
				rootPath = rootPath
				runtimeTest = {
					enabled = true
				}
				eclipsePlugin = {
					enabled = true
				}
				eclipsePluginTest = {
					enabled = true
				}
				createEclipseMetaData = true
			}
			code = {
				encoding = "UTF-8"
				fileHeader = "/*\n * generated by Xtext \${version}\n */"
			}
		}
		language = StandardLanguage {
			name = "org.eclipse.papyrusrt.xtumlrt.xtext.Tumlrt"
			fileExtensions = "umlrt"
			referencedResource = "platform:/resource/org.eclipse.papyrusrt.xtumlrt.umlrt.model/model/umlrt.genmodel"
			referencedResource = "platform:/resource/org.eclipse.papyrusrt.xtumlrt.common.model/model/common.genmodel"
			
			fragment = ecore2xtext.Ecore2XtextValueConverterServiceFragment2 auto-inject {}

			fragment = org.eclipse.xtext.generator.adapter.FragmentAdapter {
				fragment = org.eclipse.xtext.generator.ecore2xtext.FormatterFragment {}
			}

			serializer = {
				generateStub = false
			}
			validator = {
				// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			}
		}
	}
}


but when running it I get this:

0    [main] INFO  text.xtext.generator.XtextGenerator  - Initializing Xtext generator
9    [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'org.eclipse.xtext.common.types.TypesPackage'
209  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.eclipse.papyrusrt.xtumlrt.xtext at 'file:/Users/epp/Development/PapyrusRT/git/org.eclipse.papyrus-rt/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/'
209  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.eclipse.papyrusrt.xtumlrt.xtext.tests at 'file:/Users/epp/Development/PapyrusRT/git/org.eclipse.papyrus-rt/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext.tests/'
209  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.eclipse.papyrusrt.xtumlrt.xtext.ide at 'file:/Users/epp/Development/PapyrusRT/git/org.eclipse.papyrus-rt/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext.ide/'
209  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.eclipse.papyrusrt.xtumlrt.xtext.ui at 'file:/Users/epp/Development/PapyrusRT/git/org.eclipse.papyrus-rt/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext.ui/'
209  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.eclipse.papyrusrt.xtumlrt.xtext.ui.tests at 'file:/Users/epp/Development/PapyrusRT/git/org.eclipse.papyrus-rt/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext.ui.tests/'
224  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Using resourceSet registry. The registered Packages will not be registered in the global EPackage.Registry.INSTANCE!
583  [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/Xtext/Xbase/XAnnotations' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
588  [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/xbase/Xtype' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
614  [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/xbase/Xbase' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
614  [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/common/JavaVMTypes' from 'platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel'
712  [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/papyrusrt/xtumlrt/umlrt' from 'platform:/resource/org.eclipse.papyrusrt.xtumlrt.umlrt.model/model/umlrt.genmodel'
712  [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/papyrusrt/xtumlrt/common' from 'platform:/resource/org.eclipse.papyrusrt.xtumlrt.common.model/model/common.genmodel'
713  [main] ERROR xt.generator.XtextGeneratorLanguage  - Error loading 'platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel'
713  [main] ERROR xt.generator.XtextGeneratorLanguage  - Error loading 'platform:/plugin/org.eclipse.uml2.types/model/Types.genmodel'
713  [main] ERROR xt.generator.XtextGeneratorLanguage  - Error loading 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel'
1325 [main] ERROR xt.generator.XtextGeneratorLanguage  - [XtextLinkingDiagnostic: null:7 Couldn't resolve reference to EPackage 'http://www.eclipse.org/uml2/5.0.0/UML'., TransformationDiagnostic: null:27 Cannot find compatible feature importURI in sealed EClass URIImport from imported package http://www.eclipse.org/papyrusrt/xtumlrt/umlrt: The existing attribute 'importURI' has an incompatible type 'null'. The expected type is 'EString' [java.lang.String]. (ErrorCode: CannotCreateTypeInSealedMetamodel)]
1328 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Problems running workflow org.eclipse.papyrusrt.xtumlrt.xtext.GenerateTumlrt: Problem parsing 'file:/Users/epp/Development/PapyrusRT/git/org.eclipse.papyrus-rt/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/../org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/Tumlrt.xtext':
XtextLinkingDiagnostic: null:7 Couldn't resolve reference to EPackage 'http://www.eclipse.org/uml2/5.0.0/UML'.
TransformationDiagnostic: null:27 Cannot find compatible feature importURI in sealed EClass URIImport from imported package http://www.eclipse.org/papyrusrt/xtumlrt/umlrt: The existing attribute 'importURI' has an incompatible type 'null'. The expected type is 'EString' [java.lang.String]. (ErrorCode: CannotCreateTypeInSealedMetamodel)
java.lang.RuntimeException: Problems running workflow org.eclipse.papyrusrt.xtumlrt.xtext.GenerateTumlrt: Problem parsing 'file:/Users/epp/Development/PapyrusRT/git/org.eclipse.papyrus-rt/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/../org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/Tumlrt.xtext':
XtextLinkingDiagnostic: null:7 Couldn't resolve reference to EPackage 'http://www.eclipse.org/uml2/5.0.0/UML'.
TransformationDiagnostic: null:27 Cannot find compatible feature importURI in sealed EClass URIImport from imported package http://www.eclipse.org/papyrusrt/xtumlrt/umlrt: The existing attribute 'importURI' has an incompatible type 'null'. The expected type is 'EString' [java.lang.String]. (ErrorCode: CannotCreateTypeInSealedMetamodel)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:104)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:78)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:36)
Caused by: java.lang.IllegalStateException: Problem parsing 'file:/Users/epp/Development/PapyrusRT/git/org.eclipse.papyrus-rt/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/../org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/Tumlrt.xtext':
XtextLinkingDiagnostic: null:7 Couldn't resolve reference to EPackage 'http://www.eclipse.org/uml2/5.0.0/UML'.
TransformationDiagnostic: null:27 Cannot find compatible feature importURI in sealed EClass URIImport from imported package http://www.eclipse.org/papyrusrt/xtumlrt/umlrt: The existing attribute 'importURI' has an incompatible type 'null'. The expected type is 'EString' [java.lang.String]. (ErrorCode: CannotCreateTypeInSealedMetamodel)
	at org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage.initialize(XtextGeneratorLanguage.java:280)
	at org.eclipse.xtext.xtext.generator.StandardLanguage.initialize(StandardLanguage.java:166)
	at org.eclipse.xtext.xtext.generator.XtextGenerator.initialize(XtextGenerator.java:176)
	at org.eclipse.xtext.xtext.generator.XtextGenerator.checkConfigurationInternal(XtextGenerator.java:120)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent2.checkConfiguration(AbstractWorkflowComponent2.java:21)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.preInvoke(Mwe2Bridge.java:65)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.preInvoke(AbstractWorkflowComponent.java:197)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.preInvoke(AbstractCompositeWorkflowComponent.java:29)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:18)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
	... 4 more



Now, I do not have org.eclipse.uml2.uml as a project in my workspace but it is installed, Xtext recognizes it to be a registered package and I expect it to be available in the target platform.

Furthermore, I have installed the latest UML2, which is 5.1.0. It would seem like an error in line (1) in the grammar where I use 'import "http://www.eclipse.org/uml2/5.0.0/UML" as uml', but it turns out that the Ns URI declared in UML.ecore is "http://www.eclipse.org/uml2/5.0.0/UML". (If I change that line to 5.1.0, the Xtext editor points an error, with 5.0.0 it only shows a warning saying that the package contains references to elements in the package registry and not in the workspace)

Why is it complaining about not finding the package if I have it installed? I have checked and both UML.ecore and UML.genmodel are included in the jar file under the 'model' folder.

Given the warning message, is it not possible to have references to elements that are not in the workspace? Would I have to import org.eclipse.uml2.uml as a project in the workspace for it to work?

I tried adding

			referencedResource = "platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel"


to the StandardLanguage configuration, but then it fails when registering the packages saying that it doesn't recognize the 'platform' protocol.

I thought it could be dealt with by adding a URI map, as it used to be possible with the old workflow, but I can't find how to add URI maps in the new configuration style.

It's also complaining about the type importURI attribute, but the type is set to EString in the model.

Any help is appreciated.

Thanks.

Re: References to UML elements [message #1720468 is a reply to message #1720458] Mon, 18 January 2016 18:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12360
Registered: July 2009
Senior Member
hi

referencedResource = "platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel" should work fine.
debug org.eclipse.emf.mwe.utils.StandaloneSetup.setScanClassPath(boolean) for details

can you file a bug for the warning thing



Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: References to UML elements [message #1720471 is a reply to message #1720468] Mon, 18 January 2016 19:45 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 359
Registered: March 2011
Senior Member
Thanks, but it didn't quite work. Now I get:

897  [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Problems running workflow org.eclipse.papyrusrt.xtumlrt.xtext.GenerateTumlrt: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.eclipse.org/uml2/2.2.0/GenModel' not found. (platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel, 13, 84)
java.lang.RuntimeException: Problems running workflow org.eclipse.papyrusrt.xtumlrt.xtext.GenerateTumlrt: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.eclipse.org/uml2/2.2.0/GenModel' not found. (platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel, 13, 84)


I see that UML.genmodel does indeed have a reference to 2.2.0/GenModel.

But I cannot find this in the latest UML2.

Am I missing a dependency? Where would I get that GenModel?

I also found this:

https://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/

but the instructions there are for the old-style workflow.

Are there some other missing registrations necessary?

As for the rest of the instructions (providing an IResourceServiceProvider, UmlResourceDescriptionStrategy, etc.) still required or has this been subsumed by more recent versions of Xtext?

Thanks


Re: References to UML elements [message #1720475 is a reply to message #1720471] Mon, 18 January 2016 20:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12360
Registered: July 2009
Senior Member
can you try this with the "old" generator?

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: References to UML elements [message #1720478 is a reply to message #1720475] Mon, 18 January 2016 20:35 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 359
Registered: March 2011
Senior Member
I tried with the old-style workflow (below) and it succeeds, but there are some strange errors:

1761 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel'
1761 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel'
1761 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.uml2.types/model/Types.genmodel'
1761 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel'


I also discovered that the uml2/2.2.0/GenModel was located under org.eclipse.uml2.codegen.ecore. I added it to the referencedResources, to the list of dependencies and to the usedGenPackages of my genmodel, but it made no difference.

Now I'm confused: since it works with the old-style worflow, there's something about the new style that may have a bug, but even with the old-style it complains with those errors, which after debugging I found something bizarre: those genmodels are added to the resource set, but when actually loading their contents, the contents are empty! It seems that this doesn't bother the Xtext generator, though. This is strange.

Could this be a bug?

I'd like to use the new-style workflow.

The old-style workflow that works is this:

module org.eclipse.papyrusrt.xtumlrt.xtext.Tumlrt

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*

var projectName = "org.eclipse.papyrusrt.xtumlrt.xtext"
var grammarURI = "platform:/resource/${projectName}/src/org/eclipse/papyrusrt/xtumlrt/xtext/Tumlrt.xtext"
var fileExtensions = "umlrt"
var generateXtendStub = true
//var workspaceDefault = "./source"   This should be the value for the workspace provided by the maven build
var workspaceDefault = "../../../.."
var workspace = "${workspaceDefault}"
var xtumlrtBaseDir = "${workspace}/plugins/xtumlrt"
var xtextBaseDir = "${xtumlrtBaseDir}/xtext"
var umlrtCodeGenDir = "${workspace}/plugins/umlrt/codegen"
var platformUri = xtumlrtBaseDir
var runtimeProject = "${xtextBaseDir}/${projectName}"

Workflow {
    bean = StandaloneSetup {
        // use an XtextResourceset throughout the process, which is able to resolve classpath:/ URIs.
        resourceSet = org.eclipse.xtext.resource.XtextResourceSet:theResourceSet {}
        scanClassPath  = true
        platformUri = "${platformUri}"
        // add mappings from platform:/resource to classpath:/
        uriMap = {
            from = "platform:/resource/org.eclipse.xtext.xbase/"
            to = "classpath:/"
        }
        uriMap = {
            from = "platform:/resource/org.eclipse.xtext.common.types/"
            to = "classpath:/"
        }
        uriMap = {
            from = "platform:/resource/org.eclipse.papyrusrt.xtumlrt.common.model/"
            to = "${xtumlrtBaseDir}/metamodel/org.eclipse.papyrusrt.xtumlrt.common.model/"
        }
        uriMap = {
            from = "platform:/resource/org.eclipse.papyrusrt.xtumlrt.umlrt.model/"
            to = "${xtumlrtBaseDir}/metamodel/org.eclipse.papyrusrt.xtumlrt.umlrt.model/"
        }
        uriMap = {
            from = "platform:/resource/org.eclipse.papyrusrt.codegen.statemachines.flat.model/model/smflatmodel.genmodel"
            to = "${umlrtCodeGenDir}/org.eclipse.papyrusrt.codegen.statemachines.flat.model/model/smflatmodel.genmodel"
        }
        registerGenModelFile = "platform:/resource/org.eclipse.papyrusrt.xtumlrt.common.model/model/common.genmodel"
        registerGenModelFile = "platform:/resource/org.eclipse.papyrusrt.xtumlrt.umlrt.model/model/umlrt.genmodel"
        registerGeneratedEPackage = "org.eclipse.papyrusrt.xtumlrt.common.CommonPackage"
        registerGeneratedEPackage = "org.eclipse.papyrusrt.xtumlrt.umlrt.UmlrtPackage"
//      registerGeneratedEPackage = "org.eclipse.papyrusrt.codegen.statemachines.flat.model"
//      registerGenModelFile = "platform:/resource/org.eclipse.papyrusrt.codegen.statemachines.flat.model/model/smflatmodel.genmodel"
    }

    component = DirectoryCleaner {
        directory = "${runtimeProject}/src-gen"
    }

    component = DirectoryCleaner {
        directory = "${runtimeProject}.ui/src-gen"
    }

    component = Generator {
        pathRtProject = runtimeProject
        pathUiProject = "${runtimeProject}.ui"
        pathTestProject = "${runtimeProject}.tests"
        projectNameRt = projectName
        projectNameUi = "${projectName}.ui"
        language = auto-inject {
            forcedResourceSet = theResourceSet
            uri = grammarURI

            // Java API to access grammar elements (required by several other fragments)
            fragment = grammarAccess.GrammarAccessFragment auto-inject {}

            // generates Java API for the generated EPackages
            // fragment = ecore.EcoreGeneratorFragment auto-inject {}

            // the Ecore2Xtext specific terminal converter
            fragment = ecore2xtext.Ecore2XtextValueConverterServiceFragment auto-inject {}

            // serializer 2.0
            fragment = serializer.SerializerFragment auto-inject {
                //generateStub = false
            }

            // the old serialization component
            // fragment = parseTreeConstructor.ParseTreeConstructorFragment auto-inject {}

            // a custom ResourceFactory for use with EMF 
            fragment = resourceFactory.ResourceFactoryFragment auto-inject {}

            // the Antlr parser
            fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject {
                options = {
                    classSplitting = true
                }
            }

            // Xtend-based API for validation 
            fragment = validation.ValidatorFragment auto-inject {
            // composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
            // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
            }

            // old scoping and exporting API 
            // fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
            // fragment = exporting.QualifiedNamesFragment auto-inject {}

            // scoping and exporting API
            fragment = scoping.ImportURIScopingFragment auto-inject {}
            fragment = exporting.SimpleNamesFragment auto-inject {}
            fragment = builder.BuilderIntegrationFragment auto-inject {}        

            // generator API
            fragment = generator.GeneratorFragment auto-inject {}

            // formatter API 
            // fragment = formatting.FormatterFragment auto-inject {}
            fragment = ecore2xtext.FormatterFragment auto-inject {}

            // labeling API 
            fragment = labeling.LabelProviderFragment auto-inject {}

            // outline API 
            fragment = outline.OutlineTreeProviderFragment auto-inject {}
            fragment = outline.QuickOutlineFragment auto-inject {}

            // quickfix API
            fragment = quickfix.QuickfixProviderFragment auto-inject {}

            //content assist API 
            fragment = contentAssist.ContentAssistFragment auto-inject {}

            // antlr parser generator tailored for content assist 
            fragment = parser.antlr.XtextAntlrUiGeneratorFragment auto-inject {
                options = {
                    classSplitting = true
                }
            }
            
            // generates junit test support classes into Generator#pathTestProject
            fragment = junit.Junit4Fragment auto-inject {}

            // project wizard (optional) 
            // fragment = projectWizard.SimpleProjectWizardFragment auto-inject {
            //      generatorProjectName = "${projectName}.generator" 
            // }

            // rename refactoring
            fragment = refactoring.RefactorElementNameFragment auto-inject {}

            // provides the necessary bindings for java types integration
            fragment = types.TypesGeneratorFragment auto-inject {}
            
            // generates the required bindings only if the grammar inherits from Xbase
            fragment = xbase.XbaseGeneratorFragment auto-inject {}
            
            // generates the required bindings only if the grammar inherits from Xtype
            fragment = xbase.XtypeGeneratorFragment auto-inject {}

            // provides a preference page for template proposals
            fragment = templates.CodetemplatesGeneratorFragment auto-inject {}

            // provides a compare view
            fragment = compare.CompareFragment auto-inject {}
        }
    }
}
Re: References to UML elements [message #1720480 is a reply to message #1720478] Mon, 18 January 2016 21:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12360
Registered: July 2009
Senior Member
can you please file a ticket.
this usecase should work in the new generator as well.
a simple patch to add the mapping is not enhough though


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: References to UML elements [message #1720483 is a reply to message #1720480] Mon, 18 January 2016 21:08 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 359
Registered: March 2011
Senior Member
Sure, I'll open a bug.
Re: References to UML elements [message #1720487 is a reply to message #1720483] Mon, 18 January 2016 21:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12360
Registered: July 2009
Senior Member
i came so far but now i am stuck

bean = org.xtext.example.mydsl2.UriMapper {
		uriMap = {
            from = "platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"
            to = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel"
            to = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"
            to = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel"
            to = "platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.ecore"
            to = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.ecore"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"
            to = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.types/model/Types.ecore"
            to = "platform:/resource/org.eclipse.uml2.types/model/Types.ecore"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.types/model/Types.genmodel"
            to = "platform:/resource/org.eclipse.uml2.types/model/Types.genmodel"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore"
            to = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore"
            to = "platform:/resource/org.eclipse.uml2.uml/model/UML.ecore"
        }
	}
	
	component = XtextGenerator {


package org.xtext.example.mydsl2;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.mwe.core.ConfigurationException;
import org.eclipse.emf.mwe.utils.Mapping;
import org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage;

public class UriMapper {
	
	public UriMapper() {
		EPackage p = GenModelPackage.eINSTANCE;
	}
	
	public void addUriMap(final Mapping uriMap) {
		final URI baseUri = URI.createURI(uriMap.getFrom());
		final URI mappedUri = URI.createURI(uriMap.getTo());
		if (mappedUri == null)
			throw new ConfigurationException("cannot make URI out of " + uriMap.getTo());
		else {
			URIConverter.URI_MAP.put(baseUri, mappedUri);
		}
	}

}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: References to UML elements [message #1720488 is a reply to message #1720487] Mon, 18 January 2016 21:31 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 359
Registered: March 2011
Senior Member
Is this with the old-style or the new-style workflow?

PS: I've opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=486070.

Re: References to UML elements [message #1720506 is a reply to message #1720488] Tue, 19 January 2016 05:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12360
Registered: July 2009
Senior Member
this is the new style

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: References to UML elements [message #1720608 is a reply to message #1720506] Tue, 19 January 2016 17:53 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 359
Registered: March 2011
Senior Member
I tried adding the uriMaps to the old style (in the StandAloneSetup) and got an interesting result:

Before these uri maps, I was getting:

1761 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel'
1761 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel'
1761 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.uml2.types/model/Types.genmodel'
1761 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel'


With the old-style, even with those errors, generation succeeds.

But if I add

        uriMap = {
            from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"
            to = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel"
            to = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore"
            to = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"
            to = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore"
            to = "platform:/resource/org.eclipse.uml2.uml/model/UML.ecore"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel"
            to = "platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.types/model/Types.ecore"
            to = "platform:/resource/org.eclipse.uml2.types/model/Types.ecore"
        }
        uriMap = {
            from = "platform:/plugin/org.eclipse.uml2.types/model/Types.genmodel"
            to = "platform:/resource/org.eclipse.uml2.types/model/Types.genmodel"
        }


to StandaloneSetup, then I only get this:

3347 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel'
3347 [main] ERROR ipse.xtext.generator.LanguageConfig  - Error loading 'platform:/plugin/org.eclipse.uml2.types/model/Types.genmodel'


and generation succeeds as well.

I noticed that I needed to add maps for both the .ecore and .genmodel files.

Furthermore, if I open UML.genmodel I see that there is a "Problems" tab and when I open it I get what is shown in the attachment.

The first problem shows an exception:

java.io.IOException: Archive entry not found archive:file:/Users/epp/Development/PapyrusRT/ides/mars-sdk/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.uml2.uml_5.1.0.v20150906-1225.jar!/../org.eclipse.emf.ecore/model/Ecore.ecore
	at org.eclipse.emf.common.archive.ArchiveURLConnection.getInputStream(ArchiveURLConnection.java:246)
	at org.eclipse.emf.ecore.resource.impl.ArchiveURIHandlerImpl.createInputStream(ArchiveURIHandlerImpl.java:53)
	at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:360)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1269)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
...


Notice that the uri begins with 'archive:', so I suspect that might be part of the problem.

The second problem is very similar but it is with the Types.ecore file. The rest of the problems seem to be about being able to resolve proxies which point to either Ecore.ecore or Types.ecore (the files with the first problems).

This might be a hint of the problem, but I don't know what I can do about it.
Re: References to UML elements [message #1720837 is a reply to message #1720608] Thu, 21 January 2016 10:54 Go to previous messageGo to next message
Miro Spönemann is currently offline Miro SpönemannFriend
Messages: 50
Registered: March 2015
Location: Kiel, Germany
Member

I tried to reproduce a similar setup and it works if I add a StandaloneSetup as described Christians blog. You can still use the StandaloneSetup with the new Xtext 2.9 workflow style. Try adding

bean = org.eclipse.emf.mwe.utils.StandaloneSetup {
	platformUri = rootPath
	scanClassPath = true
    uriMap = {
        from = "platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"
        to = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"
    }
    uriMap = {
        from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel"
        to = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel"
    }
    uriMap = {
        from = "platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"
        to = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"
    }
    uriMap = {
        from = "platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel"
        to = "platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel"
    }
    uriMap = {
        from = "platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.ecore"
        to = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.ecore"
    }
    uriMap = {
        from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"
        to = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore"
    }
    uriMap = {
        from = "platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore"
        to = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore"
    }
    uriMap = {
        from = "platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore"
        to = "platform:/resource/org.eclipse.uml2.uml/model/UML.ecore"
    }
    uriMap = {
        from = "platform:/plugin/org.eclipse.uml2.types/model/Types.genmodel"
        to = "platform:/resource/org.eclipse.uml2.types/model/Types.genmodel"
    }
    registerGeneratedEPackage = "org.eclipse.emf.ecore.EcorePackage"
    registerGeneratedEPackage = "org.eclipse.uml2.uml.UMLPackage"
    registerGeneratedEPackage = "org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage"
    registerGeneratedEPackage = "org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage"
    registerGenModelFile = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel"
    registerGenModelFile = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"
    registerGenModelFile = "platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel"
    registerGenModelFile = "platform:/resource/org.eclipse.uml2.types/model/Types.genmodel"
    registerGenModelFile = "platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel"
}
Re: References to UML elements [message #1721032 is a reply to message #1720468] Fri, 22 January 2016 17:59 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 359
Registered: March 2011
Senior Member
OK, I have an even more basic problem now. Even before attempting generation, I see an error on the Xtext editor in the rule that has a reference to a UML element complaining that it cannot find a compatible feature in the relevant "sealed" EClass.

I've prepared a minimalistic example (attached) to show the problem.

In this example there is a (meta)class called "UMLClass" which has a reference named 'umlclass' to the UML Class element from UML.ecore.

First in line

import "http://www.eclipse.org/uml2/5.0.0/UML" as uml


I get this warning:

The imported package refers to elements in the package registry
   instead of using the instances from the workspace


and then in the following rule:

UMLClass returns UMLClass:
    'umlclass' name=EString '=' umlclass=[uml::Class|EString];


I get this error:

Cannot find compatible feature umlclass in sealed EClass UMLClass from imported package http://www.example.org/oblang: The type 'Class' used in the reference 'umlclass' is inconsistent. Probably this is due to an unsupported kind of metamodel hierarchy.	Oblang.xtext	/eposse.experiments.xtext.oblang/src/eposse/experiments/xtext/oblang	line: 18 /eposse.experiments.xtext.oblang/src/eposse/experiments/xtext/oblang/Oblang.xtext	Grammar Problem


but as you can see in the attached model, the feature is there.

the package that contains UML.ecore is org.eclipse.uml2.uml, which also has UML.genmodel and itself depends on org.eclipse.uml2.types which contains Types.ecore and Types.genmodel, all of these are installed and declared as dependencies in the plugin.

What's the problem? How can I solve this?

I also noticed that the error log has a bunch of exceptions that may be related:

java.lang.SecurityException: SHA1 digest error for model/UML.ecore
	at sun.security.util.ManifestEntryVerifier.verify(ManifestEntryVerifier.java:218)
	at java.util.jar.JarVerifier.processEntry(JarVerifier.java:241)
	at java.util.jar.JarVerifier.update(JarVerifier.java:228)
	at java.util.jar.JarVerifier$VerifierStream.read(JarVerifier.java:482)
	at java.io.FilterInputStream.read(FilterInputStream.java:133)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2928)
	at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:302)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1790)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanContent(XMLEntityScanner.java:958)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2820)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:265)
	at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:25)
	at org.eclipse.xtext.builder.resourceloader.SerialResourceLoader$1.next(SerialResourceLoader.java:47)
	at org.eclipse.xtext.builder.resourceloader.AbstractResourceLoader$CheckedLoadOperation.next(AbstractResourceLoader.java:77)
	at org.eclipse.xtext.builder.clustering.ClusteringBuilderState.writeNewResourceDescriptions(ClusteringBuilderState.java:382)
	at org.eclipse.xtext.builder.clustering.ClusteringBuilderState.doUpdate(ClusteringBuilderState.java:135)
	at org.eclipse.xtext.builder.builderState.AbstractBuilderState.update(AbstractBuilderState.java:116)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:287)
	at org.eclipse.xtext.builder.impl.XtextBuilder.fullBuild(XtextBuilder.java:319)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:155)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:359)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:382)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)


For reference I have the following installed:

Eclipse SDK 4.5.1.M20150904-0015
EMF - Eclipse Modeling Framework SDK 2.12.0.v20150928-0952
UML2 Extender SDK 5.1.1.v20150906-1225
Xtext Antlr Runtime Feature 2.1.1.v201405091103
Xtext Antlr SDK Feature 2.1.1.v201405091103
Xtext Complete SDK 2.9.1.v201512180746
Xtext Redistributable 2.9.1.v201512180746

Thanks.

Re: References to UML elements [message #1789814 is a reply to message #1720458] Thu, 31 May 2018 04:39 Go to previous messageGo to next message
Anton Hughes is currently offline Anton HughesFriend
Messages: 66
Registered: January 2013
Member
Hi

Did anyone manage to get this working?

Im also interested in using UML types in Xtext.

Thanks
Re: References to UML elements [message #1789865 is a reply to message #1789814] Thu, 31 May 2018 05:27 Go to previous message
Tamas Miklossy is currently offline Tamas MiklossyFriend
Messages: 20
Registered: February 2016
Junior Member
A nice presentation about referencing UML models from Xtext is available under https://www.youtube.com/watch?v=teOULtQ81-U
Previous Topic:Xtext 2.13 update site
Next Topic:runtime version of generated model
Goto Forum:
  


Current Time: Wed Nov 14 11:16:19 GMT 2018

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

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

Back to the top