Skip to main content



      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 04:58 Go to next message
Eclipse UserFriend
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 114 times)

[Updated on: Mon, 20 April 2015 17:08] by Moderator

Re: Incomplete and invalid serialization of Ecore elements [message #1692943 is a reply to message #1692850] Mon, 20 April 2015 14:23 Go to previous messageGo to next message
Eclipse UserFriend
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)
Re: Incomplete and invalid serialization of Ecore elements [message #1692950 is a reply to message #1692943] Mon, 20 April 2015 15:18 Go to previous messageGo to next message
Eclipse UserFriend
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 16:17] by Moderator

Re: Incomplete and invalid serialization of Ecore elements [message #1692962 is a reply to message #1692950] Mon, 20 April 2015 17:08 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 18:31:12 EDT 2025

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

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

Back to the top