Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Resolver/ResourceSet behavior doubts
Resolver/ResourceSet behavior doubts [message #1763592] Wed, 17 May 2017 13:08 Go to next message
Eclipse UserFriend
Hi,

Would you please look at the project and example grammar usage provided at: https://www.eclipse.org/forums/index.php?t=msg&th=1086007&goto=1763590&#msg_1763590

In case "Hello CCC!" is used in the example project, MyDslGenerator outputs all 'people' of the model in 'greetings1.txt'. In case "Hello CCC!" is commented out, only 'people' from the main resource appear.

It looks like an inconsistent behavior during creation of the ResourceSet.

Would you please tell whether it is an issue or something is missing in my implementation?

Thank you,
Serge
Re: Resolver/ResourceSet behavior doubts [message #1763595 is a reply to message #1763592] Wed, 17 May 2017 13:23 Go to previous messageGo to next message
Eclipse UserFriend
no the problem is the one mentioned before:

var resourceSet = resource.resourceSet
var resources = resourceSet.resources

there is no guarantee that all resources are loaded to the resourceset.
actually only the changed ones and the involved ones.
this is why this approach does not work.

you would have to query the xtext index for all greetings and use this information to load all resources needed.
class MyDslGenerator extends AbstractGenerator {

	@Inject
	IResourceDescriptionsProvider rdp;

	@Inject
	IContainer.Manager cmgr

	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
		val rds = rdp.getResourceDescriptions(resource.resourceSet)
		val rd = rds.getResourceDescription(resource.URI)
		val greetings = <Greeting>newArrayList
		for (c : cmgr.getVisibleContainers(rd, rds)) {
			for (d : c.getExportedObjectsByType(MyDslPackage.Literals.GREETING)) {
				var g = d.EObjectOrProxy as Greeting
				if (g.eIsProxy) {
					g = EcoreUtil.resolve(g, resource.resourceSet) as Greeting
					greetings.add(g);
				}
			}
		}
		
		fsa.generateFile("xxxxxx.txt", '''
			«FOR g : greetings»
				«g.name»
			«ENDFOR»
		''')
	}
}





Re: Resolver/ResourceSet behavior doubts [message #1763606 is a reply to message #1763595] Wed, 17 May 2017 14:11 Go to previous messageGo to next message
Eclipse UserFriend
Thank you Christian!

But, don't you think that there is still an inconsistency? In both cases entities from 'included' resources are not used. But, referencing a local entity leads to filling ResourcSet, while lacking of such reference doesn't.
Re: Resolver/ResourceSet behavior doubts [message #1763607 is a reply to message #1763606] Wed, 17 May 2017 14:16 Go to previous messageGo to next message
Eclipse UserFriend
i dont get that

test contains only one file.
Re: Resolver/ResourceSet behavior doubts [message #1763608 is a reply to message #1763607] Wed, 17 May 2017 14:18 Go to previous messageGo to next message
Eclipse UserFriend
and make sure you dont misc:

- clean build (all files)
- incremental build (editing one file)
Re: Resolver/ResourceSet behavior doubts [message #1763701 is a reply to message #1763607] Thu, 18 May 2017 14:11 Go to previous messageGo to next message
Eclipse UserFriend
Christian Dietrich wrote on Wed, 17 May 2017 18:16
i dont get that

test contains only one file.


Hi Christian,

There is one file in the test project. But, probably you didn't mentioned them, there are two more files in plugin resources: org.xtext.example.mydsl\headers\

Whether entities from those files included to ResourceSet or not, depends on usage of local entity. That is why it looks like an inconsistency.
The visible entities are outputted in 'greetings1.txt' file and commenting out reference to the local entity leads to different behavior.
Re: Resolver/ResourceSet behavior doubts [message #1763705 is a reply to message #1763701] Thu, 18 May 2017 14:54 Go to previous message
Eclipse UserFriend
well thats the mess you do at

MyDslImportUriResolver

if resolve is never called, stuff will never be loaded.

if you have no references (in your case these Hello xxxx! thingys then resolve will never be called.
and thus no resolve ....

Previous Topic:non-grammar features in a model object
Next Topic:Targeting both eclipse and LSP
Goto Forum:
  


Current Time: Fri Apr 18 16:21:02 EDT 2025

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

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

Back to the top