Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Can't get All sub-entities defined in different files(Xtext2.1.1)(Can't get All sub-entities defined in different files (Xtext2.1.1))
Can't get All sub-entities defined in different files(Xtext2.1.1) [message #759180] Sun, 27 November 2011 12:56 Go to next message
tiange zhang is currently offline tiange zhangFriend
Messages: 16
Registered: February 2011
Location: Shanghai, China
Junior Member
Grammar:
Entity:
	'entity' name=ValidID ('extends' superType=[Entity])? '{'
		features+=Feature*
	'}';


I want to retrieve all sub-entities for a specific entity using following xtend functions
	def superEntities(Entity e){
		var ArrayList<Entity> superEntities = newArrayList()
		var curEntity = e.superType
		while(curEntity!=null){
			superEntities += curEntity
			curEntity = curEntity.superType	
		}
		superEntities
	}

	def subEntities(Entity e){
		var entities = Iterators::filter(e.eResource.resourceSet.allContents,typeof(Entity))
		entities = Iterators::filter(entities)[entity|
			entity.superEntities.contains(e)
		]
		newArrayList(Iterators::toArray(entities,typeof(Entity)))	
	}



Define the following two models in different files:
p1.dmodel:
package p1{
	entity A {
	}
	entity B extends A{
	}
}


p2.dmodel:
package p2{
	
	import p1.*
	entity C extends A{
	}
}


If p2.dmodel is not opened in an editor, function subEntities only returns B as A's sub entity, C is missing.


How to implement subEntities(Entity e) correctly?

Thanks.

Tiange zhang


Re: Can't get All sub-entities defined in different files(Xtext2.1.1) [message #759182 is a reply to message #759180] Sun, 27 November 2011 13:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13754
Registered: July 2009
Senior Member
Hi,

from "where" do you call this code?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can't get All sub-entities defined in different files(Xtext2.1.1) [message #759186 is a reply to message #759182] Sun, 27 November 2011 13:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13754
Registered: July 2009
Senior Member
P.S: if you call it from a builder or an action/handler or something in the ide

you have basically two options

(1) fill/use a completed resourceset as described here http://kthoms.wordpress.com/2011/07/12/xtend-generating-from-multiple-input-models/
(2) use the "index" to find all references

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can't get All sub-entities defined in different files(Xtext2.1.1) [message #759188 is a reply to message #759182] Sun, 27 November 2011 13:43 Go to previous messageGo to next message
tiange zhang is currently offline tiange zhangFriend
Messages: 16
Registered: February 2011
Location: Shanghai, China
Junior Member
from DomainmodelJvmModelInferrer, used to generate documentation in super class:
def dispatch infer(Entity e, IAcceptor<JvmDeclaredType> acceptor, boolean prelinkingPhase) {
  acceptor.accept(
    e.toClass( e.fullyQualifiedName ) [
	documentation = '''«FOR subEntity : e.subEntities SEPARATOR ','»«subEntity.name»«ENDFOR»'''.toString

......


thanks

Tiange Zhang
Re: Can't get All sub-entities defined in different files(Xtext2.1.1) [message #759191 is a reply to message #759188] Sun, 27 November 2011 13:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13754
Registered: July 2009
Senior Member
Hmmm, hard to do such a thing in a performant manner. i'd feed the docs for the entities to the index
and query the index in the inferrer.

(1) use a custom DefaultResourceDescriptionStrategy
(2) search the index for all matching reference descriptions

this is not trivial and might be a lot of work to do
you might have a look at DefaultReferenceFinder
but this one is a bit UIish

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can't get All sub-entities defined in different files(Xtext2.1.1) [message #759194 is a reply to message #759191] Sun, 27 November 2011 14:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13754
Registered: July 2009
Senior Member
P.s: in your case you wont need (1) since you only need the name of the referencing subentities and i dont know if it is a good idea to use the index in the inferrer - this might be a too early point

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 27 November 2011 16:22]

Report message to a moderator

Re: Can't get All sub-entities defined in different files(Xtext2.1.1) [message #759195 is a reply to message #759194] Sun, 27 November 2011 14:53 Go to previous message
tiange zhang is currently offline tiange zhangFriend
Messages: 16
Registered: February 2011
Location: Shanghai, China
Junior Member
Thanks for your quick and detail response. I will follow your advice and try to reading Xtext source(It seems really hard...)
Previous Topic:Android 4.0
Next Topic:Duplicate JvmAnnotationTarget '&lt;unnamed&gt;' when using a AbstractModelInferrer
Goto Forum:
  


Current Time: Mon Mar 01 07:37:26 GMT 2021

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

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

Back to the top