Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Get All Objects of Type in Global Scope? Easy Way?
Get All Objects of Type in Global Scope? Easy Way? [message #1766375] Tue, 20 June 2017 17:44 Go to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
I'm dumb. I've now run into this problem the second time in 3 weeks.

I am trying to do something I think should be very simple and probably comes up on every Xtext project: I need to obtain a list of all Objects of a given type that are present in the global scope. The builder knows this. I don't.

I must be asking Google wrong, cause I can't find it.

I'm stuck here, where I can iterate through the global index, get ResourceDescriptions for every Object of a Type, but then I always get stuck in the same place where I can't resolve the damn proxy.

// Use the global scope provider. This ensures that we see the descriptions created by the prelinking phase of the Xtext builder.

// the designSandbox is an object that I'm currently validating in my DSL's validator

val rs = globalScopeProvider.getResourceDescriptions(designSandbox.eResource)
val sdIndex = rs.getExportedObjectsByType(bmxPackage.Literals.SUPPORT_DEF)   

// All the SuportDef objects are in other files other than the one containing the designSandbox - by definition
          
for (supportDefDesc : sdIndex) {
   var sd = supportDefDesc.EObjectOrProxy
   EcoreUtil2.resolve(sd, sd.eResource)


sd is _always_ a proxy. I can't figure out how to resolve it. In this case, the exported Object isn't in the current file I'm in, it's from some other imported file. That imported file (and the exported Object I have (which is always a proxy) makes reference to something in my current file). I do need to find out what external objects reference me.

Maybe there's a better way to check the cross references (EcoreUtil2 likely), but I am still coming back to the problem - which I will eventually need in my job - how do I get a list of all the Objects in my Global Scope and how do I get REAL resolved objects and not proxies?
Re: Get All Objects of Type in Global Scope? Easy Way? [message #1766376 is a reply to message #1766375] Tue, 20 June 2017 18:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
Use the resource you input into that code as context for resolving
So designResource



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Get All Objects of Type in Global Scope? Easy Way? [message #1766381 is a reply to message #1766376] Tue, 20 June 2017 20:01 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
Like this?

          for (supportDefDesc : sdIndex) {
          	var sd = supportDefDesc.EObjectOrProxy
          	EcoreUtil2.resolve(sd, designSandbox.eResource)
          	var sdResolved = sd as SupportDef 


This did not work. sdResolved is still a proxy.
Re: Get All Objects of Type in Global Scope? Easy Way? [message #1766382 is a reply to message #1766381] Tue, 20 June 2017 20:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
Do you have multiple projects

Use IContainer.Manager to obtain a container
Use IContainer.Manager to find the visible containers for that container

Ask each of the visible containers for exported objects

Then it should work


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Get All Objects of Type in Global Scope? Easy Way? [message #1766383 is a reply to message #1766382] Tue, 20 June 2017 20:11 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
Or you ask the global scope provider for its
Scope and the scope for its objects


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:Xtext 2.12 what emf version are used
Next Topic:How to get a SemanticSyntaxHighlighter to run
Goto Forum:
  


Current Time: Tue Oct 08 11:59:14 GMT 2024

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

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

Back to the top