[346952] - Can't generate the diagrams with RC2 -
UnlimitedNatural may not be casted to Integer, use explicit comparison with *
+ workarounds around #347960
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/OclMigrationProblems.qvto b/plugins/org.eclipse.gmf.codegen/templates/xpt/OclMigrationProblems.qvto
new file mode 100644
index 0000000..10ec226
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/OclMigrationProblems.qvto
@@ -0,0 +1,28 @@
+modeltype gmfgen uses "http://www.eclipse.org/gmf/2009/GenModel";
+modeltype ecore uses "http://www.eclipse.org/emf/2002/Ecore";
+
+library OclMigrationProblems;
+
+helper isUnbounded(typedElement : ecore::ETypedElement) : Boolean {
+	return typedElement.upperBound = *
+}
+
+helper isSingleValued(typedElement : ecore::ETypedElement) : Boolean {
+	return typedElement.upperBound = 1
+}
+
+helper firstOrNull(oSet : OrderedSet(gmfgen::DefaultSizeAttributes)) : gmfgen::DefaultSizeAttributes {
+	return (if oSet->isEmpty() then null else oSet->first() endif)
+} 
+
+helper firstOrNull(oSet : OrderedSet(gmfgen::ResizeConstraints)) : gmfgen::ResizeConstraints {
+	return (if oSet->isEmpty() then null else oSet->first() endif)
+} 
+
+helper firstOrNull(oSet : OrderedSet(gmfgen::LabelOffsetAttributes)) : gmfgen::LabelOffsetAttributes {
+	return (if oSet->isEmpty() then null else oSet->first() endif)
+} 
+
+helper undefinedAsFalse(param : Boolean) : Boolean {
+	return if param.oclIsUndefined() then false else param endif 
+}
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/ViewmapAttributesUtils.qvto b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/ViewmapAttributesUtils.qvto
index 1168e01..484efb8 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/ViewmapAttributesUtils.qvto
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/ViewmapAttributesUtils.qvto
@@ -9,6 +9,9 @@
  * Contributors:
  *    Dmitry Stadnik (Borland) - initial API and implementation
  */
+ 
+import xpt.OclMigrationProblems;
+
 modeltype gmfgen uses "http://www.eclipse.org/gmf/2009/GenModel";
 
 library ViewmapAttributesUtils;
