Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorashatalin2008-12-29 07:41:38 -0500
committerashatalin2008-12-29 07:41:38 -0500
commitfc1dfb3b462e159eec1b6031bb41ab79c762474b (patch)
tree66acb7873f68640147106dcd919a5041ecbc918b /plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers
parent7f3bb1960b122d5d9c4edae8dc1c330032c9cf60 (diff)
downloadorg.eclipse.gmf-tooling-fc1dfb3b462e159eec1b6031bb41ab79c762474b.tar.gz
org.eclipse.gmf-tooling-fc1dfb3b462e159eec1b6031bb41ab79c762474b.tar.xz
org.eclipse.gmf-tooling-fc1dfb3b462e159eec1b6031bb41ab79c762474b.zip
QVTO-based xpand implementation was merged to HEAD
Diffstat (limited to 'plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers')
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/AbstractParser.xpt396
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/ParserProvider.xpt223
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/i18n.qvto21
3 files changed, 640 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/AbstractParser.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/AbstractParser.xpt
new file mode 100644
index 000000000..78202abc1
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/AbstractParser.xpt
@@ -0,0 +1,396 @@
+/*
+ * Copyright (c) 2007, 2008 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:
+ * Dmitry Stadnik (Borland) - initial API and implementation
+ * Artem Tikhomirov (Borland) - [235113] alternative parser access
+ * [244419] custom parsers
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+
+«EXTENSION impl::parsers::i18n»
+
+«DEFINE className FOR gmfgen::GenParsers»«defaultAbstractParserClassName()»«ENDDEFINE»
+«DEFINE qualifiedClassName FOR gmfgen::GenParsers»«implPackageName».«EXPAND className»«ENDDEFINE»
+
+«DEFINE Main FOR gmfgen::GenParsers-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «implPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public abstract class «EXPAND className» implements org.eclipse.gmf.runtime.common.ui.services.parser.IParser {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected final org.eclipse.emf.ecore.EAttribute[] features;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected final org.eclipse.emf.ecore.EAttribute[] editableFeatures;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private String viewPattern;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private String editorPattern;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private String editPattern;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public «EXPAND className»(org.eclipse.emf.ecore.EAttribute[] features) {
+ if (features == null || java.util.Arrays.asList(features).contains(null)) {
+ throw new IllegalArgumentException();
+ }
+ this.editableFeatures = this.features = features;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public «EXPAND className»(org.eclipse.emf.ecore.EAttribute[] features,
+ org.eclipse.emf.ecore.EAttribute[] editableFeatures) {
+ if (features == null || java.util.Arrays.asList(features).contains(null)) {
+ throw new IllegalArgumentException();
+ }
+ this.features = features;
+ if (editableFeatures == null || java.util.Arrays.asList(editableFeatures).contains(null)) {
+ throw new IllegalArgumentException();
+ }
+ this.editableFeatures = editableFeatures;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public String getViewPattern() {
+ return viewPattern;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void setViewPattern(String viewPattern) {
+ this.viewPattern = viewPattern;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public String getEditorPattern() {
+ return editorPattern;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void setEditorPattern(String editorPattern) {
+ this.editorPattern = editorPattern;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public String getEditPattern() {
+ return editPattern;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void setEditPattern(String editPattern) {
+ this.editPattern = editPattern;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public boolean isAffectingEvent(Object event, int flags) {
+ if (event instanceof org.eclipse.emf.common.notify.Notification) {
+ return isAffectingFeature(((org.eclipse.emf.common.notify.Notification) event).getFeature());
+ }
+ return false;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected boolean isAffectingFeature(Object feature) {
+ for (int i = 0; i < features.length; i++) {
+ if (features[i] == feature) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.jface.text.contentassist.IContentAssistProcessor getCompletionProcessor(
+ org.eclipse.core.runtime.IAdaptable element) {
+ return null;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected Object[] getValues(org.eclipse.emf.ecore.EObject element) {
+ Object[] values = new Object[features.length];
+ for (int i = 0; i < features.length; i++) {
+ values[i] = getValue(element, features[i]);
+ }
+ return values;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected Object[] getEditableValues(org.eclipse.emf.ecore.EObject element) {
+ Object[] values = new Object[editableFeatures.length];
+ for (int i = 0; i < editableFeatures.length; i++) {
+ values[i] = getValue(element, editableFeatures[i]);
+ }
+ return values;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected Object getValue(org.eclipse.emf.ecore.EObject element, org.eclipse.emf.ecore.EAttribute feature) {
+ Object value = element.eGet(feature);
+ Class iClass = feature.getEAttributeType().getInstanceClass();
+ if (String.class.equals(iClass)) {
+ if (value == null) {
+ value = ""; «EXPAND xpt::Common::nonNLS»
+ }
+ }
+ return value;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected org.eclipse.gmf.runtime.common.core.command.ICommand getParseCommand(
+ org.eclipse.core.runtime.IAdaptable adapter, Object[] values, int flags) {
+ if (values == null || validateNewValues(values).getCode() !=
+ org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus.EDITABLE) {
+ return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
+ }
+ org.eclipse.emf.ecore.EObject element =
+ (org.eclipse.emf.ecore.EObject) adapter.getAdapter(org.eclipse.emf.ecore.EObject.class);
+ org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain =
+ org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(element);
+ if (editingDomain == null) {
+ return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
+ }
+ org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand command =
+ new org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand(
+ editingDomain, "Set Values"); «EXPAND xpt::Common::nonNLS»
+ for (int i = 0; i < values.length; i++) {
+ command.compose(getModificationCommand(element, editableFeatures[i], values[i]));
+ }
+ return command;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected org.eclipse.gmf.runtime.common.core.command.ICommand getModificationCommand(
+ org.eclipse.emf.ecore.EObject element, org.eclipse.emf.ecore.EAttribute feature, Object value) {
+ value = getValidNewValue(feature, value);
+ if (value instanceof InvalidValue) {
+ return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
+ }
+ org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest request =
+ new org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest(element, feature, value);
+ return new org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand(request);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus validateNewValues(Object[] values) {
+ if (values.length != editableFeatures.length) {
+ return org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus.UNEDITABLE_STATUS;
+ }
+ for (int i = 0; i < values.length; i++) {
+ Object value = getValidNewValue(editableFeatures[i], values[i]);
+ if (value instanceof InvalidValue) {
+ return new org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus(
+ «editorGen.plugin.getActivatorQualifiedClassName()».ID,
+ org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus.UNEDITABLE,
+ value.toString());
+ }
+ }
+ return org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus.EDITABLE_STATUS;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected Object getValidNewValue(org.eclipse.emf.ecore.EAttribute feature, Object value) {
+ org.eclipse.emf.ecore.EClassifier type = feature.getEType();
+ if (type instanceof org.eclipse.emf.ecore.EDataType) {
+ Class iClass = type.getInstanceClass();
+ if (Boolean.TYPE.equals(iClass)) {
+ if (value instanceof Boolean) {
+ // ok
+ } else if (value instanceof String) {
+ value = Boolean.valueOf((String) value);
+ } else {
+ value = new InvalidValue(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnexpectedValueTypeMessage()) FOR editorGen», iClass.getName()));
+ }
+ } 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(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnexpectedValueTypeMessage()) FOR editorGen», iClass.getName()));
+ }
+ } else if (Byte.TYPE.equals(iClass)) {
+ if (value instanceof Byte) {
+ // 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(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserWrongStringConversionMessage()) FOR editorGen», iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnexpectedValueTypeMessage()) FOR editorGen», iClass.getName()));
+ }
+ } else if (Short.TYPE.equals(iClass)) {
+ if (value instanceof Short) {
+ // 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(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserWrongStringConversionMessage()) FOR editorGen», iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnexpectedValueTypeMessage()) FOR editorGen», iClass.getName()));
+ }
+ } else if (Integer.TYPE.equals(iClass)) {
+ if (value instanceof Integer) {
+ // 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(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserWrongStringConversionMessage()) FOR editorGen», iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnexpectedValueTypeMessage()) FOR editorGen», iClass.getName()));
+ }
+ } else if (Long.TYPE.equals(iClass)) {
+ if (value instanceof Long) {
+ // 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(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserWrongStringConversionMessage()) FOR editorGen», iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnexpectedValueTypeMessage()) FOR editorGen», iClass.getName()));
+ }
+ } else if (Float.TYPE.equals(iClass)) {
+ if (value instanceof Float) {
+ // 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(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserWrongStringConversionMessage()) FOR editorGen», iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnexpectedValueTypeMessage()) FOR editorGen», iClass.getName()));
+ }
+ } else if (Double.TYPE.equals(iClass)) {
+ if (value instanceof Double) {
+ // 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(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserWrongStringConversionMessage()) FOR editorGen», iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnexpectedValueTypeMessage()) FOR editorGen», iClass.getName()));
+ }
+ } else if (type instanceof org.eclipse.emf.ecore.EEnum) {
+ if (value instanceof String) {
+ org.eclipse.emf.ecore.EEnumLiteral literal =
+ ((org.eclipse.emf.ecore.EEnum) type).getEEnumLiteralByLiteral((String) value);
+ if (literal == null) {
+ value = new InvalidValue(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnknownLiteralMessage()) FOR editorGen», value));
+ } else {
+ value = literal.getInstance();
+ }
+ } else {
+ value = new InvalidValue(org.eclipse.osgi.util.NLS.bind(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForAbstractParserUnexpectedValueTypeMessage()) FOR editorGen», String.class.getName()));
+ }
+ }
+ }
+ return value;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected class InvalidValue {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private String description;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public InvalidValue(String description) {
+ this.description = description;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public String toString() {
+ return description;
+ }
+ }
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenParsers»«ENDDEFINE»
+
+«DEFINE i18nValues FOR gmfgen::GenParsers-»
+«IF (implementations)[gmfgen::PredefinedParser]->size() > 0-»
+«EXPAND xpt::Externalizer::messageEntry(i18nKeyForAbstractParserUnexpectedValueTypeMessage(), 'Value of type {0} is expected')-»
+«EXPAND xpt::Externalizer::messageEntry(i18nKeyForAbstractParserWrongStringConversionMessage(), 'String value does not convert to {0} value')-»
+«EXPAND xpt::Externalizer::messageEntry(i18nKeyForAbstractParserUnknownLiteralMessage(), 'Unknown literal: {0}')-»
+«ENDIF-»
+«ENDDEFINE»
+
+«DEFINE i18nAccessors FOR gmfgen::GenParsers-»
+«IF (implementations)[gmfgen::PredefinedParser]->size() > 0-»
+«EXPAND xpt::Externalizer::accessorField(i18nKeyForAbstractParserUnexpectedValueTypeMessage())-»
+«EXPAND xpt::Externalizer::accessorField(i18nKeyForAbstractParserWrongStringConversionMessage())-»
+«EXPAND xpt::Externalizer::accessorField(i18nKeyForAbstractParserUnknownLiteralMessage())-»
+«ENDIF-»
+«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/ParserProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/ParserProvider.xpt
new file mode 100644
index 000000000..ef99f5736
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/ParserProvider.xpt
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2007, 2008 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:
+ * Dmitry Stadnik (Borland) - initial API and implementation
+ * Artem Tikhomirov (Borland) - [235113] alternative parser access
+ * [244419] custom parsers
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+
+«EXTENSION xpt::providers::ParserUtils»
+
+«DEFINE accessorMethod_delegate2providers FOR gmfgen::GenParsers-»
+ «EXPAND xpt::Common::generatedMemberComment('Utility method that consults ParserService')»
+ public static org.eclipse.gmf.runtime.common.ui.services.parser.IParser getParser(org.eclipse.gmf.runtime.emf.type.core.IElementType type, org.eclipse.emf.ecore.EObject object, String parserHint) {
+ return org.eclipse.gmf.runtime.common.ui.services.parser.ParserService.getInstance().getParser(new HintAdapter(type, object, parserHint));
+ }
+«ENDDEFINE»
+
+// invokes method generated with accessorMethod_delegate2providers template
+«DEFINE accessorCall_delegate2providers(elementTypeHolder : gmfgen::GenCommonBase, labelModelFacet : gmfgen::LabelModelFacet, parsedElement : String) FOR gmfgen::GenCommonBase-»
+«getDiagram().editorGen.labelParsers.getQualifiedClassName()».getParser(«EXPAND xpt::providers::ElementTypes::accessElementType FOR elementTypeHolder», «parsedElement», «IF labelModelFacet = null»«EXPAND xpt::editor::VisualIDRegistry::typeMethodCall»«ELSE»«EXPAND _parserHint(labelModelFacet, self) FOR labelModelFacet.parser»«ENDIF»)«-»
+«ENDDEFINE»
+
+«DEFINE _parserHint(labelFacet : gmfgen::LabelModelFacet, hintHolder : gmfgen::GenCommonBase) FOR gmfgen::GenParserImplementation»«EXPAND xpt::editor::VisualIDRegistry::typeMethodCall FOR hintHolder»«ENDDEFINE»
+// ExternalParser may override hint
+«DEFINE _parserHint(labelFacet : gmfgen::LabelModelFacet, hintHolder : gmfgen::GenCommonBase) FOR gmfgen::ExternalParser-»
+«IF hint = null-»
+«EXPAND xpt::editor::VisualIDRegistry::typeMethodCall FOR hintHolder-»
+«ELSE»«hint»«ENDIF-»
+«ENDDEFINE»
+«DEFINE _parserHint(labelFacet : gmfgen::DesignLabelModelFacet, hintHolder : gmfgen::GenCommonBase) FOR gmfgen::ExternalParser-»
+«IF hint = null»org.eclipse.gmf.runtime.common.ui.services.parser.CommonParserHint.DESCRIPTION«ELSE»«hint»«ENDIF-»
+«ENDDEFINE»
+«DEFINE _parserHint(labelFacet : gmfgen::DesignLabelModelFacet, hintHolder : gmfgen::GenCommonBase) FOR gmfgen::GenParserImplementation»org.eclipse.gmf.runtime.common.ui.services.parser.CommonParserHint.DESCRIPTION«ENDDEFINE»
+
+// FIXME refactor static field to an instance registered within Activator
+«REM»Complementary method to accessorMethod_delegate2providers, although for direct access need an instance of this class«ENDREM»
+«DEFINE accessorMethod_direct FOR gmfgen::GenParsers-»
+ private static «getQualifiedClassName()» ourInstance;
+
+ public static «getQualifiedClassName()» get() {
+ if (ourInstance == null) {
+ ourInstance = new «getQualifiedClassName()»();
+ }
+ return ourInstance;
+ }
+«ENDDEFINE»
+
+// XXX consider adding #getDescriptionParser() method to control that kind of parser access?
+// XXX do I really need GenCommonBase elementTypeHolder, why not use elementType reference directly?
+«DEFINE accessorCall_direct(elementTypeHolder : gmfgen::GenCommonBase, labelModelFacet : gmfgen::LabelModelFacet, parsedElement : String) FOR gmfgen::GenCommonBase-»
+«IF labelModelFacet = null or (Sequence { labelModelFacet.parser })[gmfgen::ExternalParser]->size() = 1-»
+org.eclipse.gmf.runtime.common.ui.services.parser.ParserService.getInstance().getParser(new org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter(/*«EXPAND xpt::providers::ElementTypes::accessElementType FOR elementTypeHolder», */«parsedElement», «IF labelModelFacet = null»«EXPAND xpt::editor::VisualIDRegistry::typeMethodCall»«ELSE»«EXPAND _parserHint(labelModelFacet, self) FOR labelModelFacet.parser»«ENDIF»))«-»
+«ELSE-»
+«getDiagram().editorGen.labelParsers.getQualifiedClassName()».get().«parserAccessorName(self)»()«-»
+«ENDIF-»
+«ENDDEFINE»
+
+«DEFINE provider_getParserMethod FOR gmfgen::GenParsers-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.gmf.runtime.common.ui.services.parser.IParser getParser(
+ org.eclipse.core.runtime.IAdaptable hint) {
+ String vid = (String) hint.getAdapter(String.class);
+ if (vid != null) {
+ return getParser(«EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR editorGen.diagram»(vid));
+ }
+ org.eclipse.gmf.runtime.notation.View view =
+ (org.eclipse.gmf.runtime.notation.View) hint.getAdapter(org.eclipse.gmf.runtime.notation.View.class);
+ if (view != null) {
+ return getParser(«EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR editorGen.diagram»(view));
+ }
+ return null;
+ }
+«ENDDEFINE»
+
+«DEFINE provider_providesMethod FOR gmfgen::GenParsers-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public boolean provides(org.eclipse.gmf.runtime.common.core.service.IOperation operation) {
+ if (operation instanceof org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation) {
+ org.eclipse.core.runtime.IAdaptable hint =
+ ((org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation) operation).getHint();
+ if («editorGen.diagram.getElementTypesQualifiedClassName()».getElement(hint) == null) {
+ return false;
+ }
+ return getParser(hint) != null;
+ }
+ return false;
+ }
+«ENDDEFINE»
+
+«DEFINE HintAdapterClass FOR gmfgen::GenParsers-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static class HintAdapter extends org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private final org.eclipse.gmf.runtime.emf.type.core.IElementType elementType;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public HintAdapter(org.eclipse.gmf.runtime.emf.type.core.IElementType type,
+ org.eclipse.emf.ecore.EObject object, String parserHint) {
+ super(object, parserHint);
+ «EXPAND xpt::Common::_assert('type != null')-»
+ elementType = type;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public Object getAdapter(Class adapter) {
+ if (org.eclipse.gmf.runtime.emf.type.core.IElementType.class.equals(adapter)) {
+ return elementType;
+ }
+ return super.getAdapter(adapter);
+ }
+ }
+«ENDDEFINE»
+
+«DEFINE getParserByVisualIdMethod FOR gmfgen::GenParsers-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected org.eclipse.gmf.runtime.common.ui.services.parser.IParser getParser(int visualID) {
+ switch (visualID) {
+ «EXPAND _getParsers FOREACH editorGen.diagram.topLevelNodes-»
+ «EXPAND _getParsers FOREACH editorGen.diagram.childNodes-»
+ «EXPAND _getParsers FOREACH editorGen.diagram.links-»
+ }
+ return null;
+ }
+«ENDDEFINE»
+
+«DEFINE _getParsers FOR gmfgen::GenNode»«EXPAND _getParser FOREACH labels»«ENDDEFINE»
+«DEFINE _getParsers FOR gmfgen::GenLink»«EXPAND _getParser FOREACH labels»«ENDDEFINE»
+«DEFINE _getParsers FOR gmfgen::GenChildLabelNode»«EXPAND _getParser(self) FOR labelModelFacet»«ENDDEFINE»
+«DEFINE _getParser FOR gmfgen::GenLabel»«EXPAND _getParser(self) FOR modelFacet»«ENDDEFINE»
+
+«DEFINE _getParser(element : gmfgen::GenCommonBase) FOR gmfgen::LabelModelFacet»«EXPAND _getParser(self, element) FOR parser»«ENDDEFINE»
+
+«DEFINE _getParser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::GenParserImplementation»«ERROR 'Abstract template for ' + self.repr()»«ENDDEFINE»
+«DEFINE _getParser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::ExternalParser»«REM»NOTHING TO DO«ENDREM»«ENDDEFINE»
+
+«DEFINE _getParser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::PredefinedParser-»
+ «EXPAND xpt::Common::caseVisualID FOR element» return «parserAccessorName(element)»();
+«ENDDEFINE»
+
+«DEFINE _getParser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::CustomParser-»
+ «EXPAND xpt::Common::caseVisualID FOR element» return «parserAccessorName(element)»();
+«ENDDEFINE»
+
+
+«DEFINE parsers FOR gmfgen::GenNode»«EXPAND _parser FOREACH labels»«ENDDEFINE»
+«DEFINE parsers FOR gmfgen::GenLink»«EXPAND _parser FOREACH labels»«ENDDEFINE»
+«DEFINE parsers FOR gmfgen::GenChildLabelNode»«EXPAND _parser(self) FOR labelModelFacet»«ENDDEFINE»
+
+«DEFINE _parser FOR gmfgen::GenLabel»«EXPAND _parser(self) FOR modelFacet»«ENDDEFINE»
+«DEFINE _parser(element : gmfgen::GenCommonBase) FOR gmfgen::LabelModelFacet»«EXPAND _parser(self, element) FOR parser»«ENDDEFINE»
+
+«DEFINE _parser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::GenParserImplementation»«ERROR 'Abstract template for ' + self.repr()»«ENDDEFINE»
+
+«DEFINE _parser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::CustomParser»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «qualifiedName» «parserFieldName(element)»;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ «IF holder.extensibleViaService»private«ELSE»public«ENDIF» org.eclipse.gmf.runtime.common.ui.services.parser.IParser «parserAccessorName(element)»() {
+ if («parserFieldName(element)» == null) {
+ «parserFieldName(element)» = new «qualifiedName»();
+ }
+ return «parserFieldName(element)»;
+ }
+«ENDDEFINE»
+
+«DEFINE _parser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::ExternalParser-»
+«REM»NO-OP«ENDREM-»
+«ENDDEFINE»
+
+«DEFINE _parser(modelFacet : gmfgen::FeatureLabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::PredefinedParser»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.gmf.runtime.common.ui.services.parser.IParser «parserFieldName(element)»;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ «IF holder.extensibleViaService»private«ELSE»public«ENDIF» org.eclipse.gmf.runtime.common.ui.services.parser.IParser «parserAccessorName(element)»() {
+ if («parserFieldName(element)» == null) {
+ org.eclipse.emf.ecore.EAttribute[] features = new org.eclipse.emf.ecore.EAttribute[] {
+ «EXPAND MetaModel::MetaFeature FOREACH modelFacet.metaFeatures SEPARATOR ', ' »
+ };
+ «IF modelFacet.editableMetaFeatures->size() > 0-»
+ org.eclipse.emf.ecore.EAttribute[] editableFeatures = new org.eclipse.emf.ecore.EAttribute[] {
+ «EXPAND MetaModel::MetaFeature FOREACH modelFacet.editableMetaFeatures SEPARATOR ', '»
+ };
+ «ENDIF-»
+ «getQualifiedClassName()» parser = new «getQualifiedClassName()»(features«IF modelFacet.editableMetaFeatures->size() > 0», editableFeatures«ENDIF»);
+ «EXPAND _setPatterns(viewMethod, editMethod, 'parser') FOR modelFacet-»
+ «parserFieldName(element)» = parser;
+ }
+ return «parserFieldName(element)»;
+ }
+«ENDDEFINE»
+
+«DEFINE _setPatterns(viewMethod : gmfgen::LabelTextAccessMethod, editMethod : gmfgen::LabelTextAccessMethod, parserVar : String) FOR gmfgen::FeatureLabelModelFacet-»
+«IF viewMethod <> gmfgen::LabelTextAccessMethod::NATIVE-»
+ «IF isPatternSpecified(viewPattern)-»
+ «parserVar».setViewPattern("«viewPattern»");«EXPAND xpt::Common::nonNLS(1)»
+ «ENDIF-»
+ «IF isPatternSpecified(editorPattern)-»
+ «parserVar».setEditorPattern("«editorPattern»");«EXPAND xpt::Common::nonNLS(1)»
+ «ELSEIF isPatternSpecified(viewPattern)-»
+ «parserVar».setEditorPattern("«viewPattern»");«EXPAND xpt::Common::nonNLS(1)»
+ «ENDIF-»
+«ENDIF-»
+«IF editMethod <> gmfgen::LabelTextAccessMethod::NATIVE-»
+ «IF isPatternSpecified(editPattern)-»
+ «parserVar».setEditPattern("«editPattern»");«EXPAND xpt::Common::nonNLS(1)»
+ «ELSEIF isPatternSpecified(viewPattern)-»
+ «parserVar».setEditPattern("«viewPattern»");«EXPAND xpt::Common::nonNLS(1)»
+ «ENDIF-»
+«ENDIF-»
+«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/i18n.qvto b/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/i18n.qvto
new file mode 100644
index 000000000..028d254d8
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/parsers/i18n.qvto
@@ -0,0 +1,21 @@
+library i18n;
+
+helper defaultAbstractParserClassName() : String {
+ return 'AbstractParser'
+}
+
+helper i18nKeyForAbstractParserUnexpectedValueTypeMessage() : String {
+ return defaultAbstractParserClassName() + '.UnexpectedValueType'
+}
+
+helper i18nKeyForAbstractParserWrongStringConversionMessage() : String {
+ return defaultAbstractParserClassName() + '.WrongStringConversion'
+}
+
+helper i18nKeyForAbstractParserUnknownLiteralMessage() : String {
+ return defaultAbstractParserClassName() + '.UnknownLiteral'
+}
+
+helper i18nKeyForMessageFormatParserInvalidInputError() : String {
+ return 'MessageFormatParser.InvalidInputError'
+}

Back to the top