default value for Boolean attribute and serialization [message #1763633] |
Thu, 18 May 2017 08:31 |
Fy Za Messages: 245 Registered: March 2010 |
Senior Member |
|
|
Hi all,
I have this metamodel
package myDsl : myDsl = 'http://www.xtext.org/example/mydsl/MyDsl'
{
class Model
{
property greetings : Greeting[*|1] { ordered composes };
}
class Greeting
{
attribute name : String[?];
attribute condition : Boolean[1] = 'true';
}
}
It contains a boolean attribute "condition" (lowerbound 1, upperbound 1 and default value "true")
I create an Xtext project from this existing metamodel
The Xtext grammar is
// automatically generated by Xtext
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
import "http://www.xtext.org/example/mydsl/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Model returns Model:
{Model}
'Model'
'{'
('greetings' '{' greetings+=Greeting ( "," greetings+=Greeting)* '}' )?
'}';
Greeting returns Greeting:
'Greeting'
name=ID
(condition?='valid')?
;
I create the following model
Model {
greetings {
Greeting test valid
}
}
I save and I open the model with the MyDsl editor model (the emf editor for mydsl).
I change the condition attribute value to "false".
When I save the model, i have this error
java.lang.RuntimeException: Could not serialize EObject via backtracking.
Constraint: Greeting_Greeting returns Greeting: (name=ID condition?='valid'?);
Values: name(1), condition(1)
Semantic Object: Model.greetings[0]->Greeting'ss'
URI: platform:/resource/mydsl/My.mydsl
Context: Greeting returns Greeting
at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:131)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:480)
at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_Greeting(MyDslSemanticSequencer.java:53)
at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence(MyDslSemanticSequencer.java:35)
at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:325)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:352)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:263)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:412)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:478)
at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_Model(MyDslSemanticSequencer.java:65)
at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence(MyDslSemanticSequencer.java:38)
at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:118)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:142)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:206)
at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:369)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.saveOnlyIfChangedWithMemoryBuffer(ResourceImpl.java:1144)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:985)
at myDsl.presentation.MyDslEditor$18.execute(MyDslEditor.java:1498)
at org.eclipse.ui.actions.WorkspaceModifyOperation.lambda$0(WorkspaceModifyOperation.java:107)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:128)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
It seems that it is caused by the default value.
Any suggestion how resolve it?
best regards,
[Updated on: Thu, 18 May 2017 08:33] Report message to a moderator
|
|
|
Re: default value for Boolean attribute and serialization [message #1763635 is a reply to message #1763633] |
Thu, 18 May 2017 09:18 |
|
so you have an opposite default value that differs from the default value in the concrete syntax right?
you could play arround with the transient value service.
public class MyDslTransientValueService extends DefaultTransientValueService {
@Override
public boolean isTransient(EObject owner, EStructuralFeature feature, int index) {
if (feature == TestPackage.Literals.GREETING__FLAG) {
Boolean value = (Boolean)owner.eGet(feature);
if (value == null) {
return false;
} else if (value == Boolean.FALSE) {
return true;
}
}
return super.isTransient(owner, feature, index);
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04009 seconds