@@ -34,11 +37,11 @@
 }
 
 helper getResizeConstraints(viewmap : gmfgen::Viewmap) : gmfgen::ResizeConstraints {
-	return (if null = viewmap then null else viewmap.attributes[gmfgen::ResizeConstraints]->first() endif)
+	return (if null = viewmap then null else firstOrNull(viewmap.attributes[gmfgen::ResizeConstraints]) endif)
 }
 
 helper getDefaultSizeAttributes(viewmap : gmfgen::Viewmap) : gmfgen::DefaultSizeAttributes {
-	return (if null = viewmap then null else viewmap.attributes[gmfgen::DefaultSizeAttributes]->first() endif)
+	return (if null = viewmap then null else firstOrNull(viewmap.attributes[gmfgen::DefaultSizeAttributes]) endif)
 }
 
 helper defaultSizeWidth(viewmap : gmfgen::Viewmap, defaultValue : Integer) : Integer {
@@ -50,7 +53,7 @@
 }
 
 helper getLabelOffsetAttributes(viewmap : gmfgen::Viewmap) : gmfgen::LabelOffsetAttributes {
-	return (if null = viewmap then null else viewmap.attributes[gmfgen::LabelOffsetAttributes]->first() endif)
+	return (if null = viewmap then null else firstOrNull(viewmap.attributes[gmfgen::LabelOffsetAttributes]) endif)
 }
 
 helper labelOffsetX(viewmap : gmfgen::Viewmap, defaultValue : Integer) : Integer {
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateNodeCommand.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateNodeCommand.xpt
index 92c1472..252d3ce 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateNodeCommand.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateNodeCommand.xpt
@@ -12,6 +12,7 @@
 
 «IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
 «EXTENSION xpt::diagram::Utils»
+«EXTENSION xpt::OclMigrationProblems»
 
 «DEFINE CreateNodeCommand FOR gmfgen::GenNode-»
 «EXPAND xpt::Common::copyright FOR getDiagram().editorGen-»
@@ -101,22 +102,22 @@
 «ENDDEFINE»
 
 «DEFINE canExecute_Normal FOR gmfgen::TypeModelFacet-»
-«IF containmentMetaFeature.ecoreFeature.upperBound.oclAsType(Integer) > 0 or (childMetaFeature <> containmentMetaFeature and childMetaFeature.ecoreFeature.upperBound.oclAsType(Integer) > 0)-»
+«IF not isUnbounded(containmentMetaFeature.ecoreFeature) or (childMetaFeature <> containmentMetaFeature and not isUnbounded(childMetaFeature.ecoreFeature))-»
 	«EXPAND MetaModel::DeclareAndAssign('container', 'getElementToEdit()') FOR containmentMetaFeature.genClass-»
-	«IF containmentMetaFeature.ecoreFeature.upperBound.oclAsType(Integer) > 0-»
-			«IF containmentMetaFeature.ecoreFeature.upperBound.oclAsType(Integer) = 1»
+	«IF not isUnbounded(containmentMetaFeature.ecoreFeature)-»
+			«IF isSingleValued(containmentMetaFeature.ecoreFeature)»
 		if («EXPAND MetaModel::getFeatureValue('container', containmentMetaFeature.genClass) FOR containmentMetaFeature» != null) {
 			«ELSE-»
-		if («EXPAND MetaModel::getFeatureValue('container', containmentMetaFeature.genClass) FOR containmentMetaFeature».size() >= «containmentMetaFeature.ecoreFeature.upperBound.oclAsType(Integer)») {
+		if («EXPAND MetaModel::getFeatureValue('container', containmentMetaFeature.genClass) FOR containmentMetaFeature».size() >= «containmentMetaFeature.ecoreFeature.upperBound») {
 			«ENDIF-»
 			return false;
 		}
 		«ENDIF-»
-		«IF childMetaFeature <> containmentMetaFeature and childMetaFeature.ecoreFeature.upperBound.oclAsType(Integer) > 0-»
-			«IF childMetaFeature.ecoreFeature.upperBound.oclAsType(Integer) = 1-»
+		«IF childMetaFeature <> containmentMetaFeature and not isUnbounded(childMetaFeature.ecoreFeature)-»
+			«IF isSingleValued(childMetaFeature.ecoreFeature)-»
 		if («EXPAND MetaModel::getFeatureValue('container', containmentMetaFeature.genClass) FOR childMetaFeature» != null) {
 			«ELSE-»
-		if («EXPAND MetaModel::getFeatureValue('container', containmentMetaFeature.genClass) FOR childMetaFeature».size() >= «childMetaFeature.ecoreFeature.upperBound.oclAsType(Integer)») {
+		if («EXPAND MetaModel::getFeatureValue('container', containmentMetaFeature.genClass) FOR childMetaFeature».size() >= «childMetaFeature.ecoreFeature.upperBound») {
 			«ENDIF-»
 			return false;
 		}
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt
index 7525f46..c85ded6 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt
@@ -16,6 +16,7 @@
 «EXTENSION xpt::diagram::editpolicies::Utils»
 «EXTENSION xpt::diagram::Utils»
 «EXTENSION xpt::GenModelUtils»
+«EXTENSION xpt::OclMigrationProblems»
 
 «DEFINE BaseItemSemanticEditPolicy FOR gmfgen::GenDiagram-»
 «EXPAND xpt::Common::copyright FOR editorGen-»
@@ -408,11 +409,11 @@
 «DEFINE checkEMFConstraints FOR gmfgen::LinkModelFacet»«ERROR 'Unrecognized link model facet in checkEMFConstraints: ' + self.repr()»«ENDDEFINE»
 
 «DEFINE checkEMFConstraints FOR gmfgen::TypeLinkModelFacet-»
-	«LET childMetaFeature <> containmentMetaFeature and childMetaFeature.ecoreFeature.upperBound.oclAsType(Integer) > 0 AS checkChildFeatureUpperBound-»
-		«IF containmentMetaFeature.ecoreFeature.upperBound.oclAsType(Integer) > 0 or checkChildFeatureUpperBound-»
+	«LET childMetaFeature <> containmentMetaFeature and not isUnbounded(childMetaFeature.ecoreFeature) AS checkChildFeatureBounds-»
+		«IF not isUnbounded(containmentMetaFeature.ecoreFeature) or checkChildFeatureBounds-»
 if («getContainerVariable(self)» != null) {
 			«EXPAND checkEMFConstraints(self) FOR containmentMetaFeature-»
-			«IF checkChildFeatureUpperBound-»
+			«IF checkChildFeatureBounds-»
 				«EXPAND checkEMFConstraints(self) FOR childMetaFeature-»
 			«ENDIF-»
 }
@@ -421,7 +422,7 @@
 «ENDDEFINE»
 
 «DEFINE checkEMFConstraints(modelFacet : gmfgen::TypeLinkModelFacet) FOR genmodel::GenFeature-»
-«IF ecoreFeature.upperBound.oclAsType(Integer) > 0-»
+«IF not isUnbounded(ecoreFeature)-»
 if («EXPAND featureBoundComparator(getContainerVariable(modelFacet), modelFacet.getSourceType())») {
 	return false;
 }
@@ -448,14 +449,14 @@
 
 «DEFINE featureBoundsConditionClause(targetVar : String, targetType : genmodel::GenClass) FOR genmodel::GenFeature-»
 «REM»Checking upper bounds if was specified in MM«ENDREM»«-»
-«IF ecoreFeature.upperBound.oclAsType(Integer) > 0»«EXPAND featureBoundComparator(targetVar, targetType)»«ENDIF-»
-«REM»Checking uniqueness in addition if upper bounds > 1«ENDREM»«-»
-«IF ecoreFeature.upperBound.oclAsType(Integer) > 1» || «ENDIF-»
-«REM»Checking uniqueness in if upper bounds > 1 or < 0«ENDREM»«-»
-«IF ecoreFeature.upperBound.oclAsType(Integer) <> 1»«EXPAND featureUniquenessComparator(targetVar, targetType)»«ENDIF»
+«IF not isUnbounded(ecoreFeature)»«EXPAND featureBoundComparator(targetVar, targetType)»«ENDIF-»
+«REM»Checking uniqueness in addition if upper bounds != 1«ENDREM»«-»
+«IF not isSingleValued(ecoreFeature) and not isUnbounded(ecoreFeature)» || «ENDIF-»
+«REM»Checking uniqueness in if upper bounds !- 1«ENDREM»«-»
+«IF not isSingleValued(ecoreFeature)»«EXPAND featureUniquenessComparator(targetVar, targetType)»«ENDIF»
 «ENDDEFINE»
 
-«DEFINE featureBoundComparator(featureVar : String, featureVarGenClass : genmodel::GenClass) FOR genmodel::GenFeature»«EXPAND MetaModel::getFeatureValue(featureVar, featureVarGenClass)»«IF ecoreFeature.upperBound.oclAsType(Integer) = 1» != null«ELSE».size() >= «ecoreFeature.upperBound.oclAsType(Integer)»«ENDIF»«ENDDEFINE»
+«DEFINE featureBoundComparator(featureVar : String, featureVarGenClass : genmodel::GenClass) FOR genmodel::GenFeature»«EXPAND MetaModel::getFeatureValue(featureVar, featureVarGenClass)»«IF isSingleValued(ecoreFeature)» != null«ELSE».size() >= «ecoreFeature.upperBound»«ENDIF»«ENDDEFINE»
 «DEFINE featureUniquenessComparator(featureVar : String, featureVarGenClass : genmodel::GenClass) FOR genmodel::GenFeature»«EXPAND MetaModel::getFeatureValue(featureVar, featureVarGenClass) FOR self».contains(target)«ENDDEFINE»
 
 
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/editor/GenDiagram.qvto b/plugins/org.eclipse.gmf.codegen/templates/xpt/editor/GenDiagram.qvto
index 267698a..68a5d8e 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/editor/GenDiagram.qvto
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/editor/GenDiagram.qvto
@@ -35,5 +35,5 @@
 }
 
 helper isDocRootSetFeature(gf : genmodel::GenFeature, eType : ecore::EClass) : Boolean {
-	return not isListType(gf) and gf.ecoreFeature.changeable and (-2 = gf.ecoreFeature.upperBound.oclAsType(Integer) and (gf.ecoreFeature.oclAsType(ecore::EObject).eClass().name = 'EReference' and gf.ecoreFeature.eType.oclAsType(ecore::EClass).isSuperTypeOf(eType)))
+	return not isListType(gf) and gf.ecoreFeature.changeable and (-2 = gf.ecoreFeature.upperBound and (gf.ecoreFeature.oclAsType(ecore::EObject).eClass().name = 'EReference' and gf.ecoreFeature.eType.oclAsType(ecore::EClass).isSuperTypeOf(eType)))
 }
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/navigator/Utils.qvto b/plugins/org.eclipse.gmf.codegen/templates/xpt/navigator/Utils.qvto
index d8fe1f6..00d1e75 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/navigator/Utils.qvto
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/navigator/Utils.qvto
@@ -11,6 +11,7 @@
  */
 
 import gmf.CodeGenerationUtils;
+import xpt.OclMigrationProblems;
 
 modeltype gmfgen uses "http://www.eclipse.org/gmf/2009/GenModel";
 modeltype genmodel uses "http://www.eclipse.org/emf/2002/GenModel";
@@ -49,7 +50,10 @@
 }
 
 helper getChildReferencesFrom(navigator : gmfgen::GenNavigator, parent : gmfgen::GenCommonBase) : Sequence(gmfgen::GenNavigatorChildReference) {
-	return navigator.childReferences->select(r | parent.visualID = r.parent.visualID)->asSequence()
+	return if parent.oclIsUndefined() 
+		then Sequence{} 
+		else navigator.childReferences->select(r | undefinedAsFalse(parent.visualID = r.parent.visualID))->asSequence()
+	endif
 }
 
 helper getChildReferencesTo(navigator : gmfgen::GenNavigator, child : gmfgen::GenCommonBase) : Sequence(gmfgen::GenNavigatorChildReference) {