Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Model serialization problem
Model serialization problem [message #1023942] Mon, 25 March 2013 10:09 Go to next message
José Miguel P. is currently offline José Miguel P.
Messages: 62
Registered: March 2010
Member

Hi!

Thanks for your time, in advance.

I have a xText grammar and I'm generating my ecore model from the grammar. I have checked the ecore model, and I can see that all attributes are optionals in all the metaclass, however when I try to serialize a model, I get the follow error:

org.eclipse.xtext.validation.IConcreteSyntaxValidator$InvalidConcreteSyntaxException: These errors need to be fixed before the model can be serialized.
Root.tablef->TableF.rules[0]->Rule: Feature Rule.aelectors must be set.
Root.tablef->TableF.rules[0]->Rule.select->Select: Feature Select.ieSelects must be set.
....
....
	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:316)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
	at org.eclipselabs.xtext.utils.unittesting.XtextTest.loadAndSaveModule(XtextTest.java:393)
	at org.eclipselabs.xtext.utils.unittesting.XtextTest.testFile(XtextTest.java:187)
	at com.intelliment.intellifw.driver.iptables.parser.tests.Prueba.test(Prueba.java:24)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.eclipse.xtext.junit4.XtextRunner$1.evaluate(XtextRunner.java:55)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


As took at the beginning, all features are optionals, so I don't know why Serializer need all instanced. In my proof, I can read a xText model, and I get the error trying serialize the same.

Any idea?

Thanks in advance!
Re: Model serialization problem [message #1023946 is a reply to message #1023942] Mon, 25 March 2013 10:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5849
Registered: July 2009
Senior Member
Can you share something reproducable?
Re: Model serialization problem [message #1027399 is a reply to message #1023946] Tue, 26 March 2013 19:33 Go to previous messageGo to next message
José Miguel P. is currently offline José Miguel P.
Messages: 62
Registered: March 2010
Member

Hi Christian,

Sorry for the delay, I've been trying found the mistake, here is my conclusions:

This is my grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

DslRoot:
	tabTypeOne = TabTypeOne &
	tabTypeTwo = TabTypeTwo?
;

TabTypeOne:
	'*typeOne'
	rules+=Rule*
	'CONFIRM'
;

TabTypeTwo:
	'*typeTwo'
	rules+=Rule*
	'CONFIRM'
;



/*************************
 * Rule
 *************************/
Rule:
	tab = TargetTab?
	do = Do
	result = Result
	resultOptions = ResultOptions
	;

TargetTab:
	'-t' name = ('filter'|'nat'|'mangle'|'raw')
;

Do:
	('-A'|'--append') (standarAppendTo= ('SOURCE' | 'TARGET' | 'ELEMENT' | 'PRESOURCE' | 'POSTSOURCE'))
;



Result:
	'-res' (value=('ACCEPT' | 'REJECT'))
;

ResultOptions:
	('--resaon' rejectWith=('reason-one'|'reason-two'|'reason-three'))? &
	('--to--target-element' rejectWith=OBJ)? &
	('--to-source-element' sourceObj=OBJ)?
;

/*
 * 
 * TERMINALES
 * 
 */

terminal DASH : '-';

terminal OBJ:
	INT DASH INT
;




For my grammar restrictions, ResultOptions are not mandatory in Rule, but if it appear, it can contains rejectWith, rejectWith and/or sourceObj in any order, so I have model it like


...

Rule:
	tab = TargetTab?
	do = Do
	result = Result
	resultOptions = ResultOptions  <- Not mandatory
	;


// all optionals and in any order, so ResultOptions in occasions will not be instanced
ResultOptions:
	('--resaon' rejectWith=('reason-one'|'reason-two'|'reason-three'))? &  
	('--to--target-element' rejectWith=OBJ)? &
	('--to-source-element' sourceObj=OBJ)?
;




Using this approximation, I can load models like this:

*typeOne
-A ELEMENT -res ACCEPT
-A ELEMENT -res REJECT --resaon reason-three
-A ELEMENT-res ACCEPT
CONFIRM
# THO
*typeTwo
-A PRESOURCE -res ACCEPT --to--target-element 15-25
CONFIRM


When I try save the model, I get the problem


// Test
public class LoadSaveTest {

	public static void main(String[] args) throws IOException {
		
		new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		
		XtextResourceSet resourceSet = new XtextResourceSet();		
		Resource res = resourceSet.getResource(URI.createFileURI("scr/scr1.mydsl"), true);
		DslRoot script = (DslRoot)res.getContents().get(0);
		
		
		Resource res2 = resourceSet.createResource(URI.createFileURI("scr/scr1_cp.mydsl"));
		res2.getContents().add(script);
		res2.save(null);


	}

}




Error:


Exception in thread "main" org.eclipse.xtext.validation.IConcreteSyntaxValidator$InvalidConcreteSyntaxException: These errors need to be fixed before the model can be serialized.
DslRoot.tabTypeOne->TabTypeOne.rules[0]->Rule: Feature Rule.resultOptions must be set.
DslRoot.tabTypeOne->TabTypeOne.rules[2]->Rule: Feature Rule.resultOptions must be set.

	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:330)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:992)
	at org.xtext.example.mydsl.tests.LoadSaveTest.main(LoadSaveTest.java:39)




