Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to manufacture model elements
How to manufacture model elements [message #1047858] Tue, 23 April 2013 19:01
Chris Ainsley is currently offline Chris Ainsley
Messages: 74
Registered: March 2010
Location: UK
Member

Hello,

I have added an eOperation to my .ecore model that will return a list of elements, some of which are scanned and manufactured from the file system.

I also added an implementation for this method in a custom model implementation class and am using some naive model generation code as follows:

Collection collection = AttributesFactory.eINSTANCE.createCollection();
collection.setName(name);
someList.add(collection);


I really didn't expect it to work at all, but it does kind of work, albeit naively and only in the case that there are zero validation problems with the generated model item (Collection).

Now the problem is that when there is a problem validating the manufactured collection the following exception is thrown (as I really expected).

java.lang.IllegalArgumentException: You can only add issues for EObjects contained in the currently validated resource 'platform:/resource/TestProj/attributetest/test.attributes'. But the given EObject was contained in 'null'
	at org.eclipse.xtext.validation.AbstractDeclarativeValidator.checkIsFromCurrentlyCheckedResource(AbstractDeclarativeValidator.java:550)
	at org.eclipse.xtext.validation.AbstractDeclarativeValidator.acceptError(AbstractDeclarativeValidator.java:533)
	at org.eclipse.xtext.validation.AbstractDeclarativeValidator.error(AbstractDeclarativeValidator.java:421)
	at org.eclipse.xtext.validation.AbstractDeclarativeValidator.error(AbstractDeclarativeValidator.java:411)
	at org.eclipse.xtext.validation.AbstractDeclarativeValidator.error(AbstractDeclarativeValidator.java:407)


Now, obviously, creating an EObject is not just as simple as creating an object then setting the values. I also need to set at minimum some kind of eResource and possibly some other fields.

In this example, the created Collection object corresponds to a folder in the workspace. I'd like to be able to create this Collection and be able to show a validation problem without XText crashing.

How can this be achieved?
Previous Topic:unique name validation in project, not the whole workspace
Next Topic:variable should visible to only in present function.
Goto Forum:
  


Current Time: Sat Sep 20 06:17:49 GMT 2014

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

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