summaryrefslogtreecommitdiff
path: root/lint/src
diff options
context:
space:
mode:
authorMatthew Gharrity <gharrma@google.com>2021-02-26 14:18:37 -0500
committerMatthew Gharrity <gharrma@google.com>2021-02-26 14:56:14 -0500
commit5168061f438c0166642ef7b6d1f793e7f27522c0 (patch)
tree9d33e2756eac43c65539fc28e2b551c8863da7b2 /lint/src
parentd1598affa67691f850fc2e68405a551a70528ac0 (diff)
downloadidea-5168061f438c0166642ef7b6d1f793e7f27522c0.tar.gz
Lint: minor cleanup in DomPsiConverter
Bug: n/a Test: existing Change-Id: Ia8fd402a70c0c998ca4f3d2e398355aaa13bd562
Diffstat (limited to 'lint/src')
-rw-r--r--lint/src/com/android/tools/idea/lint/common/DomPsiConverter.java96
1 files changed, 19 insertions, 77 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 787b073ccd0..482c3dbbb2f 100644
--- a/lint/src/com/android/tools/idea/lint/common/DomPsiConverter.java
+++ b/lint/src/com/android/tools/idea/lint/common/DomPsiConverter.java
@@ -1016,32 +1016,19 @@ public class DomPsiConverter {
@NotNull
@Override
public String getNamespaceURI() {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)myTag::getNamespace);
- }
- return myTag.getNamespace();
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)myTag::getNamespace);
}
@NotNull
@Override
public NamedNodeMap getAttributes() {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<NamedNodeMap>)this::getAttributes);
- }
-
- if (myAttributes == null) {
- XmlAttribute[] attributes = myTag.getAttributes();
- if (attributes.length == 0) {
- myAttributes = EMPTY_ATTRIBUTES;
+ return ApplicationManager.getApplication().runReadAction((Computable<NamedNodeMap>)() -> {
+ if (myAttributes == null) {
+ XmlAttribute[] attributes = myTag.getAttributes();
+ myAttributes = attributes.length == 0 ? EMPTY_ATTRIBUTES : new DomNamedNodeMap(this, attributes);
}
- else {
- myAttributes = new DomNamedNodeMap(this, attributes);
- }
- }
-
- return myAttributes;
+ return myAttributes;
+ });
}
// From org.w3c.dom.Element:
@@ -1049,23 +1036,13 @@ public class DomPsiConverter {
@NotNull
@Override
public String getTagName() {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)this::getTagName);
- }
-
- return myTag.getName();
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)myTag::getName);
}
@Nullable
@Override
public String getLocalName() {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)this::getLocalName);
- }
-
- return myTag.getLocalName();
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)myTag::getLocalName);
}
@NotNull
@@ -1221,12 +1198,7 @@ public class DomPsiConverter {
@NotNull
@Override
public String getNodeValue() throws DOMException {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)this::getNodeValue);
- }
-
- return myText.getText();
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)myText::getText);
}
@Override
@@ -1291,12 +1263,7 @@ public class DomPsiConverter {
@NotNull
@Override
public String getNodeValue() throws DOMException {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)this::getNodeValue);
- }
-
- return myComment.getCommentText();
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)myComment::getCommentText);
}
@Override
@@ -1350,11 +1317,7 @@ public class DomPsiConverter {
@NotNull
@Override
public String getName() {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)this::getName);
- }
- return myAttribute.getName();
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)myAttribute::getName);
}
@Override
@@ -1365,49 +1328,28 @@ public class DomPsiConverter {
@NotNull
@Override
public String getValue() {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)this::getValue);
- }
-
- String value = myAttribute.getDisplayValue();
- if (value == null) {
- value = "";
- }
- return value;
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)() -> {
+ String value = myAttribute.getDisplayValue();
+ return value == null ? "" : value;
+ });
}
@NotNull
@Override
public String getLocalName() {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)this::getLocalName);
- }
-
- return myAttribute.getLocalName();
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)myAttribute::getLocalName);
}
@NotNull
@Override
public String getPrefix() {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)this::getPrefix);
- }
-
- return myAttribute.getNamespacePrefix();
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)myAttribute::getNamespacePrefix);
}
@NotNull
@Override
public String getNamespaceURI() {
- Application application = ApplicationManager.getApplication();
- if (!application.isReadAccessAllowed()) {
- return application.runReadAction((Computable<String>)this::getNamespaceURI);
- }
-
- return myAttribute.getNamespace();
+ return ApplicationManager.getApplication().runReadAction((Computable<String>)myAttribute::getNamespace);
}
@Override