Bug 494465 - LiveShadowedResourceDescriptions bogus behaviour
Summary: LiveShadowedResourceDescriptions bogus behaviour
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.10.0   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 494444 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-05-24 13:03 EDT by Christian Dietrich CLA
Modified: 2016-06-01 01:59 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Dietrich CLA 2016-05-24 13:03:09 EDT
LiveShadowedResourceDescriptions behaves bogus if you call org.eclipse.xtext.resource.impl.LiveShadowedResourceDescriptions.getAllResourceDescriptions()

without un-lazy-ing the collection e.g. inside a forloop
and resolve the stuff into the resourceset

e.g.

val index = resourceDescriptionsProvider.getResourceDescriptions(context.eResource)
val resourceDescription = index.getResourceDescription(context.eResource.URI)
val containers = manager.getVisibleContainers(resourceDescription, index) ?: emptyList

for (container : containers) {
	val greetings = container.getExportedObjectsByType(MyDslPackage.Literals.GREETING)
	for (greeting : greetings) {
		val result = EcoreUtil2.resolve(greeting.getEObjectOrProxy, context) as Greeting
		println(result.name + " visited")
	}
}

through the filtering !isExistingOrRenamedResourceURI(input.getURI());
all resource descriptions but the first are removed by the lazy collection

=> you have to do something like

for (greeting : greetings.toList)
Comment 1 Christian Dietrich CLA 2016-05-24 13:13:20 EDT
@Sven @Moritz what do you think?
is there a point where could "freeze" the resources map of the resourceset?
Comment 2 Sven Efftinge CLA 2016-05-24 13:41:12 EDT
We cannot 'freeze' it as that changes the behavior and breaks users. 
I would simply not use LiveShadowedResourceDescriptions. 
I think we should deprecate and eventually delete it.
Comment 3 Moritz Eysholdt CLA 2016-05-24 13:48:01 EDT
The LiveShadowedResourceDescriptions is needed by users that programmatically modify their EMF model and later serialize it using Xtext, e.g. graphical editors with Xtext-persistence.

The LiveShadowedResourceDescriptions is needed to make sure cross references are serialized with the names from the model. Other implementation only use names from persisted files and/or Xtext's dirty state. 

So I oppose deprecating LiveShadowedResourceDescriptions unless we have a better solution for the use case.
Comment 4 Christian Dietrich CLA 2016-05-24 13:48:50 EDT
yes we use LiveShadowedResourceDescriptions
to be able to serialize multiple models referring each other from eclipse without turning off scope validation inside CrossRefSerializer. this way was proposed by Moritz here as well: https://www.eclipse.org/forums/index.php/m/1732573/?srch=LiveScopeResourceSetInitializer#msg_1732573
Comment 5 Jan Koehnlein CLA 2016-05-25 03:03:44 EDT
(In reply to Sven Efftinge from comment #2)
> We cannot 'freeze' it as that changes the behavior and breaks users. 
> I would simply not use LiveShadowedResourceDescriptions. 
> I think we should deprecate and eventually delete it.

I object. LSRD has been initially created for rename refactoring and it is definitively needed there.
Comment 6 Christian Dietrich CLA 2016-06-01 01:59:21 EDT
*** Bug 494444 has been marked as a duplicate of this bug. ***