Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 432795 - XText doesn't want to serialize for some reasons
Summary: XText doesn't want to serialize for some reasons
Status: RESOLVED WONTFIX
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.6.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-15 04:59 EDT by Cedric Brun CLA
Modified: 2017-07-11 17:43 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cedric Brun CLA 2014-04-15 04:59:01 EDT
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 ?
Comment 1 Cedric Brun CLA 2014-04-15 05:25:37 EDT
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);
	}
}
Comment 2 Ed Merks CLA 2014-04-15 12:52:46 EDT
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...
Comment 3 Moritz Eysholdt CLA 2014-04-15 17:37:36 EDT
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.
Comment 4 Cedric Brun CLA 2014-04-16 03:51:38 EDT
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!