summaryrefslogtreecommitdiff
path: root/lint/src
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2021-02-23 19:47:57 -0800
committerTor Norbye <tnorbye@google.com>2021-02-25 03:24:29 +0000
commit4ffd3ae8f9e765fcdde9b8ef6c63f11e3d1597bf (patch)
tree57a81d34e50592cfb0b6286e9b78bde10f0763fb /lint/src
parent432e2ce46d835e7d1bbff291c28ad8d8f167f5c0 (diff)
downloadidea-4ffd3ae8f9e765fcdde9b8ef6c63f11e3d1597bf.tar.gz
Add missing root comment nodes to DOM document
Lint's PSI to DOM bridge was only placing the root document element into the DOM document -- not comment nodes etc. Bug: https://groups.google.com/g/lint-dev/c/O_Py6TDM0Eg/m/QFdVx8x2CQAJ Test: Unit test included Change-Id: I9125641aff807e0b78564dc01cf8105400ced801
Diffstat (limited to 'lint/src')
-rw-r--r--lint/src/com/android/tools/idea/lint/common/DomPsiConverter.java37
1 files changed, 33 insertions, 4 deletions
diff --git a/lint/src/com/android/tools/idea/lint/common/DomPsiConverter.java b/lint/src/com/android/tools/idea/lint/common/DomPsiConverter.java
index 0bf6025eeec..96d229b766e 100644
--- a/lint/src/com/android/tools/idea/lint/common/DomPsiConverter.java
+++ b/lint/src/com/android/tools/idea/lint/common/DomPsiConverter.java
@@ -755,9 +755,28 @@ public class DomPsiConverter {
if (myChildren == null) {
DomNodeList list = new DomNodeList();
myChildren = list;
- DomNode documentElement = (DomNode)getDocumentElement();
- if (documentElement != null) {
- list.add(documentElement);
+ // Include siblings as well such as the root comment
+ PsiElement element = myPsiDocument.getFirstChild();
+ while (element != null) {
+ if (element instanceof XmlTag) {
+ if (myRoot != null && myRoot.myTag == element) {
+ list.add(myRoot);
+ } else {
+ DomElement node = new DomElement(this, this, (XmlTag)element);
+ if (myRoot == null) {
+ myRoot = node;
+ }
+ list.add(node);
+ }
+ } else if (element instanceof XmlComment) {
+ DomNode node = new DomComment(this, this, (XmlComment)element);
+ list.add(node);
+ } else if (element instanceof XmlText) {
+ // This is not valid XML but PSI may represent erroneous XML being edited
+ DomNode node = new DomText(this, this, (XmlText)element);
+ list.add(node);
+ }
+ element = element.getNextSibling();
}
}
@@ -1235,6 +1254,11 @@ public class DomPsiConverter {
return true;
}
+ @Override
+ public @NotNull String getData() throws DOMException {
+ return getNodeValue();
+ }
+
@NotNull
@Override
public String getWholeText() {
@@ -1272,7 +1296,7 @@ public class DomPsiConverter {
return application.runReadAction((Computable<String>)this::getNodeValue);
}
- return myComment.getText();
+ return myComment.getCommentText();
}
@Override
@@ -1285,6 +1309,11 @@ public class DomPsiConverter {
public String getTextContent() throws DOMException {
return getNodeValue();
}
+
+ @Override
+ public @NotNull String getData() throws DOMException {
+ return getNodeValue();
+ }
}
private static class DomAttr extends DomNode implements Attr {