More robust @RequiresPermission handling.
The "conditional" value doesn't have any permissions to examine.
Test: builds, boots, "conditional" annotations work
Bug: 73559440
Change-Id: I78b3a9c86bdc972f1a3a7817e885e994cf84f8f6
diff --git a/src/com/google/doclava/AndroidAuxSource.java b/src/com/google/doclava/AndroidAuxSource.java
index cfcc0ac..1c97b18 100644
--- a/src/com/google/doclava/AndroidAuxSource.java
+++ b/src/com/google/doclava/AndroidAuxSource.java
@@ -146,12 +146,11 @@
// Document required permissions
if ((type == TYPE_CLASS || type == TYPE_METHOD || type == TYPE_FIELD)
&& annotation.type().qualifiedNameMatches("android", "annotation.RequiresPermission")) {
- ArrayList<AnnotationValueInfo> values = null;
+ ArrayList<AnnotationValueInfo> values = new ArrayList<>();
boolean any = false;
for (AnnotationValueInfo val : annotation.elementValues()) {
switch (val.element().name()) {
case "value":
- values = new ArrayList<AnnotationValueInfo>();
values.add(val);
break;
case "allOf":
@@ -163,7 +162,7 @@
break;
}
}
- if (values == null || values.isEmpty()) continue;
+ if (values.isEmpty()) continue;
ClassInfo permClass = annotation.type().findClass("android.Manifest.permission");
ArrayList<TagInfo> valueTags = new ArrayList<>();
diff --git a/src/com/google/doclava/AndroidLinter.java b/src/com/google/doclava/AndroidLinter.java
index 399226d..c5a00f0 100644
--- a/src/com/google/doclava/AndroidLinter.java
+++ b/src/com/google/doclava/AndroidLinter.java
@@ -77,7 +77,7 @@
for (AnnotationInstanceInfo a : method.annotations()) {
if (a.type().qualifiedNameMatches("android", "annotation.RequiresPermission")) {
hasAnnotation = true;
- ArrayList<AnnotationValueInfo> values = new ArrayList<AnnotationValueInfo>();
+ ArrayList<AnnotationValueInfo> values = new ArrayList<>();
for (AnnotationValueInfo val : a.elementValues()) {
switch (val.element().name()) {
case "value":
@@ -91,6 +91,8 @@
break;
}
}
+ if (values.isEmpty()) continue;
+
for (AnnotationValueInfo value : values) {
String perm = String.valueOf(value.value());
if (perm.indexOf('.') >= 0) perm = perm.substring(perm.lastIndexOf('.') + 1);
diff --git a/src/com/google/doclava/Stubs.java b/src/com/google/doclava/Stubs.java
index 81387be..c4453af 100644
--- a/src/com/google/doclava/Stubs.java
+++ b/src/com/google/doclava/Stubs.java
@@ -1586,11 +1586,10 @@
if (a.type().qualifiedNameMatches("android", "annotation.RequiresPermission")) {
hasAnnotation = true;
for (AnnotationValueInfo val : a.elementValues()) {
- ArrayList<AnnotationValueInfo> values = null;
+ ArrayList<AnnotationValueInfo> values = new ArrayList<>();
boolean any = false;
switch (val.element().name()) {
case "value":
- values = new ArrayList<AnnotationValueInfo>();
values.add(val);
break;
case "allOf":
@@ -1601,6 +1600,7 @@
values = (ArrayList<AnnotationValueInfo>) val.value();
break;
}
+ if (values.isEmpty()) continue;
ArrayList<String> system = new ArrayList<>();
ArrayList<String> nonSystem = new ArrayList<>();