diff options
author | glefur | 2012-02-08 10:45:16 +0000 |
---|---|---|
committer | glefur | 2012-02-08 10:45:16 +0000 |
commit | 94c169041553dcca46ba0f7cd3a546672553f582 (patch) | |
tree | 28fbb819decc4afa670769f341565e59e2e27490 | |
parent | c2f2ac15bb711b10444e0e2e1c7a0acd7999d204 (diff) | |
download | org.eclipse.eef-94c169041553dcca46ba0f7cd3a546672553f582.tar.gz org.eclipse.eef-94c169041553dcca46ba0f7cd3a546672553f582.tar.xz org.eclipse.eef-94c169041553dcca46ba0f7cd3a546672553f582.zip |
FIXED: NPE on optional Integer
-rw-r--r-- | plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFConverterUtil.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFConverterUtil.java b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFConverterUtil.java index f3a1541b6..be333c939 100644 --- a/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFConverterUtil.java +++ b/plugins/org.eclipse.emf.eef.runtime/src/org/eclipse/emf/eef/runtime/impl/utils/EEFConverterUtil.java @@ -130,4 +130,25 @@ public class EEFConverterUtil extends EcoreUtil { Boolean value = (Boolean)createFromString(eBoolean, literal); return value.booleanValue(); } + + /** + * Creates an instance of the datatype. + * + * @param eDataType + * the datatype to instantiate. + * @param literal + * the string value of the datatype. + * @return an instance of the datatype. + * @see #convertToString(EDataType, Object) + */ + public static Object createFromString(EDataType eDataType, String literal) { + // If the string literal is null or empty, the returned value is the + // default value of the DataType + if (literal == null || literal.trim().length() == 0) { + return eDataType.getDefaultValue(); + } else { + return EcoreUtil.createFromString(eDataType, literal); + } + } + } |