Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Exception when serializing
Exception when serializing [message #774802] Wed, 04 January 2012 16:42 Go to next message
Thomas Williams is currently offline Thomas WilliamsFriend
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 #775134 is a reply to message #774802] Thu, 05 January 2012 12:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this is a bug in the new serializer. please file a ticket.
as a workaround

(1) change grammar to
RealNumber returns ecore::EDoubleObject:
	('-')? INT ( '.' INT )? ;


(2) use the old one
fragment = parseTreeConstructor.ParseTreeConstructorFragment {}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Exception when serializing [message #775245 is a reply to message #775134] Thu, 05 January 2012 16:23 Go to previous messageGo to next message
Thomas Williams is currently offline Thomas WilliamsFriend
Messages: 15
Registered: January 2012
Junior Member
Thanks Christian,

So that I can be sure of writing a usable bug-report can I request some clarification:

* Can you confirm that this is two different workarounds, not two steps to the same workaround - I did just (1) and that seems to have fixed the problem.
* Presumably this fix works because the default for an EDoubleObject is null rather than 0.0 so it's not being marked as a transient ?

Thanks,

Tom
Re: Exception when serializing [message #775304 is a reply to message #775245] Thu, 05 January 2012 18:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi Tom

(1) and (2) are alternative solutions.
and yes "null" as default value does the trick. => it is more kind a workaround than a solution

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Exception when serializing [message #776873 is a reply to message #775304] Mon, 09 January 2012 12:48 Go to previous messageGo to next message
Thomas Williams is currently offline Thomas WilliamsFriend
Messages: 15
Registered: January 2012
Junior Member
Hi Christian,

And is the fact that I was unable to solve the problem by implementing my own TransientValueService the same bug? a separate bug? or just an example of me misunderstanding the use of TransientValueService ?

Sincerely,

Tom

Re: Exception when serializing [message #776886 is a reply to message #776873] Mon, 09 January 2012 13:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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
Re: Exception when serializing [message #776991 is a reply to message #776886] Mon, 09 January 2012 16:18 Go to previous messageGo to next message
Thomas Williams is currently offline Thomas WilliamsFriend
Messages: 15
Registered: January 2012
Junior Member
Thanks.

I have confirmed that by also using a custom org.eclipse.xtext.serializer.sequencer.ITransientValueService.
Re: Exception when serializing [message #831194 is a reply to message #776991] Wed, 28 March 2012 15:39 Go to previous message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

A link to the bug, in case anyone wants to follow it:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=368180
Previous Topic:setup with multiple xtext files in project
Next Topic:Using xtext without eclipse
Goto Forum:
  


Current Time: Fri Apr 19 00:53:31 GMT 2024

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

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

Back to the top