release-request-7d12f16b-b4a7-4324-8b59-be2d4e07dcb3-for-git_oc-release-4094438 snap-temp-L80000000073561277

Change-Id: Iba38d0b22b81234c054c86e5ce138e7252c5bb41
diff --git a/src/com/google/doclava/AndroidAuxSource.java b/src/com/google/doclava/AndroidAuxSource.java
index d006af0..8ed9fb0 100644
--- a/src/com/google/doclava/AndroidAuxSource.java
+++ b/src/com/google/doclava/AndroidAuxSource.java
@@ -20,6 +20,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 public class AndroidAuxSource implements AuxSource {
   private static final int TYPE_FIELD = 0;
@@ -77,31 +78,44 @@
   @Override
   public TagInfo[] fieldAuxTags(FieldInfo field) {
     if (hasSuppress(field)) return TagInfo.EMPTY_ARRAY;
-    return auxTags(TYPE_FIELD, field.annotations());
+    return auxTags(TYPE_FIELD, field.annotations(), toString(field.inlineTags()));
   }
 
   @Override
   public TagInfo[] methodAuxTags(MethodInfo method) {
     if (hasSuppress(method)) return TagInfo.EMPTY_ARRAY;
-    return auxTags(TYPE_METHOD, method.annotations());
+    return auxTags(TYPE_METHOD, method.annotations(), toString(method.inlineTags().tags()));
   }
 
   @Override
-  public TagInfo[] paramAuxTags(MethodInfo method, ParameterInfo param) {
+  public TagInfo[] paramAuxTags(MethodInfo method, ParameterInfo param, String comment) {
     if (hasSuppress(method)) return TagInfo.EMPTY_ARRAY;
     if (hasSuppress(param.annotations())) return TagInfo.EMPTY_ARRAY;
-    return auxTags(TYPE_PARAM, param.annotations());
+    return auxTags(TYPE_PARAM, param.annotations(), new String[] { comment });
   }
 
   @Override
   public TagInfo[] returnAuxTags(MethodInfo method) {
     if (hasSuppress(method)) return TagInfo.EMPTY_ARRAY;
-    return auxTags(TYPE_RETURN, method.annotations());
+    return auxTags(TYPE_RETURN, method.annotations(), toString(method.returnTags().tags()));
   }
 
-  private static TagInfo[] auxTags(int type, List<AnnotationInstanceInfo> annotations) {
+  private static TagInfo[] auxTags(int type, List<AnnotationInstanceInfo> annotations,
+      String[] comment) {
     ArrayList<TagInfo> tags = new ArrayList<>();
     for (AnnotationInstanceInfo annotation : annotations) {
+      // Ignore null-related annotations when docs already mention
+      if (annotation.type().qualifiedNameMatches("android", "annotation.NonNull")
+          || annotation.type().qualifiedNameMatches("android", "annotation.Nullable")) {
+        boolean mentionsNull = false;
+        for (String c : comment) {
+          mentionsNull |= Pattern.compile("\\bnull\\b").matcher(c).find();
+        }
+        if (mentionsNull) {
+          continue;
+        }
+      }
+
       // Blindly include docs requested by annotations
       ParsedTagInfo[] docTags = ParsedTagInfo.EMPTY_ARRAY;
       switch (type) {
@@ -238,6 +252,14 @@
     return tags.toArray(TagInfo.getArray(tags.size()));
   }
 
+  private static String[] toString(TagInfo[] tags) {
+    final String[] res = new String[tags.length];
+    for (int i = 0; i < res.length; i++) {
+      res[i] = tags[i].text();
+    }
+    return res;
+  }
+
   private static boolean hasSuppress(MemberInfo member) {
     return hasSuppress(member.annotations())
         || hasSuppress(member.containingClass().annotations());
diff --git a/src/com/google/doclava/AuxSource.java b/src/com/google/doclava/AuxSource.java
index 03594f5..df03546 100644
--- a/src/com/google/doclava/AuxSource.java
+++ b/src/com/google/doclava/AuxSource.java
@@ -20,7 +20,7 @@
   public TagInfo[] classAuxTags(ClassInfo clazz);
   public TagInfo[] fieldAuxTags(FieldInfo field);
   public TagInfo[] methodAuxTags(MethodInfo method);
-  public TagInfo[] paramAuxTags(MethodInfo method, ParameterInfo param);
+  public TagInfo[] paramAuxTags(MethodInfo method, ParameterInfo param, String comment);
   public TagInfo[] returnAuxTags(MethodInfo method);
 }
 
@@ -41,7 +41,7 @@
   }
 
   @Override
-  public TagInfo[] paramAuxTags(MethodInfo method, ParameterInfo param) {
+  public TagInfo[] paramAuxTags(MethodInfo method, ParameterInfo param, String comment) {
     return TagInfo.EMPTY_ARRAY;
   }
 
diff --git a/src/com/google/doclava/MethodInfo.java b/src/com/google/doclava/MethodInfo.java
index 5ed58eb..47b1978 100644
--- a/src/com/google/doclava/MethodInfo.java
+++ b/src/com/google/doclava/MethodInfo.java
@@ -513,7 +513,7 @@
         }
 
         // Collect all docs requested by annotations
-        TagInfo[] auxTags = Doclava.auxSource.paramAuxTags(this, param);
+        TagInfo[] auxTags = Doclava.auxSource.paramAuxTags(this, param, comment);
 
         // Okay, now add the collected parameter information to the method data
         mParamTags[i] =