Exception when serializing [message #774802] |
Wed, 04 January 2012 16:42 |
Thomas Williams Messages: 15 Registered: January 2012 |
Junior Member |
|
|
Dear Xtexters,
I'm having problems doing a round-trip of parse and serialize using XText 2.1.1.
Pared down to a minimum my grammar looks like this:
grammar psenterprise.xtext.GpromsLanguage with org.eclipse.xtext.common.Terminals
import "some url which the forum won't allow me to post" as ecore
generate gpromsLanguage "some other url which the forum won't allow me to post"
GeneralProcessModellingSystem:
variableTypeEntity=VariableTypeEntity ;
VariableTypeEntity:
name = ID
'=' default=RealNumber
':' lowerBound=RealNumber
':' upperBound=RealNumber
("UNIT" '=' unit=STRING)? ;
RealNumber returns ecore::EDouble:
('-')? INT ( '.' INT )? ;
And I am trying to parse and then serialize a String:
private static String LANGUAGE_TEXT = "GasConcentration = 1.0 : 0.0 : 10.0 UNIT = \"mol/m3\"";
public static void main(String[] args) throws IOException {
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
Injector injector = new GpromsLanguageStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.createResource(URI.createURI("dummy:/example.gPROMS"));
InputStream in = new ByteArrayInputStream(LANGUAGE_TEXT.getBytes());
resource.load(in, resourceSet.getLoadOptions());
if (!resource.getErrors().isEmpty()) {
System.out.println(resource.getErrors());
return;
}
GeneralProcessModellingSystem gpms = (GeneralProcessModellingSystem) resource.getContents().get(0);
VariableTypeEntity variableTypeEntity = gpms.getVariableTypeEntity();
System.out.println(org.eclipse.xtext.util.EmfFormatter.objToStr(gpms));
Serializer serializer = injector.getInstance(Serializer.class);
String s = serializer.serialize(gpms);
System.out.println(s);
}
I get the following output from EmfFormatter.objToStr(gpms):
GeneralProcessModellingSystem {
cref VariableTypeEntity variableTypeEntity VariableTypeEntity {
attr EString name 'GasConcentration'
attr EDouble default '1.0'
attr EDouble upperBound '10.0'
attr EString unit 'mol/m3'
}
}
Note the unexpected absence of the "lowerBound".
And then the serialize() call fails with:
Exception in thread "main" java.lang.RuntimeException: Could not serialize EObject via backtracking.
Constraint: null name=ID default=RealNumber lowerBound=RealNumber upperBound=RealNumber unit=STRING? null
Values: name(1), default(1), upperBound(1), unit(1)
Semantic Object: GeneralProcessModellingSystem.variableTypeEntity->VariableTypeEntity'GasConcentration'
Context: VariableTypeEntity
at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:70)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:425)
at psenterprise.xtext.serializer.AbstractGpromsLanguageSemanticSequencer.sequence_VariableTypeEntity(AbstractGpromsLanguageSemanticSequencer.java:112)
at psenterprise.xtext.serializer.AbstractGpromsLanguageSemanticSequencer.createSequence(AbstractGpromsLanguageSemanticSequencer.java:67)
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:215)
at psenterprise.xtext.serializer.AbstractGpromsLanguageSemanticSequencer.sequence_GeneralProcessModellingSystem(AbstractGpromsLanguageSemanticSequencer.java:102)
at psenterprise.xtext.serializer.AbstractGpromsLanguageSemanticSequencer.createSequence(AbstractGpromsLanguageSemanticSequencer.java:60)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:84)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:103)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:117)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:50)
at psenterprise.gparser.Main.serializeGPMS(Main.java:108)
at psenterprise.gparser.Main.main(Main.java:53)
From reading other posts and web-pages I'm fairly certain this is something to do with the "lowerBound" being considered "transient?" because its value is equal to the default for EDouble but I haven't been able to determine what I'm supposed to do to work around this.
I have tried implementing:
public class GpromsLanguageTransientValueService extends DefaultTransientValueService{
@Override
public boolean isTransient(EObject owner, EStructuralFeature feature, int index) {
System.out.println(owner);
if (owner instanceof VariableTypeEntity && GpromsLanguagePackage.VARIABLE_TYPE_ENTITY__LOWER_BOUND == feature.getFeatureID()) {
return false;
}
return super.isTransient(owner, feature, index);
}
}
And binding it with:
public class GpromsLanguageRuntimeModule extends psenterprise.xtext.AbstractGpromsLanguageRuntimeModule {
@Override
public Class<? extends ITransientValueService> bindITransientValueService() {
return GpromsLanguageTransientValueService.class;
}
}
And I can see that my TransientValueService is being called, but it's not fixing the problem.
Can anyone help?
Sincerely,
Tom
[Updated on: Wed, 04 January 2012 16:42] Report message to a moderator
|
|
|
|
|
|
|
Re: Exception when serializing [message #776886 is a reply to message #776873] |
Mon, 09 January 2012 13:08 |
|
yes and no - the transient value service should have done this too.
but of course you should have implemented and bound the correct one (org.eclipse.xtext.serializer.sequencer.ITransientValueService)
it is imho a bug that the missleading org.eclipse.xtext.parsetree.reconstr.ITransientValueService has a binding in the DefaultRuntimeModule
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01369 seconds