I understand this problem is normal because Rule need resultOptions set. For try, I have established it by hand doing:



public class LoadSaveTest {

...
		for (Rule r : script.getTabTypeOne().getRules()){
			if (r.getResultOptions() == null){
				r.setResultOptions(MyDslFactory.eINSTANCE.createResultOptions());
			}
		}		
...

}



By doing it, I get the follow problem:


Exception in thread "main" java.lang.RuntimeException: Could not serialize EObject via backtracking.
Constraint: null (rejectWith='reason-one' | rejectWith='reason-three' | rejectWith='reason-two' | sourceObj=OBJ | targetObj=OBJ)+ null
Values: 
Semantic Object: DslRoot.tabTypeOne->TabTypeOne.rules[0]->Rule.resultOptions->ResultOptions
Context: ResultOptions
	at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:70)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:441)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_ResultOptions(MyDslSemanticSequencer.java:107)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.createSequence(MyDslSemanticSequencer.java:52)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:222)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:401)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_Rule(MyDslSemanticSequencer.java:125)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.createSequence(MyDslSemanticSequencer.java:58)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:239)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:394)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_TabTypeOne(MyDslSemanticSequencer.java:134)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.createSequence(MyDslSemanticSequencer.java:64)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:299)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:222)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:401)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:439)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_DslRoot(MyDslSemanticSequencer.java:98)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.createSequence(MyDslSemanticSequencer.java:40)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:85)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:108)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:130)
	at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:330)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:992)
	at org.xtext.example.mydsl.tests.LoadSaveTest.main(LoadSaveTest.java:39)




I tried by setting ResultOptions optional

Rule:
	tab = TargetTab?
	do = Do
	result = Result
	resultOptions = ResultOptions? <- optional
	;


but I get a problem generating the grammar:

...

3272 [main] ERROR enerator.CompositeGeneratorFragment  - java.io.FileNotFoundException: ../org.xtext.example.mydsl.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyDslParser.java (No such file or directory)
org.eclipse.emf.common.util.WrappedException: java.io.FileNotFoundException: ../org.xtext.example.mydsl.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyDslParser.java (No such file or directory)
	at org.eclipse.xtext.util.Files.readFileIntoString(Files.java:129)
	at org.eclipse.xtext.generator.parser.antlr.AbstractAntlrGeneratorFragment.simplifyUnorderedGroupPredicates(AbstractAntlrGeneratorFragment.java:123)
	at org.eclipse.xtext.generator.parser.antlr.AbstractAntlrGeneratorFragment.simplifyUnorderedGroupPredicatesIfRequired(AbstractAntlrGeneratorFragment.java:111)
	at org.eclipse.xtext.generator.parser.antlr.XtextAntlrUiGeneratorFragment.generate(XtextAntlrUiGeneratorFragment.java:51)
	at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:92)
	at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:113)
	at org.eclipse.xtext.generator.Generator.generate(Generator.java:361)
	at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:128)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: java.io.FileNotFoundException: ../org.xtext.example.mydsl.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyDslParser.java (No such file or directory)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:120)
	at java.io.FileInputStream.<init>(FileInputStream.java:79)
	at org.eclipse.xtext.util.Files.readFileIntoString(Files.java:126)
	... 17 more
