Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammer for UML-Association
Grammer for UML-Association [message #1143897] Fri, 18 October 2013 13:55 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hello everyone!
I'm trying to write a grammer for UML-Classdiagrams by importing the UML2 metamodel and writing the necessary xtext-grammer.

Everything runs well (for example the parsing rules for: Classes, Enums, Properties, Datatypes, Inheritage etc..) except associations. Here is a snippet of my Grammer which describes this:
Association_Impl returns Association:
	{Association}
	(isAbstract?='isAbstract')?
	'assoc' name=ID ('specializes' generalization+=Generalization_Impl)?	
	'{' 
	//The properties of an association are the association ends whose values are
	// the instances being related by a specific  instance of the association. 
	//Two properties (asso ends) are prescribed, one is optional	 
	 	 
	  (ownedEnd+=Property_Association_Impl)*  
  	  		   
	 //member-end min 2x	 
	  'role_1:' memberEnd+=[Property|QualifiedName] ';'
	  'role_2:' memberEnd+=[Property|QualifiedName] ';' 
	   ('further_roles: '(memberEnd+=[Property|QualifiedName] ';')*  )?  		
	'}'	
	;


I think the problem is this feature of an association:
(ownedEnd+=Property_Association_Impl)* .
It is not possible to create these properties (they are not visible in the outline-view). The uml-metamodel expects that all necessary references of these properties are already set!

My question is now: Is it possible to instantiate some model-elements programmatically by default??

I thought about something like:

  • user writes an association
  • xtext creates an association-instance with two ownedEnd-Properties

Maybe someone has an idea?

Thanks alot,
Alex

Re: Grammer for UML-Association [message #1159289 is a reply to message #1143897] Mon, 28 October 2013 12:30 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,

the specified grammar for UML-Associations of the first post leads to the following exceptions while editing the xtext file:

!STACK 0
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=1, size=0
	at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:346)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:478)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.next(EContentsEList.java:559)
	at org.eclipse.emf.common.util.AbstractTreeIterator.next(AbstractTreeIterator.java:133)
	at org.eclipse.xtext.linking.impl.AbstractCleaningLinker.clearAllReferences(AbstractCleaningLinker.java:75)
	at org.eclipse.xtext.linking.impl.AbstractCleaningLinker.beforeModelLinked(AbstractCleaningLinker.java:65)
	at org.eclipse.xtext.linking.impl.AbstractCleaningLinker.linkModel(AbstractCleaningLinker.java:37)
	at org.eclipse.xtext.resource.XtextResource.doLinking(XtextResource.java:282)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doLinking(LazyLinkingResource.java:88)
	at org.eclipse.xtext.resource.XtextResource.updateInternalState(XtextResource.java:250)
	at org.eclipse.xtext.resource.XtextResource.updateInternalState(XtextResource.java:240)
	at org.eclipse.xtext.resource.XtextResource.doLoad(XtextResource.java:163)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doLoad(LazyLinkingResource.java:81)
	at org.eclipse.xtext.resource.XtextResource.reparse(XtextResource.java:186)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.modify(XtextDocument.java:207)
	at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.process(AbstractReadWriteAcces.java:111)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler$DocumentListener.performNecessaryUpdates(XtextReconciler.java:95)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.updateContentBeforeRead(XtextDocument.java:147)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.beforeReadOnly(XtextDocument.java:168)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.beforeReadOnly(XtextDocument.java:1)
	at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.readOnly(AbstractReadWriteAcces.java:61)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.readOnly(XtextDocument.java:228)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:79)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob.createIssues(ValidationJob.java:75)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob.run(ValidationJob.java:64)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)



The problem is that it is not possible to create new property-instances within the association-block. These new created properties should be added to the association.

Here is a screenshot of the problem that while editing the
https://dl.dropboxusercontent.com/u/18688378/xtext/problems/associationError..png

Is it maybe possible to create all the necessary properties of an association programmatically when the user adds a new association block in the xtext file?

