Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » entity cross references in domainmodel
entity cross references in domainmodel [message #756794] Tue, 15 November 2011 07:08 Go to next message
tiange zhang is currently offline tiange zhangFriend
Messages: 16
Registered: February 2011
Location: Shanghai, China
Junior Member
hi,

I modify the org.eclipse.xtext.examples.domainmodel grammar from:
 'entity' name=ValidID ('extends' superType=JvmParameterizedTypeReference)? '{' 


to:
'entity' name=ValidID ('extends' superType=[Entity])? '{'...


I also modify the related code of DomainmodelJvmModelInferrer.xtend form:
 if (e.superType != null)
	superTypes += e.superType.cloneWithProxies 

to:
	
if (e.superType != null)
   //superTypes += e.superType.jvmElements.filter(typeof(JvmType)).head.createTypeRef()
   superTypes += typeReferences.findDeclaredType(e.superType.fullyQualifiedName.toString,e).createTypeRef()


First reason of this modification is I want the supertype of entity must be another entity. Another reason is each entity will generate a java interface and an implementation.


The problem is, the entity must defined in the right sequence, otherwise will cause NullPointerException during source generation dur to typeReferences.findDeclaredType returns null.

following model is ok in editor, but cann't generate java source.
package a{
	entity A extends B{
		
	}
	entity B{
		
	}
}


I think the real problem is, if any generated java source will be referenced via TypeReferences.findDeclaredType or IJvmModelAssociations.getJvmElements(), success or not depends on the definition sequence.
For a large model, especially attribute/operation are introduced,it is difficult to arrange sequence of type definitions , so are there some way to fix this problem systematically? I noticed that there is a parameter named prelinkingPhase in IJvmModelInferrer.infer(...), is it for this problem?

Thanks.

Tiange Zhang
Re: entity cross references in domainmodel [message #757271 is a reply to message #756794] Thu, 17 November 2011 12:33 Go to previous message
tiange zhang is currently offline tiange zhangFriend
Messages: 16
Registered: February 2011
Location: Shanghai, China
Junior Member
I found a way to partially fix the problem. Add an infer method for root model element:

def dispatch infer(DomainModel domainModel, IAcceptor<JvmDeclaredType> acceptor, boolean prelinkingPhase){
	domainModel.eContents.forEach[ e|
		infer(e,acceptor,prelinkingPhase)
	]

	inferLinkedElements(domainModel)

	return
	}


infer(..) generate jvm types only, all other model elements which cross link to others are generated in inferLinkedElements(...)

It seems working well if all model elements are defined in one file. I am still trying to find a way to fix the errors when there are several model files.
Previous Topic:Add new file
Next Topic:[xtend2] import static inner Java classes
Goto Forum:
  


Current Time: Fri Apr 19 16:25:20 GMT 2024

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

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

Back to the top