Skip to content

Commit

Permalink
Check the uniqueness of element declaration see #111
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Sep 10, 2018
1 parent 3edbcc3 commit 0b1d0cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public Collection<CMElementDeclaration> getElements() {
XSNamedMap map = model.getComponents(XSConstants.ELEMENT_DECLARATION);
for (int j = 0; j < map.getLength(); j++) {
XSElementDeclaration elementDeclaration = (XSElementDeclaration) map.item(j);
elements.add(getXSDElement(elementDeclaration));
CMElementDeclaration cmElement = getXSDElement(elementDeclaration);
// check element declaration is not already added (ex: xs:annotation)
if (!elements.contains(cmElement)) {
elements.add(cmElement);
}
}
}
return elements;
Expand All @@ -58,7 +62,7 @@ public Collection<CMElementDeclaration> getElements() {
public CMElementDeclaration findCMElement(Element node, String namespace) {
List<Element> paths = new ArrayList<>();
Element element = node;
while (element != null && (namespace == null || namespace.equals(element.getNamespaceURI()))) {
while (element != null && (namespace == null || namespace.equals(element.getNamespaceURI()))) {
paths.add(0, element);
element = element.getParent() instanceof Element ? (Element) element.getParent() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ private void collectElementsDeclaration(XSTerm term, Collection<CMElementDeclara
break;
case XSConstants.ELEMENT_DECLARATION:
XSElementDeclaration elementDeclaration = (XSElementDeclaration) term;
elements.add(document.getXSDElement(elementDeclaration));
CMElementDeclaration cmElement = document.getXSDElement(elementDeclaration);
// check element declaration is not already added (ex: xs:annotation)
if (!elements.contains(cmElement)) {
elements.add(cmElement);
}
break;
}
}
Expand Down

0 comments on commit 0b1d0cd

Please sign in to comment.