summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-17 19:21:55 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-07-17 19:21:55 +0000
commitabbecba7dcfa2ed2eaaaf35eb3e75ca5b84ceada (patch)
tree3b1b9ebdda86c3a611885ffdb406c6dc03788ecc
parent5732a0d4f70af9081c2ea5c08886dbc7f15c4595 (diff)
parent96d47ed78ac3c626ea4d64f8b53ded91fc604a13 (diff)
downloaddoclava-androidx-g3-release.tar.gz
Merge "Snap for 8738840 from b8a330e005b4e5bb93d273ca93b9359ad5e31d40 to androidx-g3-release" into androidx-g3-releaseandroidx-g3-release
-rw-r--r--Android.bp2
-rw-r--r--METADATA4
-rw-r--r--gradle/wrapper/gradle-wrapper.properties2
-rw-r--r--src/com/google/doclava/Converter.java38
4 files changed, 38 insertions, 8 deletions
diff --git a/Android.bp b/Android.bp
index a3e2317..4c81ca5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -54,6 +54,7 @@ droiddoc_exported_dir {
java_library_host {
name: "doclava",
+ java_version: "1.8",
srcs: [
"src/**/*.java",
],
@@ -69,6 +70,7 @@ java_library_host {
java_library_host {
name: "doclava-no-guava",
+ java_version: "1.8",
srcs: [
"src/**/*.java",
],
diff --git a/METADATA b/METADATA
index 95f8f51..abbaf9d 100644
--- a/METADATA
+++ b/METADATA
@@ -1,6 +1,4 @@
third_party {
- # would be NOTICE save for:
- # templates/
- # templates-sdk/
+ license_note: "would be NOTICE save for: templates/ and templates-sdk/"
license_type: RESTRICTED
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 92352a0..27a6e95 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=../../../../tools/external/gradle/gradle-6.5.1-bin.zip
+distributionUrl=../../../../tools/external/gradle/gradle-7.4-bin.zip
diff --git a/src/com/google/doclava/Converter.java b/src/com/google/doclava/Converter.java
index cf14237..2143875 100644
--- a/src/com/google/doclava/Converter.java
+++ b/src/com/google/doclava/Converter.java
@@ -23,6 +23,7 @@ import com.sun.javadoc.AnnotationTypeElementDoc;
import com.sun.javadoc.AnnotationValue;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.ConstructorDoc;
+import com.sun.javadoc.Doc;
import com.sun.javadoc.ExecutableMemberDoc;
import com.sun.javadoc.FieldDoc;
import com.sun.javadoc.MemberDoc;
@@ -43,7 +44,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
public class Converter {
private static RootDoc root;
@@ -288,7 +288,7 @@ public class Converter {
}
private static ParameterInfo[] convertParameters(Parameter[] p, ExecutableMemberDoc m) {
- SourcePosition pos = m.position();
+ SourcePosition pos = getPositionSafe(m);
int len = p.length;
ParameterInfo[] q = new ParameterInfo[len];
for (int i = 0; i < len; i++) {
@@ -447,6 +447,27 @@ public class Converter {
return (MethodInfo) mMethods.obtain(o);
}
+ /**
+ * Returns the result of a call to {@code f.position()} but avoids a {@link NullPointerException}
+ * if {@code f.position()} throws a {@link NullPointerException} due to the {@link Doc} element
+ * being related to an annotation.
+ *
+ * <p>This is consistent with the Java runtime where references to annotations that do not exist
+ * on the classpath are allowed. This method is used, for example, to allow Doclava to process
+ * JARs in the classpath that were generated by the Kotlin compiler, without requiring the Kotlin
+ * stdlib to exist on the classpath when Doclava is executed.
+ */
+ private static SourcePosition getPositionSafe(Doc f) {
+ try {
+ return f.position();
+ } catch (NullPointerException e) {
+ if (f.isAnnotationTypeElement() || mFieldDocElementsOnAnnotationClasses.contains(f)) {
+ return null;
+ }
+ throw e;
+ }
+ }
+
private static Cache mMethods = new Cache() {
@Override
protected Object make(Object o) {
@@ -466,7 +487,7 @@ public class Converter {
new ArrayList<ParameterInfo>(Arrays.asList(
Converter.convertParameters(m.parameters(), m))),
new ArrayList<ClassInfo>(Arrays.asList(Converter.convertClasses(
- m.thrownExceptions()))), Converter.convertSourcePosition(m.position()),
+ m.thrownExceptions()))), Converter.convertSourcePosition(getPositionSafe(m)),
new ArrayList<AnnotationInstanceInfo>(Arrays.asList(
Converter.convertAnnotationInstances(m.annotations()))));
result.setVarargs(m.isVarArgs());
@@ -547,7 +568,7 @@ public class Converter {
.obtainClass(f.containingClass()), f.isPublic(), f.isProtected(), f.isPackagePrivate(), f
.isPrivate(), f.isFinal(), f.isStatic(), f.isTransient(), f.isVolatile(),
f.isSynthetic(), Converter.obtainType(f.type()), f.getRawCommentText(),
- f.constantValue(), Converter.convertSourcePosition(f.position()),
+ f.constantValue(), Converter.convertSourcePosition(getPositionSafe(f)),
new ArrayList<AnnotationInstanceInfo>(Arrays.asList(Converter
.convertAnnotationInstances(f.annotations()))));
}
@@ -760,6 +781,12 @@ public class Converter {
new HashMap<AnnotationValue, AnnotationValueInfo>();
private static HashSet<AnnotationValue> mAnnotationValuesNeedingInit =
new HashSet<AnnotationValue>();
+ /**
+ * Stores the {@link FieldDoc} instances the are contained in annotation classes. This is used by
+ * {@link #getPositionSafe(Doc)} to allow {@link NullPointerException} for annotation classes to
+ * be ignored.
+ */
+ private static HashSet<FieldDoc> mFieldDocElementsOnAnnotationClasses = new HashSet<FieldDoc>();
private static AnnotationValueInfo obtainAnnotationValue(AnnotationValue o, MethodInfo element) {
if (o == null) {
@@ -769,6 +796,9 @@ public class Converter {
if (v != null) return v;
v = new AnnotationValueInfo(element);
mAnnotationValues.put(o, v);
+ if (o.value() instanceof FieldDoc) {
+ mFieldDocElementsOnAnnotationClasses.add((FieldDoc) o.value());
+ }
if (mAnnotationValuesNeedingInit != null) {
mAnnotationValuesNeedingInit.add(o);
} else {