Skip to content
Snippets Groups Projects
Commit ebd5d5f3 authored by Simon Barner's avatar Simon Barner
Browse files

- Apply <underlying EMF Factory>.createFromString() to all String input in...

- Apply <underlying EMF Factory>.createFromString() to all String input in order to ensure conversion for input received e.g. from TextCellEditors on all code paths
parent a2a6a583
No related branches found
No related tags found
No related merge requests found
......@@ -51,13 +51,15 @@ public abstract class MultiInstanceAnnotationValueProviderBase<T extends IAnnota
extends SingleEStructuralFeatureValueProviderBase<T> {
/**
* {@link EDataType} of the value type V of the underlying EMap<String, V> storing the annotation
* {@link EDataType} of the value type V of the underlying EMap<String, V> storing the
* annotation
* instances.
*/
EDataType valueDataType;
/**
* {@link EFactory} to construct (in particular from a {@link String} representation instances of
* {@link EFactory} to construct (in particular from a {@link String} representation instances
* of
* the value type V of the underlying EMap<String, V> storing the annotation instances.
*/
EFactory valueFactory;
......@@ -90,13 +92,22 @@ public abstract class MultiInstanceAnnotationValueProviderBase<T extends IAnnota
}
/**
* Sets a value for a multi-instance {@link IAnnotatedSpecification} from a {@link String}
* representation of the input.
*/
@SuppressWarnings("unchecked")
private <V> void setAnnotationValueFromString(String value, T specification, String instanceKey) {
((EMap<String, V>)getAnnotationValue(specification)).put(instanceKey,
(V)valueFactory.createFromString(valueDataType, value));
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <V> void setAnnotationValue(V value, T specification, String instanceKey) {
if(value instanceof String) {
((EMap<String, V>)getAnnotationValue(specification)).put(instanceKey,
(V)valueFactory.createFromString(valueDataType, (String)value));
setAnnotationValueFromString((String)value, specification, instanceKey);
} else {
((EMap<String, V>)getAnnotationValue(specification)).put(instanceKey, value);
}
......@@ -104,11 +115,9 @@ public abstract class MultiInstanceAnnotationValueProviderBase<T extends IAnnota
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public void setAnnotationValue(String value, T specification, String instanceKey) {
((EMap<String, String>)getAnnotationValue(specification)).put(instanceKey, value);
setAnnotationValueFromString(value, specification, instanceKey);
}
/** {@inheritDoc} */
......
......@@ -95,20 +95,32 @@ public abstract class SingleEStructuralFeatureValueProviderBase<T extends IAnnot
this.structuralFeatureDefaultValue = structuralFeatureDefaultValue;
}
/**
* Sets a value for a {@link IAnnotatedSpecification} from a {@link String} representation of
* the input.
*/
private <V> void setAnnotationValueFromString(String value, T specification) {
specification.eSet(
structuralFeature,
structuralFeatureFactory.createFromString(
((EAttribute)structuralFeature).getEAttributeType(), value));
}
/** {@inheritDoc} */
@Override
public <U> void setAnnotationValue(U value, T specification) throws Exception {
specification.eSet(structuralFeature, value);
if(value instanceof String) {
setAnnotationValueFromString((String)value, specification);
} else {
specification.eSet(structuralFeature, value);
}
}
/** {@inheritDoc} */
@Override
public void setAnnotationValue(String value, T specification) throws Exception {
if(structuralFeature instanceof EAttribute) {
setAnnotationValue(
structuralFeatureFactory.createFromString(
((EAttribute)structuralFeature).getEAttributeType(), value),
specification);
setAnnotationValueFromString(value, specification);
} else {
throw new Exception(
"setAnnotationValue(String, T) is not supported / has not been implemented the annotation type " +
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment