Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resolver/ResourceSet behavior doubts
Resolver/ResourceSet behavior doubts [message #1763592] Wed, 17 May 2017 17:08 Go to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
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 17:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
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»
		''')
	}
}







Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Resolver/ResourceSet behavior doubts [message #1763606 is a reply to message #1763595] Wed, 17 May 2017 18:11 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
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 18:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
i dont get that

test contains only one file.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Resolver/ResourceSet behavior doubts [message #1763608 is a reply to message #1763607] Wed, 17 May 2017 18:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
and make sure you dont misc:

- clean build (all files)
- incremental build (editing one file)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Resolver/ResourceSet behavior doubts [message #1763701 is a reply to message #1763607] Thu, 18 May 2017 18:11 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
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 18:54 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
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 ....



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:non-grammar features in a model object
Next Topic:Targeting both eclipse and LSP
Goto Forum:
  


Current Time: Thu Dec 12 08:55:00 GMT 2024

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

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

Back to the top