[330260] [content model] Model Group Definition's choice's optional element is created
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java
index 60341ad..290f6f5 100644
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java
@@ -428,7 +428,19 @@
}
if (cmNode != null) {
- visitCMNode(cmNode);
+ // Bug 330260
+ // Problem - Add child element also adds optional grand-child elements
+ // This assumes 'e' is a model group choice, case 1. However 'e' could be a model group definition, case 2, where the
+ // first child is a model group. In the first case (choice), the first child is an
+ // element. Upon visiting the element (visitCMElementDeclaration), the minOccurs of the
+ // choice is ALSO considered. If its minOccurs is 0, then the first element is not added as a child.
+ // However, in the second case (model group definition), the first child is a choice, but the multiplicity is [1,1],
+ // meaning, it is required. So the first element is then added as child, even though
+ // the model group definition reference is optional. (minOccurs is not checked in this method, visitCMGroup)
+ // Visit the node only if it is not a GROUP (model group). If it is an element, then visit it.
+ if (!(cmNode.getNodeType() == CMNode.GROUP && min > 0)) {
+ visitCMNode(cmNode);
+ }
}
}
else if (e.getOperator() == CMGroup.ALL // ALL