Skip to main content



      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 13:44 Go to next message
Eclipse UserFriend
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 14:00 Go to previous messageGo to next message
Eclipse UserFriend
Use the resource you input into that code as context for resolving
So designResource

Re: Get All Objects of Type in Global Scope? Easy Way? [message #1766381 is a reply to message #1766376] Tue, 20 June 2017 16:01 Go to previous messageGo to next message
Eclipse UserFriend
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 16:07 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Get All Objects of Type in Global Scope? Easy Way? [message #1766383 is a reply to message #1766382] Tue, 20 June 2017 16:11 Go to previous message
Eclipse UserFriend
Or you ask the global scope provider for its
Scope and the scope for its objects
Previous Topic:Xtext 2.12 what emf version are used
Next Topic:How to get a SemanticSyntaxHighlighter to run
Goto Forum:
  


Current Time: Tue May 13 11:25:23 EDT 2025

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

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

Back to the top