From ebd5d5f30c6a200bdd8bb13f8374a776aa136c0a Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Thu, 28 Aug 2014 12:56:20 +0000 Subject: [PATCH] - 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 --- ...tiInstanceAnnotationValueProviderBase.java | 23 +++++++++++++------ ...leEStructuralFeatureValueProviderBase.java | 22 ++++++++++++++---- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/MultiInstanceAnnotationValueProviderBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/MultiInstanceAnnotationValueProviderBase.java index 832cc75ba..97f068506 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/MultiInstanceAnnotationValueProviderBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/MultiInstanceAnnotationValueProviderBase.java @@ -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} */ diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/SingleEStructuralFeatureValueProviderBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/SingleEStructuralFeatureValueProviderBase.java index 1a33ffcc4..1cbd3bb58 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/SingleEStructuralFeatureValueProviderBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/SingleEStructuralFeatureValueProviderBase.java @@ -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 " + -- GitLab