Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using getReferenceDescriptions (getReferenceDescriptions returns stale references after delete.)
Using getReferenceDescriptions [message #1698662] Wed, 17 June 2015 06:42 Go to next message
Andrew Clark is currently offline Andrew ClarkFriend
Messages: 23
Registered: June 2010
Junior Member
I have 2 grammars where models from one grammar reference objects from models of the other.

There is a simple validator to warn if a object is not referenced.

	@Inject
	private IResourceDescriptions resourceDescriptions;

	@Check
	def checkIsRefenced(Greeting greeting) {
		if (greeting.findAllReferences.size == 0) {
			warning('No references to greeting', 
					MyDsl1Package.Literals.GREETING__NAME)
		}
	}

	def private findAllReferences(EObject eo) {

		val targetUri = EcoreUtil.getURI(eo);
		val referenceDescriptions = resourceDescriptions.allResourceDescriptions.map[referenceDescriptions].flatten
		
		val referenceURIs = referenceDescriptions.filter[it.targetEObjectUri.equals(targetUri)]

		return referenceURIs
	}



If I delete an item in the editor showing the warning , then the warning 'moves' to the next item - I understand this as position is not updated in the URI . However, on save it stays there, if I then make a dummy change in the file and save again the warning correctly disappears.

How do I ensure the references are updated before the validation runs?
Note that the getAllResourceDescriptions is returning DirtyStateAwareResourceDescriptions which I thought would handle this case.

I have also tried using IReferenceFinder.findAllReferences , this exhibits the same behavior.

I am using

Xtext
Version: 2.8.2.v201504100559
Build id: R201504100559

I have attached a simple example .
Re: Using getReferenceDescriptions [message #1698673 is a reply to message #1698662] Wed, 17 June 2015 08:16 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Andrew,

it's not possible to rely on reference descriptions in the validator
since they are not fully available there.
Also IReferenceDescriptions cannot be injected directly but should be
obtained from the ResourceDescriptionsProvider.

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: Using getReferenceDescriptions [message #1698684 is a reply to message #1698673] Wed, 17 June 2015 09:10 Go to previous messageGo to next message
Andrew Clark is currently offline Andrew ClarkFriend
Messages: 23
Registered: June 2010
Junior Member
Hi Sebastian,

Does this simply mean that this kind of check is simply impossible ? We have a project that has grown over time and now has many unused model 'definitions'. Whats worse is that these definitions generate code so we are generating unused code!

I implemented this validation and the maintainers of the models were very happy Smile , in fact they have now asked for more similar 'not referenced' validations. I then noticed the 'refresh' problem. It would be a shame if I have to go back to the maintainers and tell them the validation is not reliable Sad .

FindReferences has to handle this, I guess this is then done in the UI .

Do you have any suggestions on how I should provide this functionality ?

Quote:
Also IReferenceDescriptions cannot be injected directly but should be
obtained from the ResourceDescriptionsProvider.


I do not inject IReferenceDescriptions , I guess you mean IResourceDescriptions.

I originally used the ResourceDescriptionsProvider , I only switched to injecting IResourceDescriptions directly to see if it would help, is was a shot in the dark Wink . It did then provide an instance of DirtyStateAwareResourceDescriptions which surprised me.

cheers,

Andrew
Re: Using getReferenceDescriptions [message #1698690 is a reply to message #1698684] Wed, 17 June 2015 09:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

you would write an Action on a file or a Project that does the Analysis on a built index.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using getReferenceDescriptions [message #1698691 is a reply to message #1698684] Wed, 17 June 2015 09:42 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Andrew,

it is certainly possible to perform such validation, but during the
build it is not feasible. There you'd have to use a builder participant
that creates the markers.

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: Using getReferenceDescriptions [message #1698741 is a reply to message #1698690] Wed, 17 June 2015 14:38 Go to previous messageGo to next message
Andrew Clark is currently offline Andrew ClarkFriend
Messages: 23
Registered: June 2010
Junior Member
Hi Christian,

Quote:
you would write an Action on a file or a Project that does the Analysis on a built index.


How is this different from simply making the validations EXPENSIVE ?

cheers,

Andrew
Re: Using getReferenceDescriptions [message #1698759 is a reply to message #1698741] Wed, 17 June 2015 16:05 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
you have a separate button

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:ID being anything except Newlines creating problems
Next Topic:Class access and injection
Goto Forum:
  


Current Time: Tue Mar 19 07:11:37 GMT 2024

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

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

Back to the top