Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Issue with multiple grammars for same Ecore model
Issue with multiple grammars for same Ecore model [message #1228857] Wed, 08 January 2014 08:17 Go to next message
Nieves Salor is currently offline Nieves SalorFriend
Messages: 19
Registered: September 2013
Junior Member
Hi,
I developed a Xtext project creating a textual grammar (model1) with cross-references to another Ecore model (non-Xtext one, model2). This is working fine.
However, now I need to create another grammar editor for the first model (model1), thus also containing the same cross-references to model2. For this, I use the import mechanism instead of the generate one when I am writing the grammar (the same one the wizard provides). But, it returns me a compilation error for each of the elements of model2 in the form:
Cannot find compatible feature ..." error for references to Ecore classes requesting the same type of the feature.

I have read in some posts that could be due to the cardinality, but I put exactly the same constructs as the original grammar and it keeps failing. Also I have tried the import with the namespace uri and with the complete form (resource/...) but it does not solve anything.

At the end, I removed the import mechanism and use generate to create a model3. With this it works and both models (model1 and model3) are exactly the same. Nevertheless this solution is not maintainable..so someone can shed some light into what may be the issue??

Thanks in advance
Re: Issue with multiple grammars for same Ecore model [message #1228915 is a reply to message #1228857] Wed, 08 January 2014 10:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
How do your grammars and workflows Look like?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Issue with multiple grammars for same Ecore model [message #1228932 is a reply to message #1228915] Wed, 08 January 2014 11:20 Go to previous messageGo to next message
Nieves Salor is currently offline Nieves SalorFriend
Messages: 19
Registered: September 2013
Junior Member
My first (original) grammar headers are

grammar Pluto hidden(WS, ML_COMMENT, SL_COMMENT)//with org.eclipse.xtext.common.Terminals

generate pluto "http://example/compiler/Pluto"
import "platform:/resource/SSMModel/model/ssm.ecore" as ssm
import "http://www.eclipse.org/emf/2002/Ecore" as ecore


where the ssm is the non-Xtext project but I have created the xtext.ui and xtext plugings associated.

And the original workflow
var grammarURI = "classpath:/example/compiler/Pluto.xtext"
var fileExtensions = "pluto"
var projectName = "parserCompiler"
var runtimeProject = "../${projectName}"
var generateXtendStub = true
var encoding = "UTF-8"

Workflow {
    bean = StandaloneSetup {
    	scanClassPath = true
    	platformUri = "${runtimeProject}/.."
    	uriMap = {
            from = "platform:/plugin/SSMModel/model/ssm.ecore"
            to = "platform:/resource/SSMModel/model/ssm.ecore"
        }
        uriMap = {
            from = "platform:/plugin/SSMModel/model/ssm_schema.genmodel"
            to = "platform:/resource/SSMModel/model/ssm_schema.genmodel"
        }
    	registerGeneratedEPackage = "example.ssm.model.ssm.ssmPackage"
		registerGenModelFile = "platform:/resource/SSMModel/model/ssm_schema.genmodel"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}/src-gen"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}/model"
    }
    
    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"
    	encoding = encoding
    	language = auto-inject {
    		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.EMFGeneratorFragment 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 = "example.compiler.validation.PlutoValidator"
    		//    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 {}
    	}
    }
}


And the second grammar headers
grammar PlutoL hidden(WS, ML_COMMENT, SL_COMMENT)

import "http://example/PlutoL"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "ase5_SSM" as ssm


and the workflow
var grammarURI = "classpath:example/PlutoL.xtext"
var fileExtensions = "plutoL"
var projectName = "plutoCompiler"
var runtimeProject = "../${projectName}"
var generateXtendStub = true
var encoding = "UTF-8"

Workflow {
	bean = StandaloneSetup {
		scanClassPath  = true
		platformUri = "${runtimeProject}/.."
		uriMap = {
            from = "platform:/plugin/SSMModel/model/ssm.ecore"
            to = "platform:/resource/SSMModel/model/ssm.ecore"
        }
        uriMap = {
            from = "platform:/plugin/SSMModel/model/ssm_schema.genmodel"
            to = "platform:/resource/SSMModel/model/ssm_schema.genmodel"
        }
    	registerGeneratedEPackage = "example.ssm.model.ssm.ssmPackage"
		registerGenModelFile = "platform:/resource/SSMModel/model/ssm_schema.genmodel"
		
			}

	  component = DirectoryCleaner {
    	directory = "${runtimeProject}/src-gen"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}/model"
    }
    
    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"
    	encoding = encoding
    	language = auto-inject {
    		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.EMFGeneratorFragment 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 = "example.compiler.validation.PlutoValidator"
    		//    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 {}
    	}
	}
}


and I get errors of type
Cannot find compatible feature activity in sealed EClass ActivityCall from imported package http://example/compiler/PlutoL: The existing reference 'activity' has an incompatible type 'Activity'. The expected type is 'Activity'.	PlutoL.xtext

Thanks
Re: Issue with multiple grammars for same Ecore model [message #1228935 is a reply to message #1228932] Wed, 08 January 2014 11:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hmmm

- does this message come from editor or when running the workflow?
- why does the second workflow contain a fragment = ecore.EMFGeneratorFragment auto-inject {}
- from which ecore do ActivityCall and Activity come from? (from pluto???)
- how does the use look like in the grammar
- why is there no register thing for pluto in the second workflow?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 08 January 2014 11:43]

Report message to a moderator

Re: Issue with multiple grammars for same Ecore model [message #1228946 is a reply to message #1228935] Wed, 08 January 2014 11:50 Go to previous messageGo to next message
Nieves Salor is currently offline Nieves SalorFriend
Messages: 19
Registered: September 2013
Junior Member
Quote:
- does this message come from editor or when running the workflow?

If I use
import "ase5_SSM" as ssm  
then in the eclipse compiler and if I use the import as
import "platform:/resource/SSMModel/model/ssm.ecore" as ssm 
when I run the workflow.

Quote:
- why does the second workflow contain a fragment = ecore.EMFGeneratorFragment auto-inject {}

Sorry I have not removed this as now I have it instead with the import with the generate to make it work.

Quote:
- from which ecore do ActivityCall and Activity come from? (from pluto???)

ActivityCall comes from the ecore of the originalGrammar(pluto) and Activity from the ssm one (the non-xtext one)

Quote:
- how does the use look like in the grammar

I attach both grammars

Quote:
- why is there so register thing for pluto in the second workflow?

Same answer as the second question
  • Attachment: Pluto.xtext
    (Size: 13.44KB, Downloaded 116 times)
  • Attachment: PlutoL.xtext
    (Size: 15.41KB, Downloaded 108 times)
Re: Issue with multiple grammars for same Ecore model [message #1228949 is a reply to message #1228946] Wed, 08 January 2014 11:56 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the grammars look fine.

so the problem might actually be how you do the register thing in the workflow and/or the header of the model.
so please make sure you add a registergeneratedepackage for all packages.
then it should work to import packages by ns uri in both grammars.

more is hard to say without beeing able to actually debug.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:order of variables
Next Topic:Adding a library to runtime project
Goto Forum:
  


Current Time: Thu Apr 18 01:05:56 GMT 2024

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

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

Back to the top