Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xcore -> Xtext
Xcore -> Xtext [message #1082529] Thu, 08 August 2013 13:58 Go to next message
Eclipse UserFriend
Just read Jan's excellent: http://koehnlein.blogspot.ca/2013/06/using-xcore-in-xtext.html at his suggestion.

Currently I'm using the xcore -> genmodel -> xtext approach for referring to the imported gen model, but I can't get the score version working quite yet..

I have EMF Metamodels (only) activated. In the mwe I'm currently importing registering the package like:

	bean = StandaloneSetup {
		scanClassPath  = true
		platformUri = "${runtimeProject}/.."
		registerGeneratedEPackage = "my.MyPackage"
		registerGenModelFile = "platform:/resource/my/model/My.genmodel"
	}


I tried adding a line to the (xtext project wizard created) generator component thus:

		language = auto-inject {
			uri = grammarURI
... many lines later
            loadedResource = "platform:/resource/my/model/My.xcore"
		}


Then at Jan's suggestion I removed the registerGenModelFile line and when that didn't work the registerGeneratedEPackage as well.

I'm importing the source xcore/ecore like this :

import "my"


Could you post an example workflow for setting this up?
Re: Xcore -> Xtext [message #1082554 is a reply to message #1082529] Thu, 08 August 2013 14:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

what is exactly not working?
http://www.eclipse.org/forums/index.php/m/1077807/

~Christian
Re: Xcore -> Xtext [message #1082557 is a reply to message #1082554] Thu, 08 August 2013 15:05 Go to previous messageGo to next message
Eclipse UserFriend
Sorry, should have mentioned that. Smile Without registering the genmodel, the workflow won't run, reporting that it can't find the packages. So it doesn't seem able to import the xcore model from the loadedResource line alone.
Re: Xcore -> Xtext [message #1082573 is a reply to message #1082557] Thu, 08 August 2013 15:31 Go to previous messageGo to next message
Eclipse UserFriend
hmm in my case it actually works...
which version of Xtext and Xcore do you use.
what is the error message you get?
Re: Xcore -> Xtext [message #1082613 is a reply to message #1082573] Thu, 08 August 2013 16:45 Go to previous messageGo to next message
Eclipse UserFriend
See below..as noted, it simply can't find the referenced packages.

Note btw, that I'm referring to an xcore model defined in a separate project. I've also included import for org.eclipse.emf.ecore.xcore;bundle-version="1.1.0",

I'm running EMF 2.9, Xcore 1.1 and Xtext 2.4 respectivly..

...snip..
Caused by: java.lang.IllegalStateException: Problem parsing 'classpath:/my/My.xtext':[XtextLinkingDiagnostic: null:4 Couldn't resolve reference to EPackage 'my..'., XtextLinkingDiagnostic: null:7 Couldn't resolve reference to EClassifier 'MyRootClass'....]
	at org.eclipse.xtext.generator.LanguageConfig.setUri(LanguageConfig.java:211)
	... 42 more
Re: Xcore -> Xtext [message #1082618 is a reply to message #1082613] Thu, 08 August 2013 16:51 Go to previous messageGo to next message
Eclipse UserFriend
hmmm i am using xcore 1.0 sure the names of the package you are importing is correct?
Re: Xcore -> Xtext [message #1082663 is a reply to message #1082613] Thu, 08 August 2013 18:22 Go to previous messageGo to next message
Eclipse UserFriend
Oh, I forgot to mention that interestingly, the xtext grammar parses just fine, it's fully aware of the xcore. So it's got to be something in the workflow itself...

Are you using the same basic mwe2 as the xtext project wizard creates?

thanks,

Miles
Re: Xcore -> Xtext [message #1082664 is a reply to message #1082618] Thu, 08 August 2013 18:23 Go to previous messageGo to next message
Eclipse UserFriend
Christian Dietrich wrote on Thu, 08 August 2013 16:51
hmmm i am using xcore 1.0 sure the names of the package you are importing is correct?


Well, yeah definetely. Because again, it works just fine when I load the package from genmodel. Also see msg above, it works for the .xtext editor as well.
Re: Xcore -> Xtext [message #1082857 is a reply to message #1082664] Fri, 09 August 2013 01:47 Go to previous messageGo to next message
Eclipse UserFriend
hmmm strange could you pack a sample project to reproduce?
Re: Xcore -> Xtext [message #1082885 is a reply to message #1082663] Fri, 09 August 2013 02:49 Go to previous messageGo to next message
Eclipse UserFriend
Did you try to also skip the registerGeneratedEPackage?
If the Xcore is loaded into the resource set, the ecore and the genmodel
can be found there, so no need for registration in StandaloneSetup.


Am 09.08.13 00:22, schrieb Miles Parker:
> Oh, I forgot to mention that interestingly, the xtext grammar parses
> just fine, it's fully aware of the xcore. So it's got to be something in
> the workflow itself...
>
> Are you using the same basic mwe2 as the xtext project wizard creates?
>
> thanks,
>
> Miles


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Xcore -> Xtext [message #1083324 is a reply to message #1082885] Fri, 09 August 2013 16:17 Go to previous messageGo to next message
Eclipse UserFriend
Jan Kohnlein wrote on Fri, 09 August 2013 02:49
Did you try to also skip the registerGeneratedEPackage?
If the Xcore is loaded into the resource set, the ecore and the genmodel
can be found there, so no need for registration in StandaloneSetup.


Yeah, that's what I was assuming, but I tried all three possibilities and none of them worked.

I'll try to reproduce w/ a sanitized set of projects next week..

But in the meantime, could you post the entire mew2 workflow from your example in case I'm missing something obvious?
Re: Xcore -> Xtext [message #1083329 is a reply to message #1083324] Fri, 09 August 2013 16:26 Go to previous messageGo to next message
Eclipse UserFriend
module org.xtext.example.mydsl.GenerateMyDsl

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

var grammarURI = "classpath:/org/xtext/example/mydsl/MyDsl.xtext"
var fileExtensions = "mydsl"
var projectName = "org.xtext.example.mydsl"
var runtimeProject = "../${projectName}"
var generateXtendStub = true

Workflow {
    bean = StandaloneSetup {
    	scanClassPath = true
    	platformUri = "${runtimeProject}/.."
    	// The following two lines can be removed, if Xbase is not used.
    	registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage"
    	registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}/src-gen"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}.ui/src-gen"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}.tests/src-gen"
    }
    
    component = Generator {
    	pathRtProject = runtimeProject
    	pathUiProject = "${runtimeProject}.ui"
    	pathTestProject = "${runtimeProject}.tests"
    	projectNameRt = projectName
    	projectNameUi = "${projectName}.ui"
    	language = auto-inject {
    		loadedResource = "platform:/resource/org.eclipse.emf.ecore.xcore.lib/model/XcoreLang.xcore"
    		loadedResource = "platform:/resource/test.xcore/model/test.xcore"
    		
    		uri = grammarURI
    
    		// Java API to access grammar elements (required by several other fragments)
    		fragment = grammarAccess.GrammarAccessFragment auto-inject {}
    
    		
    
    		// the old serialization component
    		// fragment = parseTreeConstructor.ParseTreeConstructorFragment auto-inject {}    
    
    		// serializer 2.0
    		fragment = serializer.SerializerFragment auto-inject {
    			generateStub = false
    		}
    
    		// a custom ResourceFactory for use with EMF
    		fragment = resourceFactory.ResourceFactoryFragment auto-inject {}
    
    		// The antlr parser generator fragment.
    		fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject {
    		//  options = {
    		//      backtrack = 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.ImportURIScopingFragment auto-inject {}
    		// fragment = exporting.SimpleNamesFragment auto-inject {}
    
    		// scoping and exporting API
    		fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
    		fragment = exporting.QualifiedNamesFragment auto-inject {}
    		fragment = builder.BuilderIntegrationFragment auto-inject {}
    
    		// generator API
    		fragment = generator.GeneratorFragment auto-inject {}
    
    		// formatter API
    		fragment = formatting.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 {}
    
    		// generates a more lightweight Antlr parser and lexer tailored for content assist
    		fragment = parser.antlr.XtextAntlrUiGeneratorFragment auto-inject {}
    
    		// generates junit test support classes into Generator#pathTestProject
    		fragment = junit.Junit4Fragment auto-inject {}
    
    		// project wizard (optional)
    		// fragment = projectWizard.SimpleProjectWizardFragment auto-inject {
    		//      generatorProjectName = "${projectName}"
    		// }
    
    		// 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 {}
    
    		// provides a preference page for template proposals
    		fragment = templates.CodetemplatesGeneratorFragment auto-inject {}
    
    		// provides a compare view
    		fragment = compare.CompareFragment auto-inject {}
    	}
    }
}

Re: Xcore -> Xtext [message #1083342 is a reply to message #1083329] Fri, 09 August 2013 16:52 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Christian, that did it! Very Happy

Here's where I went wrong:

As mentioned above, I had something like

Quote:

language = auto-inject {
uri = grammarURI
loadedResource = "platform:/resource/my.package/model/my.xcore"


This is what I needed:

Quote:

language = auto-inject {
loadedResource = "platform:/resource/org.eclipse.emf.ecore.xcore.lib/model/XcoreLang.xcore"
loadedResource = "platform:/resource/my.package/model/my.xcore"
uri = grammarURI


Two things are different:

1. I needed to load the XCoreLanguage explicitly, I guess it doesn't import transitively.
2. Putting the uri = grammar line first doesn't work. I'm not sure why that is, presumably there is some side-effect of that assignment..
Re: Xcore -> Xtext [message #1083346 is a reply to message #1083342] Fri, 09 August 2013 16:56 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

yes setting the uri is more than a property setting ...
it actually loads the grammar file.
Re: Xcore -> Xtext [message #1083349 is a reply to message #1083342] Fri, 09 August 2013 17:01 Go to previous messageGo to next message
Eclipse UserFriend
BTW, is there documentation anywhere about what the various options do? I noticed some interesting differences in Christian's workflow, like XtextAntlrGeneratorFragment classSplitting is commented out.

Other difference from what the XText project wizard does by default:

			fragment = ecore2xtext.FormatterFragment auto-inject {}
=>

			fragment = formatting.FormatterFragment auto-inject {}


Makes sense, though I'm not quite sure why this would effect formatting exactly..

			fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
			fragment = exporting.QualifiedNamesFragment auto-inject {}
=>
			fragment = scoping.ImportURIScopingFragment auto-inject {}
			fragment = exporting.SimpleNamesFragment auto-inject {}


But that's simply a difference in configuration choices.
Re: Xcore -> Xtext [message #1083549 is a reply to message #1083342] Sat, 10 August 2013 00:41 Go to previous message
Eclipse UserFriend
Miles,

Note that https://bugs.eclipse.org/bugs/show_bug.cgi?id=412429 is open
to consider this issue. I investigated it and while the Xcore stand
alone setup correctly configures the standalone resource set to support
this implicitly, that's not the resource set into which the grammar is
loaded, and hence the problem.


On 09/08/2013 10:52 PM, Miles Parker wrote:
> Thanks Christian, that did it! :d
>
> Here's where I went wrong:
>
> As mentioned above, I had something like
>
> Quote:
>> language = auto-inject {
>> uri = grammarURI loadedResource =
>> "platform:/resource/my.package/model/my.xcore"
>
>
> This is what I needed:
>
> Quote:
>> language = auto-inject {
>> loadedResource =
>> "platform:/resource/org.eclipse.emf.ecore.xcore.lib/model/XcoreLang.xcore"
>> loadedResource = "platform:/resource/my.package/model/my.xcore"
>> uri = grammarURI
>
>
> Two things are different:
>
> 1. I needed to load the XCoreLanguage explicitly, I guess it doesn't
> import transitively.
> 2. Putting the uri = grammar line first doesn't work. I'm not sure why
> that is, presumably there is some side-effect of that assignment..
>
Previous Topic:Error in referencing
Next Topic:SemanticSequencer generator: naming clash with ecore packages
Goto Forum:
  


Current Time: Mon Jul 14 16:16:13 EDT 2025

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

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

Back to the top