Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [SOLVED] Incomplete and invalid serialization of Ecore elements
[SOLVED] Incomplete and invalid serialization of Ecore elements [message #1692850] Mon, 20 April 2015 08:58 Go to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Dear all,

I'm currently writing unit tests for the serialization of my DSL from the Ecore elements that are corresponding to my DSL elements.

@Inject
protected ISerializer serializer;

public void serializeAgent() {
    String s =
          "agent Foo extends foo.ecore.SubAgent {\n"
	+ "new(b : int = 5) { super(null) }\n"
	+ "}";
    EObject object = agent(s);
    SaveOptions.Builder builder = SaveOptions.newBuilder();
    String text = serializer.serialize(object, builder.getOptions());
    assertEquals(s, text);
}


The grammar of my DSL is defined in the attached file. The key rules is "Parameter", which defines the default value for the parameter.
The function "agent()" is parsing the text and create the Ecore elements (similar to the clazz() function in the Xtend's unit tests).

The unit test fails since the output of the serializer is:
agent Foo extends


If I remove the default value, i.e " = 5", the output of the serializer is good and complete.


Could you give me a starting point from which I could explore and find the problem?
  • Attachment: SARL.xtext
    (Size: 8.29KB, Downloaded 72 times)

[Updated on: Mon, 20 April 2015 21:08]

Report message to a moderator

Re: Incomplete and invalid serialization of Ecore elements [message #1692943 is a reply to message #1692850] Mon, 20 April 2015 18:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13887
Registered: July 2009
Senior Member
Hi,

first of all: why do you extend xtend? why not extending xbase only?
then: did you check the parsed model is correct?
besides this: what about debugging for exceptions in the serializer (e.g. in the XXXSemanticSequencer)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incomplete and invalid serialization of Ecore elements [message #1692950 is a reply to message #1692943] Mon, 20 April 2015 19:18 Go to previous messageGo to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Dear Christian,

For extending our agent-oriented programming language (SARL), several of your users and designers have requested to include some object-oriented definitions as internal data structures (inner classes) in the agents. I'm trying to extend our language with OO statements coming from Xtend since the syntax and the operational semantic of Xtend are close to the ones of SARL. Moreover, we benefit of the developments on Xtend that are beyond the scope of SARL strictly speaking. The extension of SARL with OO from Xtend is a proof of concept that may be selected as the standard way by the agent-oriented programmers. Additionnally, the pair SARL+Xtend may becomes an alternative to Scala+Actor extension.

The parsed model seems to be correct. I have explored the Ecore elements by hand (with the debugger), and they seems to be correctly parsed.
I have started to debug the serializer and the SARLSemanticSequencer, but unfortunatelly, I have not detected any exception.
I'm still exploring, instruction per instruction, the execution of the serializer. I will give you more details when I obtain them from my exploration.

[Updated on: Mon, 20 April 2015 20:17]

Report message to a moderator

Re: Incomplete and invalid serialization of Ecore elements [message #1692962 is a reply to message #1692950] Mon, 20 April 2015 21:08 Go to previous message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
I found the problem: the types pointed by the JvmTypeReference cannot be resolved (especially "foo.ecore.SubAgent").

I solve the problem by forcing the validation of the code, and specifying the classpath URI context on the XtextResourceSet.

protected SarlAgent agent(String string) throws Exception {
    List<XtendTypeDeclaration> decls = file(string, true).getXtendTypes();
    return (SarlAgent) decls.get(decls.size() - 1);
}
protected XtendFile file(String string, boolean validate) throws Exception {
    XtendFile script = this.parser.parse(string);
    if (validate) {
        Resource resource = script.eResource();
        ResourceSet resourceSet = resource.getResourceSet();
        if (resourceSet instanceof XtextResourceSet) {
            ((XtextResourceSet) resourceSet).setClasspathURIContext(getClass());
        }
        assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
        Collection<Issue> issues = Collections2.filter(issues(resource), new Predicate<Issue>() {
                @Override
                public boolean apply(Issue input) {
                    return input.getSeverity() == Severity.ERROR;
                }
        });
        assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
    }
    return script;
}
Previous Topic:[SOLVED] Instance a custom element inside the model factory
Next Topic:[solved] external XML file for contentassist+codegeneration
Goto Forum:
  


Current Time: Mon Apr 19 13:27:22 GMT 2021

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

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

Back to the top