Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to validate broken crosslinks
How to validate broken crosslinks [message #755135] Mon, 07 November 2011 13:44 Go to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Hi,

I'm generating code using a Context Menu, as showed here: http://christiandietrich.wordpress.com/2011/10/15/xtext-calling-the-generator-from-a-context-menu/

The problem I am having now is that I need to validate the resource before calling the generator. Using

Resource r = rs.getResource(uri, true);
		
EList<Diagnostic> errors = r.getErrors();


only gets syntax errors. It never says when the object has broken crosslinks, so my generator fails.

I read here http://www.eclipse.org/Xtext/documentation/2_1_0/060-validation.php that "If you want to validate whether all links are valid, you will have to navigate through the model so that all installed EMF proxies get resolved."

What do they mean with navigate my model and how can be done? is there another way (for example, just not enable de "Generate" button when the resource has errors)?

Thanks!




Re: How to validate broken crosslinks [message #755146 is a reply to message #755135] Mon, 07 November 2011 14:13 Go to previous messageGo to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
I did this and it works, but I'm not sure if it is the right way to do it.

                EList<Diagnostic> errors = r.getErrors();
		TreeIterator<EObject> it = r.getAllContents();
		while(it.hasNext()) {
			Diagnostician.INSTANCE.validate(it.next());
			if(errors.size() > 0)
				break;			
		}

[Updated on: Mon, 07 November 2011 14:14]

Report message to a moderator

Re: How to validate broken crosslinks [message #755167 is a reply to message #755146] Mon, 07 November 2011 15:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

why do you want to validate at all. you are in the editor. so simply ask the resource for its errors.

Resource r = rs.getResource(uri, true);
EcoreUtil.resolveAll(r);
for (org.eclipse.emf.ecore.resource.Resource.Diagnostic d : r.getErrors()) {
System.out.println(d.getMessage());
}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to validate broken crosslinks [message #755382 is a reply to message #755167] Tue, 08 November 2011 10:29 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
@Christian: I think that'll still get you only the syntactic and linking errors, not those coming from (custom) validation. However, you can use the Diagnostician as in http://www.eclipse.org/Xtext/documentation/2_1_0/060-validation.php#validation_4

Re: How to validate broken crosslinks [message #755497 is a reply to message #755146] Tue, 08 November 2011 16:32 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Lucy,

please use the IResourceValidator which accumulates the syntax errors,
linking problems and validation issues.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 07.11.11 15:14, Lucy wrote:
> I did this and it works, but I'm not sure if it is the right way to do it.
>
>
> EList<Diagnostic> errors = r.getErrors();
> TreeIterator<EObject> it = r.getAllContents();
> while(it.hasNext()) {
> Diagnostician.INSTANCE.validate(it.next());
> if(errors.size() > 0)
> break;
> }
>
>
Previous Topic:Get a DSL's metamodel
Next Topic:error &quot;Could not serialize EObject via backtracking&quot;
Goto Forum:
  


Current Time: Tue Apr 23 07:38:54 GMT 2024

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

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

Back to the top