Bug 469806 - [serializer] TransientValueService.defaultValueIsSerializeable() is sometimes wrong
Summary: [serializer] TransientValueService.defaultValueIsSerializeable() is sometimes...
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.8.2   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-10 04:21 EDT by Moritz Eysholdt CLA
Modified: 2015-06-10 07:10 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Moritz Eysholdt CLA 2015-06-10 04:21:18 EDT
the method TransientValueService.defaultValueIsSerializeable(EStructuralFeature) currently has this implementation:

protected boolean defaultValueIsSerializeable(EStructuralFeature feature) {
	if (feature instanceof EAttribute) {
		if (feature.getEType() == EcorePackage.eINSTANCE.getEString() && feature.getDefaultValue() == null)
			return false;
		return true;
	}
	return false;
}

The assumption that any default value from an EAttribute can be serialized except if it's EString with value null - is far to narrow. 

A better strategy would be 

if(feature instanceof EAttribute) {
  return defaultVal != null || isJavaPrimitive(featureType) || isEnumLiteral(featureType)
}
Comment 1 Moritz Eysholdt CLA 2015-06-10 04:22:42 EDT
workaround: Subclass (Legacy)TransientValueService, override .defaultValueIsSerializeable() and bind it in the runtime module of your language.
Comment 2 Michael Vorburger CLA 2015-06-10 07:10:16 EDT
> workaround

isJavaPrimitive(featureType) OK as below?

isEnumLiteral(featureType) how to?


protected boolean defaultValueIsSerializeable(EStructuralFeature feature) {
	if(feature instanceof EAttribute) {
		EClassifier featureType = feature.getEType();
		Object defaultValue = feature.getDefaultValue();
		return defaultValue != null || isJavaPrimitive(featureType) || isEnumLiteral(featureType);
	}
	return false;
}

private boolean isJavaPrimitive(EClassifier eType) {
	return eType.getInstanceClass().isPrimitive();
}

private boolean isEnumLiteral(EClassifier eType) {
	// TODO Not eType instanceof EEnumLiteral but ??
	return false;
}