Thanks for any suggestion,
Alex
Re: Grammer for UML-Association [message #1160964 is a reply to message #1159289] Tue, 29 October 2013 13:35 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hello everyone!
I will try a workaround for solving the problem. I want to implement a QuickFix, that creates to properties in the xtext-model and assign them to the containing association.
But I'm not sure if this is a "clean" way to solve this problem.

Please critique me if I'm going in the wrong direction!

Regards,
Alex
Re: Grammer for UML-Association [message #1161022 is a reply to message #1160964] Tue, 29 October 2013 14:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13488
Registered: July 2009
Senior Member
Hi,

sorry i am too poor with UML Metamodel to give any advice.

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Grammer for UML-Association [message #1161051 is a reply to message #1161022] Tue, 29 October 2013 14:46 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hmm ok.
But maybe you may give me a hint how I can solve the following problem.
I implemented a quickfix. So if a user writes an association statement an error (with an quickfix) appears on the association name. But when I run the quickfix
I get these exceptions:

Caused by: org.eclipse.xtext.validation.IConcreteSyntaxValidator$InvalidConcreteSyntaxException: These errors need to be fixed before the model can be serialized.
Model.packagedElement[0]->Package'de'.packagedElement[2]->Association'a': The feature Association.memberEnd contains non-transient values but has no corresponding assignment in rule PackageableElement.
Model.packagedElement[0]->Package'de'.packagedElement[2]->Association'a'.ownedEnd[0]->Property'memeberEnd_1': The feature TypedElement(Property).type contains non-transient values but has no corresponding assignment in rule Property_Association_Impl.
Model.packagedElement[0]->Package'de'.packagedElement[2]->Association'a'.ownedEnd[0]->Property'memeberEnd_1': The feature Property.association contains non-transient values but has no corresponding assignment in rule Property_Association_Impl.
Model.packagedElement[0]->Package'de'.packagedElement[2]->Association'a'.ownedEnd[0]->Property'memeberEnd_1': The feature Property.association contains non-transient values but has no corresponding assignment in rule Property_Impl.
Model.packagedElement[0]->Package'de'.packagedElement[2]->Association'a'.ownedEnd[1]->Property'memeberEnd_2': The feature TypedElement(Property).type contains non-transient values but has no corresponding assignment in rule Property_Association_Impl.
Model.packagedElement[0]->Package'de'.packagedElement[2]->Association'a'.ownedEnd[1]->Property'memeberEnd_2': The feature Property.association contains non-transient values but has no corresponding assignment in rule Property_Association_Impl.
Model.packagedElement[0]->Package'de'.packagedElement[2]->Association'a'.ownedEnd[1]->Property'memeberEnd_2': The feature Property.association contains non-transient values but has no corresponding assignment in rule Property_Impl.


I really don't understand what is meant by: non-transient values. I find the necessary container (association) and put in two properties programmatically.

Here a snippet of the quickfix:
override apply(EObject element, IModificationContext context) throws Exception {
		//adding some properties for the association
		if (element instanceof Association){
			val asso = element as Association
			val prop1 = UMLFactory.eINSTANCE.createProperty()
			prop1.name  = "memeberEnd_1"
                        //simple acces to a class, in the xtext-file a class is created at the first place
			prop1.type = asso.nearestPackage.ownedTypes.get(0)
			
			println(prop1.type.name)
			
			val prop2 = UMLFactory.eINSTANCE.createProperty()
			prop2.name = "memeberEnd_2"
			prop2.type = asso.nearestPackage.ownedTypes.get(0)
			
			println(prop2.type.name)
			
			asso.getOwnedEnds.add(prop1)
			asso.getOwnedEnds.add(prop2)		
			 
		}


Or is it maybe even better to disable the standard validation (against the UML-Metamodel constraints) of the xtext-model? Is this even possible?

Thanks,
Alex
Re: Grammer for UML-Association [message #1161174 is a reply to message #1161051] Tue, 29 October 2013 16:30 Go to previous message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hello,

I fixed now the incomming exceptions by adding the necessary features to my DSL-rules. So the programmatically creation of these properties runs and the textual syntax is also generated
in the xtexteditor. But now I get the following exception from xtext:

1    [Worker-3] ERROR org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy  - Parsing in reconciler failed.
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=1, size=0
	at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:346)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:478)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.next(EContentsEList.java:559)
	at org.eclipse.emf.common.util.AbstractTreeIterator.next(AbstractTreeIterator.java:133)
	at org.eclipse.xtext.linking.impl.AbstractCleaningLinker.clearAllReferences(AbstractCleaningLinker.java:75)
	at org.eclipse.xtext.linking.impl.AbstractCleaningLinker.beforeModelLinked(AbstractCleaningLinker.java:65)
	at org.eclipse.xtext.linking.impl.AbstractCleaningLinker.linkModel(AbstractCleaningLinker.java:37)
	at org.eclipse.xtext.resource.XtextResource.doLinking(XtextResource.java:282)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doLinking(LazyLinkingResource.java:88)
	at org.eclipse.xtext.resource.XtextResource.updateInternalState(XtextResource.java:250)
	at org.eclipse.xtext.resource.XtextResource.updateInternalState(XtextResource.java:240)
	at org.eclipse.xtext.resource.XtextResource.update(XtextResource.java:221)
	at org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy.doReconcile(XtextDocumentReconcileStrategy.java:125)
	at org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy.reconcile(XtextDocumentReconcileStrategy.java:55)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler.doRun(XtextReconciler.java:329)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler.access$3(XtextReconciler.java:316)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler$1.process(XtextReconciler.java:273)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler$1.process(XtextReconciler.java:1)
	at org.eclipse.xtext.util.concurrent.IUnitOfWork$Void.exec(IUnitOfWork.java:36)
	at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.modify(AbstractReadWriteAcces.java:81)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.modify(XtextDocument.java:201)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.internalModify(XtextDocument.java:98)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler.run(XtextReconciler.java:270)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)



Does someone has any idea what is the problem here?

Alex
Previous Topic:OutOfMemoryError at org.eclipse.xtext.ui.editor.syntaxcoloring
Next Topic:EnumLiteralDeclaration: problem getting the values of the reference
Goto Forum:
  


Current Time: Mon Jul 06 18:34:52 GMT 2020

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

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

Back to the top