Skip to content

Commit

Permalink
DOM document should store Invalid end tag </
Browse files Browse the repository at this point in the history
Fixes eclipse-lemminx#886

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Sep 24, 2020
1 parent 3ea8abb commit 5707527
Show file tree
Hide file tree
Showing 19 changed files with 364 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ public String getTagName() {
return tag;
}

/**
* Returns true if the DOM element have a tag name and null otherwise (ex : '<'
* or '</').
*
* @return true if the DOM element have a tag name and null otherwise (ex : '<'
* or '</').
*/
public boolean hasTagName() {
return tag != null;
}

/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -397,12 +408,23 @@ public boolean isEndTagClosed() {
* Returns true if the given element is an orphan end tag (which has no start
* tag, eg: </a>) and false otherwise.
*
* @param tagName the end tag name.
* @return true if the given element is an orphan end tag (which has no start
* tag, eg: </a>) and false otherwise.
*/
public boolean isOrphanEndTag(String tagName) {
return isSameTag(tagName) && hasEndTag() && !hasStartTag();
public boolean isOrphanEndTag() {
return hasEndTag() && !hasStartTag();
}

/**
* Returns true if the given element is an orphan end tag (which has no start
* tag, eg: </a>) of the given tag name and false otherwise.
*
* @param tagName the end tag name.
* @return true if the given element is an orphan end tag (which has no start
* tag, eg: </a>) of the given tag name and false otherwise.
*/
public boolean isOrphanEndTagOf(String tagName) {
return isSameTag(tagName) && isOrphanEndTag();
}

@Override
Expand All @@ -423,7 +445,7 @@ public DOMElement getOrphanEndElement(int offset, String tagName) {
for (DOMNode child : children) {
if (child.isElement()) {
DOMElement childElement = (DOMElement) child;
if (childElement.isOrphanEndTag(tagName)) {
if (childElement.isOrphanEndTagOf(tagName)) {
return childElement;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ public DOMElement getOrphanEndElement(int offset, String tagName) {
}
// emp| </employe>
DOMElement nextElement = (DOMElement) next;
if (nextElement.isOrphanEndTag(tagName)) {
if (nextElement.isOrphanEndTagOf(tagName)) {
return nextElement;
}
return null;
Expand Down
Loading

0 comments on commit 5707527

Please sign in to comment.