...



How can I do it?

Thanks so much in advance.
Re: Model serialization problem [message #1027773 is a reply to message #1027399] Wed, 27 March 2013 07:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5849
Registered: July 2009
Senior Member
Hmm sounds like a bug to me
Re: Model serialization problem [message #1027776 is a reply to message #1027773] Wed, 27 March 2013 07:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5849
Registered: July 2009
Senior Member
P.S: did you try to use the old parsetreeconstructorfragment instead of the serializer fragment in the workflow
Re: Model serialization problem [message #1027990 is a reply to message #1027776] Wed, 27 March 2013 13:32 Go to previous messageGo to next message
José Miguel P. is currently offline José Miguel P.
Messages: 62
Registered: March 2010
Member

Hi Christian,

I was not try with the old ParseTreeConstructorFragment, I have try for this example and it works, but not properly. Executing the last LoadSaveTest with this input:

*typeOne
-A ELEMENT -res ACCEPT
-A ELEMENT -res REJECT --resaon reason-three
-A ELEMENT-res ACCEPT
CONFIRM
# THO
*typeTwo
-A PRESOURCE -res ACCEPT --to--target-element 15-25
CONFIRM


I get this output:

*typeOne
-A ELEMENT -res ACCEPT
-A ELEMENT -res REJECT --resaon reason-three
-A ELEMENT-res ACCEPT
CONFIRM


Also, I have other similar grammar but more complex, and I'm having the same problem using ParseTreeConstructorFragment and this is the error:

... 

Exception in thread "main" java.lang.IllegalArgumentException: Could not determine the value for the unassigned rulecall of rule COLON from within rule OBJ. You might want to implement org.eclipse.xtext.parsetree.reconstr.ITokenSerializer$IValueSerializer.serializeUnassignedValue() or modify your implementation to handle this rulecall.
	at org.eclipse.xtext.parsetree.reconstr.impl.ValueSerializer.serializeUnassignedValue(ValueSerializer.java:98)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor$UnassignedTextToken.serializeInternal(AbstractParseTreeConstructor.java:369)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor$AbstractToken.serialize(AbstractParseTreeConstructor.java:158)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:771)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:766)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:766)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:766)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:766)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:766)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serializeSubtree(AbstractParseTreeConstructor.java:732)
	at org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:61)
	at org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:67)
	at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:330)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:992)
	at com.intelliment.intellifw.driver.iptables.parser.tests.Prueba2.main(Prueba2.java:70)


I'm going to try reproduce this error in the small grammar.

Thanks in advance!
Re: Model serialization problem [message #1031215 is a reply to message #1027990] Mon, 01 April 2013 07:19 Go to previous messageGo to next message
José Miguel P. is currently offline José Miguel P.
Messages: 62
Registered: March 2010
Member

There are a mistake in my last example, with the last grammar and example, the last ParseTreeConstructorFragment is working properly.

Should it work by using the SerializerFragment?

I'm having other related problems with a similar but more complex grammar, I'm going to try isolate the problem.
Thanks in advance.
Re: Model serialization problem [message #1031261 is a reply to message #1031215] Mon, 01 April 2013 08:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5849
Registered: July 2009
Senior Member
Yes if it does not work with "the new" serialzer then it is bug.
Please file a ticket into bugzilla

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Model serialization problem [message #1031838 is a reply to message #1031261] Tue, 02 April 2013 05:06 Go to previous message
José Miguel P. is currently offline José Miguel P.
Messages: 62
Registered: March 2010
Member

Thanks for your help.
Here is the ticket https://bugs.eclipse.org/bugs/show_bug.cgi?id=404704

José Miguel.
Previous Topic:ResourceDescriptionStrategy for locally defined eObjects
Next Topic:Get referenced object in another model (cyclic resolution or no corresponding inode)
Goto Forum:
  


Current Time: Mon Apr 21 03:17:26 EDT 2014

Powered by FUDForum. Page generated in 0.01829 seconds