Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordstadnik2006-02-13 16:49:10 +0000
committerdstadnik2006-02-13 16:49:10 +0000
commitecbc345c467e4ae99fecad96bb95cfd80f082ad4 (patch)
tree7e6f046d72a6b9f4a424f593edaf4a3924e9e518
parent283600b5feb4497b74defa4851ca9d958c405832 (diff)
downloadorg.eclipse.gmf-tooling-ecbc345c467e4ae99fecad96bb95cfd80f082ad4.tar.gz
org.eclipse.gmf-tooling-ecbc345c467e4ae99fecad96bb95cfd80f082ad4.tar.xz
org.eclipse.gmf-tooling-ecbc345c467e4ae99fecad96bb95cfd80f082ad4.zip
#127336 add convertion from string
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/PortCanonicalEditPolicy.java11
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/ShipCanonicalEditPolicy.java11
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/TaiPanBaseItemSemanticEditPolicy.java2
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanAbstractParser.java73
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanElementTypes.java1
-rw-r--r--plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/providers/AbstractParserGenerator.java2
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/providers/AbstractParser.javajet73
7 files changed, 169 insertions, 4 deletions
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/PortCanonicalEditPolicy.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/PortCanonicalEditPolicy.java
index 167e3b893..9cbc1c528 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/PortCanonicalEditPolicy.java
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/PortCanonicalEditPolicy.java
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2005 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dmitri Stadnik (Borland) - initial API and implementation
+ */
package org.eclipse.gmf.examples.taipan.gmf.editor.edit.policies;
import org.eclipse.core.runtime.IAdaptable;
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/ShipCanonicalEditPolicy.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/ShipCanonicalEditPolicy.java
index c12d49676..8067531fe 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/ShipCanonicalEditPolicy.java
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/ShipCanonicalEditPolicy.java
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2005 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dmitri Stadnik (Borland) - initial API and implementation
+ */
package org.eclipse.gmf.examples.taipan.gmf.editor.edit.policies;
import org.eclipse.core.runtime.IAdaptable;
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/TaiPanBaseItemSemanticEditPolicy.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/TaiPanBaseItemSemanticEditPolicy.java
index 82cc5fa71..2de725cc3 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/TaiPanBaseItemSemanticEditPolicy.java
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/edit/policies/TaiPanBaseItemSemanticEditPolicy.java
@@ -37,8 +37,6 @@ import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipReques
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.gmf.examples.taipan.gmf.editor.part.TaiPanDiagramEditorPlugin;
-
/**
* @generated
*/
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanAbstractParser.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanAbstractParser.java
index ab31bc4e9..6f691a283 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanAbstractParser.java
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanAbstractParser.java
@@ -221,6 +221,13 @@ public abstract class TaiPanAbstractParser implements IParser {
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ value = new Character(s.charAt(0));
+ }
} else {
value = new InvalidValue("Value of type Character is expected");
}
@@ -229,6 +236,17 @@ public abstract class TaiPanAbstractParser implements IParser {
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Byte.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Byte value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Byte is expected");
}
@@ -237,6 +255,17 @@ public abstract class TaiPanAbstractParser implements IParser {
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Short.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Short value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Short is expected");
}
@@ -245,6 +274,17 @@ public abstract class TaiPanAbstractParser implements IParser {
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Integer.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Integer value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Integer is expected");
}
@@ -253,6 +293,17 @@ public abstract class TaiPanAbstractParser implements IParser {
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Long.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Long value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Long is expected");
}
@@ -261,6 +312,17 @@ public abstract class TaiPanAbstractParser implements IParser {
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Float.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Float value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Float is expected");
}
@@ -269,6 +331,17 @@ public abstract class TaiPanAbstractParser implements IParser {
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Double.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Double value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Double is expected");
}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanElementTypes.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanElementTypes.java
index 5386e6a48..722f9f444 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanElementTypes.java
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/src/org/eclipse/gmf/examples/taipan/gmf/editor/providers/TaiPanElementTypes.java
@@ -25,7 +25,6 @@ import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.gmf.examples.taipan.TaiPanFactory;
import org.eclipse.gmf.examples.taipan.TaiPanPackage;
import org.eclipse.gmf.examples.taipan.gmf.editor.part.TaiPanDiagramEditorPlugin;
diff --git a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/providers/AbstractParserGenerator.java b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/providers/AbstractParserGenerator.java
index fd8c97777..d4043f746 100644
--- a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/providers/AbstractParserGenerator.java
+++ b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/providers/AbstractParserGenerator.java
@@ -20,7 +20,7 @@ public class AbstractParserGenerator
protected final String TEXT_3 = NL + "import java.text.MessageFormat;" + NL + "import java.text.ParsePosition;" + NL + "" + NL + "import org.eclipse.core.runtime.IAdaptable;" + NL + "import org.eclipse.emf.ecore.EClassifier;" + NL + "import org.eclipse.emf.ecore.EDataType;" + NL + "import org.eclipse.emf.ecore.EEnum;" + NL + "import org.eclipse.emf.ecore.EEnumLiteral;" + NL + "import org.eclipse.emf.ecore.EObject;" + NL + "import org.eclipse.emf.ecore.EStructuralFeature;" + NL + "import org.eclipse.gmf.runtime.common.core.command.ICommand;" + NL + "import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;" + NL + "import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;" + NL + "import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;" + NL + "import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;" + NL + "import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;" + NL + "import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;" + NL + "import org.eclipse.jface.text.contentassist.IContentAssistProcessor;";
protected final String TEXT_4 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public abstract class ";
protected final String TEXT_5 = " implements IParser {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate String viewPattern;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate MessageFormat viewProcessor;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate String editPattern;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate MessageFormat editProcessor;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic String getViewPattern() {" + NL + "\t\treturn viewPattern;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected MessageFormat getViewProcessor() {" + NL + "\t\treturn viewProcessor;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void setViewPattern(String viewPattern) {" + NL + "\t\tthis.viewPattern = viewPattern;" + NL + "\t\tviewProcessor = createViewProcessor(viewPattern);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected MessageFormat createViewProcessor(String viewPattern) {" + NL + "\t\treturn new MessageFormat(viewPattern);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic String getEditPattern() {" + NL + "\t\treturn editPattern;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected MessageFormat getEditProcessor() {" + NL + "\t\treturn editProcessor;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void setEditPattern(String editPattern) {" + NL + "\t\tthis.editPattern = editPattern;" + NL + "\t\teditProcessor = createEditProcessor(editPattern);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected MessageFormat createEditProcessor(String editPattern) {" + NL + "\t\treturn new MessageFormat(editPattern);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic String getPrintString(IAdaptable adapter, int flags) {" + NL + "\t\treturn getStringByPattern(adapter, flags, getViewPattern(), getViewProcessor());" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic String getEditString(IAdaptable adapter, int flags) {" + NL + "\t\treturn getStringByPattern(adapter, flags, getEditPattern(), getEditProcessor());" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected abstract String getStringByPattern(IAdaptable adapter, int flags, String pattern, MessageFormat processor);" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic IParserEditStatus isValidEditString(IAdaptable element, String editString) {" + NL + "\t\tParsePosition pos = new ParsePosition(0);" + NL + "\t\tObject[] values = getEditProcessor().parse(editString, pos);" + NL + "\t\tif (values == null) {" + NL + "\t\t\treturn new ParserEditStatus(";
- protected final String TEXT_6 = ".ID," + NL + "\t\t\t\tIParserEditStatus.UNEDITABLE, \"Invalid input at \" + pos.getErrorIndex());" + NL + "\t\t}" + NL + "\t\treturn validateNewValues(values);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected IParserEditStatus validateNewValues(Object[] values) {" + NL + "\t\treturn ParserEditStatus.EDITABLE_STATUS;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ICommand getParseCommand(IAdaptable adapter, String newString, int flags) {" + NL + "\t\tObject[] values = getEditProcessor().parse(newString, new ParsePosition(0));" + NL + "\t\tif (values == null || validateNewValues(values).getCode() != IParserEditStatus.EDITABLE) {" + NL + "\t\t\treturn UnexecutableCommand.INSTANCE;" + NL + "\t\t}" + NL + "\t\treturn getParseCommand(adapter, values);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected abstract ICommand getParseCommand(IAdaptable adapter, Object[] values);" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic IContentAssistProcessor getCompletionProcessor(IAdaptable element) {" + NL + "\t\treturn null;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected ICommand getModificationCommand(EObject element, EStructuralFeature feature, Object value) {" + NL + "\t\tvalue = getValidNewValue(feature, value);" + NL + "\t\tif (value instanceof InvalidValue) {" + NL + "\t\t\treturn UnexecutableCommand.INSTANCE;" + NL + "\t\t}" + NL + "\t\tSetRequest request = new SetRequest(element, feature, value);" + NL + "\t\treturn new SetValueCommand(request);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected Object getValidValue(EStructuralFeature feature, Object value) {" + NL + "\t\tEClassifier type = feature.getEType();" + NL + "\t\tif (type instanceof EDataType) {" + NL + "\t\t\tClass iClass = type.getInstanceClass();" + NL + "\t\t\tif (String.class.equals(iClass)) {" + NL + "\t\t\t\tif (value == null) {" + NL + "\t\t\t\t\tvalue = \"\";" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\treturn value;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected Object getValidNewValue(EStructuralFeature feature, Object value) {" + NL + "\t\tEClassifier type = feature.getEType();" + NL + "\t\tif (type instanceof EDataType) {" + NL + "\t\t\tClass iClass = type.getInstanceClass();" + NL + "\t\t\tif (Boolean.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Boolean) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof String) {" + NL + "\t\t\t\t\tvalue = Boolean.valueOf((String) value);" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Boolean is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Character.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Character) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Character is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Byte.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Byte) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Byte(((Number) value).byteValue());" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Byte is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Short.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Short) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Short(((Number) value).shortValue());" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Short is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Integer.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Integer) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Integer(((Number) value).intValue());" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Integer is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Long.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Long) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Long(((Number) value).longValue());" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Long is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Float.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Float) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Float(((Number) value).floatValue());" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Float is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Double.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Double) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Double(((Number) value).doubleValue());" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Double is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (type instanceof EEnum) {" + NL + "\t\t\t\tif (value instanceof String) {" + NL + "\t\t\t\t\tEEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);" + NL + "\t\t\t\t\tif (literal == null) {" + NL + "\t\t\t\t\t\tvalue = new InvalidValue(\"Unknown literal: \" + value);" + NL + "\t\t\t\t\t} else {" + NL + "\t\t\t\t\t\tvalue = literal.getInstance();" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type String is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\treturn value;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected class InvalidValue {" + NL + "" + NL + "\t\tprivate String description;" + NL + "" + NL + "\t\tpublic InvalidValue(String description) {" + NL + "\t\t\tthis.description = description;" + NL + "\t\t}" + NL + "" + NL + "\t\tpublic String toString() {" + NL + "\t\t\treturn description;" + NL + "\t\t}" + NL + "\t}" + NL + "}";
+ protected final String TEXT_6 = ".ID," + NL + "\t\t\t\tIParserEditStatus.UNEDITABLE, \"Invalid input at \" + pos.getErrorIndex());" + NL + "\t\t}" + NL + "\t\treturn validateNewValues(values);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected IParserEditStatus validateNewValues(Object[] values) {" + NL + "\t\treturn ParserEditStatus.EDITABLE_STATUS;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ICommand getParseCommand(IAdaptable adapter, String newString, int flags) {" + NL + "\t\tObject[] values = getEditProcessor().parse(newString, new ParsePosition(0));" + NL + "\t\tif (values == null || validateNewValues(values).getCode() != IParserEditStatus.EDITABLE) {" + NL + "\t\t\treturn UnexecutableCommand.INSTANCE;" + NL + "\t\t}" + NL + "\t\treturn getParseCommand(adapter, values);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected abstract ICommand getParseCommand(IAdaptable adapter, Object[] values);" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic IContentAssistProcessor getCompletionProcessor(IAdaptable element) {" + NL + "\t\treturn null;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected ICommand getModificationCommand(EObject element, EStructuralFeature feature, Object value) {" + NL + "\t\tvalue = getValidNewValue(feature, value);" + NL + "\t\tif (value instanceof InvalidValue) {" + NL + "\t\t\treturn UnexecutableCommand.INSTANCE;" + NL + "\t\t}" + NL + "\t\tSetRequest request = new SetRequest(element, feature, value);" + NL + "\t\treturn new SetValueCommand(request);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected Object getValidValue(EStructuralFeature feature, Object value) {" + NL + "\t\tEClassifier type = feature.getEType();" + NL + "\t\tif (type instanceof EDataType) {" + NL + "\t\t\tClass iClass = type.getInstanceClass();" + NL + "\t\t\tif (String.class.equals(iClass)) {" + NL + "\t\t\t\tif (value == null) {" + NL + "\t\t\t\t\tvalue = \"\";" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\treturn value;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected Object getValidNewValue(EStructuralFeature feature, Object value) {" + NL + "\t\tEClassifier type = feature.getEType();" + NL + "\t\tif (type instanceof EDataType) {" + NL + "\t\t\tClass iClass = type.getInstanceClass();" + NL + "\t\t\tif (Boolean.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Boolean) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof String) {" + NL + "\t\t\t\t\tvalue = Boolean.valueOf((String) value);" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Boolean is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Character.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Character) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof String) {" + NL + "\t\t\t\t\tString s = (String) value;" + NL + "\t\t\t\t\tif (s.length() == 0) {" + NL + "\t\t\t\t\t\tvalue = null;" + NL + "\t\t\t\t\t} else {" + NL + "\t\t\t\t\t\tvalue = new Character(s.charAt(0));" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Character is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Byte.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Byte) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Byte(((Number) value).byteValue());" + NL + "\t\t\t\t} else if (value instanceof String) {" + NL + "\t\t\t\t\tString s = (String) value;" + NL + "\t\t\t\t\tif (s.length() == 0) {" + NL + "\t\t\t\t\t\tvalue = null;" + NL + "\t\t\t\t\t} else {" + NL + "\t\t\t\t\t\ttry {" + NL + "\t\t\t\t\t\t\tvalue = Byte.valueOf(s);" + NL + "\t\t\t\t\t\t} catch (NumberFormatException nfe) {" + NL + "\t\t\t\t\t\t\tvalue = new InvalidValue(\"String value does not convert to Byte value\");" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Byte is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Short.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Short) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Short(((Number) value).shortValue());" + NL + "\t\t\t\t} else if (value instanceof String) {" + NL + "\t\t\t\t\tString s = (String) value;" + NL + "\t\t\t\t\tif (s.length() == 0) {" + NL + "\t\t\t\t\t\tvalue = null;" + NL + "\t\t\t\t\t} else {" + NL + "\t\t\t\t\t\ttry {" + NL + "\t\t\t\t\t\t\tvalue = Short.valueOf(s);" + NL + "\t\t\t\t\t\t} catch (NumberFormatException nfe) {" + NL + "\t\t\t\t\t\t\tvalue = new InvalidValue(\"String value does not convert to Short value\");" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Short is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Integer.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Integer) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Integer(((Number) value).intValue());" + NL + "\t\t\t\t} else if (value instanceof String) {" + NL + "\t\t\t\t\tString s = (String) value;" + NL + "\t\t\t\t\tif (s.length() == 0) {" + NL + "\t\t\t\t\t\tvalue = null;" + NL + "\t\t\t\t\t} else {" + NL + "\t\t\t\t\t\ttry {" + NL + "\t\t\t\t\t\t\tvalue = Integer.valueOf(s);" + NL + "\t\t\t\t\t\t} catch (NumberFormatException nfe) {" + NL + "\t\t\t\t\t\t\tvalue = new InvalidValue(\"String value does not convert to Integer value\");" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Integer is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Long.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Long) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Long(((Number) value).longValue());" + NL + "\t\t\t\t} else if (value instanceof String) {" + NL + "\t\t\t\t\tString s = (String) value;" + NL + "\t\t\t\t\tif (s.length() == 0) {" + NL + "\t\t\t\t\t\tvalue = null;" + NL + "\t\t\t\t\t} else {" + NL + "\t\t\t\t\t\ttry {" + NL + "\t\t\t\t\t\t\tvalue = Long.valueOf(s);" + NL + "\t\t\t\t\t\t} catch (NumberFormatException nfe) {" + NL + "\t\t\t\t\t\t\tvalue = new InvalidValue(\"String value does not convert to Long value\");" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Long is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Float.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Float) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Float(((Number) value).floatValue());" + NL + "\t\t\t\t} else if (value instanceof String) {" + NL + "\t\t\t\t\tString s = (String) value;" + NL + "\t\t\t\t\tif (s.length() == 0) {" + NL + "\t\t\t\t\t\tvalue = null;" + NL + "\t\t\t\t\t} else {" + NL + "\t\t\t\t\t\ttry {" + NL + "\t\t\t\t\t\t\tvalue = Float.valueOf(s);" + NL + "\t\t\t\t\t\t} catch (NumberFormatException nfe) {" + NL + "\t\t\t\t\t\t\tvalue = new InvalidValue(\"String value does not convert to Float value\");" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Float is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (Double.TYPE.equals(iClass)) {" + NL + "\t\t\t\tif (value instanceof Double) {" + NL + "\t\t\t\t\t// ok" + NL + "\t\t\t\t} else if (value instanceof Number) {" + NL + "\t\t\t\t\tvalue = new Double(((Number) value).doubleValue());" + NL + "\t\t\t\t} else if (value instanceof String) {" + NL + "\t\t\t\t\tString s = (String) value;" + NL + "\t\t\t\t\tif (s.length() == 0) {" + NL + "\t\t\t\t\t\tvalue = null;" + NL + "\t\t\t\t\t} else {" + NL + "\t\t\t\t\t\ttry {" + NL + "\t\t\t\t\t\t\tvalue = Double.valueOf(s);" + NL + "\t\t\t\t\t\t} catch (NumberFormatException nfe) {" + NL + "\t\t\t\t\t\t\tvalue = new InvalidValue(\"String value does not convert to Double value\");" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type Double is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t} else if (type instanceof EEnum) {" + NL + "\t\t\t\tif (value instanceof String) {" + NL + "\t\t\t\t\tEEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);" + NL + "\t\t\t\t\tif (literal == null) {" + NL + "\t\t\t\t\t\tvalue = new InvalidValue(\"Unknown literal: \" + value);" + NL + "\t\t\t\t\t} else {" + NL + "\t\t\t\t\t\tvalue = literal.getInstance();" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t} else {" + NL + "\t\t\t\t\tvalue = new InvalidValue(\"Value of type String is expected\");" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\treturn value;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected class InvalidValue {" + NL + "" + NL + "\t\tprivate String description;" + NL + "" + NL + "\t\tpublic InvalidValue(String description) {" + NL + "\t\t\tthis.description = description;" + NL + "\t\t}" + NL + "" + NL + "\t\tpublic String toString() {" + NL + "\t\t\treturn description;" + NL + "\t\t}" + NL + "\t}" + NL + "}";
protected final String TEXT_7 = NL;
public String generate(Object argument)
diff --git a/plugins/org.eclipse.gmf.codegen/templates/providers/AbstractParser.javajet b/plugins/org.eclipse.gmf.codegen/templates/providers/AbstractParser.javajet
index 6fb5738f7..de136df6e 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/providers/AbstractParser.javajet
+++ b/plugins/org.eclipse.gmf.codegen/templates/providers/AbstractParser.javajet
@@ -215,6 +215,13 @@ public abstract class <%=genDiagram.getAbstractParserClassName()%> implements IP
} else if (Character.TYPE.equals(iClass)) {
if (value instanceof Character) {
// ok
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ value = new Character(s.charAt(0));
+ }
} else {
value = new InvalidValue("Value of type Character is expected");
}
@@ -223,6 +230,17 @@ public abstract class <%=genDiagram.getAbstractParserClassName()%> implements IP
// ok
} else if (value instanceof Number) {
value = new Byte(((Number) value).byteValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Byte.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Byte value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Byte is expected");
}
@@ -231,6 +249,17 @@ public abstract class <%=genDiagram.getAbstractParserClassName()%> implements IP
// ok
} else if (value instanceof Number) {
value = new Short(((Number) value).shortValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Short.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Short value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Short is expected");
}
@@ -239,6 +268,17 @@ public abstract class <%=genDiagram.getAbstractParserClassName()%> implements IP
// ok
} else if (value instanceof Number) {
value = new Integer(((Number) value).intValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Integer.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Integer value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Integer is expected");
}
@@ -247,6 +287,17 @@ public abstract class <%=genDiagram.getAbstractParserClassName()%> implements IP
// ok
} else if (value instanceof Number) {
value = new Long(((Number) value).longValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Long.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Long value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Long is expected");
}
@@ -255,6 +306,17 @@ public abstract class <%=genDiagram.getAbstractParserClassName()%> implements IP
// ok
} else if (value instanceof Number) {
value = new Float(((Number) value).floatValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Float.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Float value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Float is expected");
}
@@ -263,6 +325,17 @@ public abstract class <%=genDiagram.getAbstractParserClassName()%> implements IP
// ok
} else if (value instanceof Number) {
value = new Double(((Number) value).doubleValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Double.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue("String value does not convert to Double value");
+ }
+ }
} else {
value = new InvalidValue("Value of type Double is expected");
}

Back to the top