[SOLVED] Incomplete and invalid serialization of Ecore elements [message #1692850] |
Mon, 20 April 2015 08:58 |
|
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:
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 88 times)
[Updated on: Mon, 20 April 2015 21:08] Report message to a moderator
|
|
|
|
Re: Incomplete and invalid serialization of Ecore elements [message #1692950 is a reply to message #1692943] |
Mon, 20 April 2015 19:18 |
|
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 |
|
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;
}
|
|
|
Powered by
FUDForum. Page generated in 0.02806 seconds