Community
Participate
Working Groups
Hi, A bit of background : I'm currently trying to make EcoreTools 2 play nicer with Xcore, what I'm basically doing is that I'm making sure Sirius can load the model correctly (Sirius in those case will create an XtextResourceSet and configure it by declaring the Java handlers & co with the current project) The model looks correctly loaded and Sirius allow me to graphically edit and modify it. But even with no modification of the Xcore resource in memorry, when calling save() I get an exception, for instance : !STACK 0 org.eclipse.xtext.validation.IConcreteSyntaxValidator$InvalidConcreteSyntaxException: These errors need to be fixed before the model can be serialized. XPackage'domain'.classifiers[0]->XClass'Library': Feature XClass.interface must be set. Constraint: (abstract?|interface) Quantities: abstract:0, interface:0 XPackage'domain'.classifiers[1]->XClass'Book': Feature XClass.interface must be set. Constraint: (abstract?|interface) Quantities: abstract:0, interface:0 And the save is not done, worst than that, the Xcore file is emptied. Call stacktrace is : at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:96) at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:130) at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:344) at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430) It looks to me like the Serializer is not happy with booleans which would not be set (!). Is that expected ? Is there something we can do here ? Is there some specific operation/behavior I could plug before the save to make sure the model is in a state which will make the Serializer happy ?
A very crude JUnit Test (should be launched as an Plugin Test) which fails for me with the errors I mentionned in the previous comment : public class TestXCoreSerialization { String xCoreContent = "package domain" + "\n" + "class Book { \n String title \n " + "}\n" + "class Library {" + "}"; @Test public void test() throws IOException { XtextResourceSet set = new XtextResourceSet(); Resource res = set.createResource(URI .createURI("platform:/resource/xcore/model/domain.xcore")); InputStream is = new ByteArrayInputStream( xCoreContent.getBytes("UTF-8")); res.load(is, Collections.EMPTY_MAP); res.save(new OutputStream() { @Override public void write(int b) throws IOException { } }, Collections.EMPTY_MAP); } }
I guess this part of the grammar is confusing for the serializer: XClass: {XClass} (annotations+=XAnnotation)* ((abstract?='abstract'? 'class') | interface?= 'interface') name = ID But in the case you mentioned both abstract and interface are false, so it should just choose the class keyword... I'll have a closer look when I have some time. Maybe Moritz understands better at a glance...
Hi Cedric, hi Ed, the serializer works properly if you turn off validation: public class TestXCoreSerialization { String xCoreContent = "package domain" + "\n" + "class Book { \n String title \n " + "}\n" + "class Library {" + "}"; @Test public void test() throws IOException { XtextResourceSet set = new XtextResourceSet(); Resource res = set.createResource(URI.createURI("platform:/resource/xcore/model/domain.xcore")); InputStream is = new ByteArrayInputStream(xCoreContent.getBytes("UTF-8")); res.load(is, Collections.EMPTY_MAP); ByteArrayOutputStream out = new ByteArrayOutputStream(); res.save(out, SaveOptions.newBuilder().noValidation().getOptions().toOptionsMap()); System.out.println(out); } } Turning off validation is not as bad as it sounds. The ConcreteSyntaxValidator is a relict from the days of the old serializer (org.eclipse.xtext.parsetree.reconstr). I built it as an attempt to provider more understandable error messages in case a model is not serializeable. Even though the error messages with the new serializer (org.eclipse.xtext.serializer) are much better, the ConcreteSyntaxValidator is still enabled as there are a few cases were it provides simpler (better) error messages. In this case, however, the error raised by the ConcreteSyntaxValidator is a false positive. This is a bug. I'm moving the ticket to Xtext.
I figured I could turn it off but had no clue what were the actual implications, you basically answered my next question before I even had to ask it. Thanks!