Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 347270

Summary: [Serualizer] ClassCastException in ValueConverter in case of Enums
Product: [Modeling] TMF Reporter: Holger Schill <Holger.Schill>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: moritz.eysholdt
Version: 2.0.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
patch to solve the problem none

Description Holger Schill CLA 2011-05-26 05:03:00 EDT
Created attachment 196644 [details]
patch to solve the problem

If you have a grammar like this:

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

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

Model:
	persons+=Person*
;
Person:
	kind=TYPE
;
enum TYPE :
	good | bad
;


You will get a ClassCastException by unsing the ValueConverter. This happens because in 

org.eclipse.xtext.serializer.acceptor.SequenceFeeder.getToken(RuleCall, Object, INode)

there is nobody taking care if it is a enum. Because of that for all assignments the ValueSerializer is used. 

org.eclipse.xtext.serializer.tokens.ValueSerializer.serializeAssignedValue(EObject, RuleCall, Object, INode, Acceptor)

This causes the problem because there is no ValueConverter that can handle Enums.
Instead of the ValueSerializer the EnumSerializer should be used in 
org.eclipse.xtext.serializer.acceptor.SequenceFeeder.getToken(RuleCall, Object, INode).

The attached patch solves the problem. I have written an testcase but I could not find other testcases for the serializer independent from xbase of xtend2.
@Moritz Please let me know where we should put common testcases for the serializer.
Comment 1 Moritz Eysholdt CLA 2011-05-31 10:10:37 EDT
the patch looks fine; you can commit it if you want to
Comment 2 Holger Schill CLA 2011-05-31 10:23:31 EDT
pushed to master.
Comment 3 Moritz Eysholdt CLA 2011-06-01 05:41:34 EDT
thx Holger!
Comment 4 Karsten Thoms CLA 2017-09-19 17:05:25 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 17:17:17 EDT
Closing all bugs that were set to RESOLVED before Neon.0