Use AutoValue from external/auto

Use the AutoValue built from source instead of the prebuilts
from external/dagger2.

Also replace the annotations that were being picked up from the prebuilts
with local stubs.

Bug: 158870037
Test: m checkbuild
Change-Id: I37eff2258f343a17cb1fa80ca7f36f80aa9536ff
diff --git a/Android.bp b/Android.bp
index 8a1af22..2206d6d 100644
--- a/Android.bp
+++ b/Android.bp
@@ -20,6 +20,7 @@
     srcs: [
         "java/**/*.java",
         "proto/**/*.proto",
+        "android-annotation-stubs/src/**/*.java",
     ],
 
     manifest: "manifest.txt",
@@ -28,8 +29,11 @@
         "guava",
     ],
 
-    plugins: ["dagger2-auto-value"],
-    libs: ["dagger2-auto-value"],
+    plugins: ["auto_value_plugin"],
+    libs: [
+        "auto_value_annotations",
+        "auto_value_memoized_extension_annotations",
+    ],
 
     proto: {
         type: "full",
diff --git a/android-annotation-stubs/gen_annotations.sh b/android-annotation-stubs/gen_annotations.sh
new file mode 100755
index 0000000..1965324
--- /dev/null
+++ b/android-annotation-stubs/gen_annotations.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+declare -A INNER
+declare -A PARAMETER
+declare -A IMPORT
+
+ANNOTATIONS=(
+    org.checkerframework.checker.nullness.qual.Nullable
+    org.checkerframework.checker.nullness.compatqual.NullableDecl
+)
+
+for a in ${ANNOTATIONS[@]}; do
+    package=${a%.*}
+    class=${a##*.}
+    dir=$(dirname $0)/src/${package//.//}
+    file=${class}.java
+    inner=${INNER[$a]}
+    parameter=${PARAMETER[$a]}
+    import=
+
+    if [ -n "${parameter}" ]; then
+	parameter="${parameter} value();"
+    fi
+
+    for i in ${IMPORT[$a]}; do
+	import="${import}import ${i};"
+    done
+
+    mkdir -p ${dir}
+    sed -e"s/__PACKAGE__/${package}/" \
+	-e"s/__CLASS__/${class}/" \
+	-e"s/__INNER__/${inner}/" \
+	-e"s/__PARAMETER__/${parameter}/" \
+	-e"s/__IMPORT__/${import}/" \
+	$(dirname $0)/tmpl.java > ${dir}/${file}
+    google-java-format -i ${dir}/${file}
+done
diff --git a/android-annotation-stubs/src/org/checkerframework/checker/nullness/compatqual/NullableDecl.java b/android-annotation-stubs/src/org/checkerframework/checker/nullness/compatqual/NullableDecl.java
new file mode 100644
index 0000000..2d39b0f
--- /dev/null
+++ b/android-annotation-stubs/src/org/checkerframework/checker/nullness/compatqual/NullableDecl.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.checkerframework.checker.nullness.compatqual;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/* This is an annotation stub to avoid dependencies on annotations that aren't
+ * in the Android platform source tree. */
+
+@Target({
+  ElementType.ANNOTATION_TYPE,
+  ElementType.CONSTRUCTOR,
+  ElementType.FIELD,
+  ElementType.LOCAL_VARIABLE,
+  ElementType.METHOD,
+  ElementType.PACKAGE,
+  ElementType.PARAMETER,
+  ElementType.TYPE,
+  ElementType.TYPE_PARAMETER,
+  ElementType.TYPE_USE
+})
+@Retention(RetentionPolicy.SOURCE)
+public @interface NullableDecl {}
diff --git a/android-annotation-stubs/src/org/checkerframework/checker/nullness/qual/Nullable.java b/android-annotation-stubs/src/org/checkerframework/checker/nullness/qual/Nullable.java
new file mode 100644
index 0000000..276d64c
--- /dev/null
+++ b/android-annotation-stubs/src/org/checkerframework/checker/nullness/qual/Nullable.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.checkerframework.checker.nullness.qual;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/* This is an annotation stub to avoid dependencies on annotations that aren't
+ * in the Android platform source tree. */
+
+@Target({
+  ElementType.ANNOTATION_TYPE,
+  ElementType.CONSTRUCTOR,
+  ElementType.FIELD,
+  ElementType.LOCAL_VARIABLE,
+  ElementType.METHOD,
+  ElementType.PACKAGE,
+  ElementType.PARAMETER,
+  ElementType.TYPE,
+  ElementType.TYPE_PARAMETER,
+  ElementType.TYPE_USE
+})
+@Retention(RetentionPolicy.SOURCE)
+public @interface Nullable {}
diff --git a/android-annotation-stubs/tmpl.java b/android-annotation-stubs/tmpl.java
new file mode 100644
index 0000000..c4df609
--- /dev/null
+++ b/android-annotation-stubs/tmpl.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package __PACKAGE__;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+__IMPORT__
+
+/* This is an annotation stub to avoid dependencies on annotations that aren't
+ * in the Android platform source tree. */
+
+@Target({
+  ElementType.ANNOTATION_TYPE,
+  ElementType.CONSTRUCTOR,
+  ElementType.FIELD,
+  ElementType.LOCAL_VARIABLE,
+  ElementType.METHOD,
+  ElementType.PACKAGE,
+  ElementType.PARAMETER,
+  ElementType.TYPE,
+  ElementType.TYPE_PARAMETER,
+  ElementType.TYPE_USE})
+@Retention(RetentionPolicy.SOURCE)
+public @interface __CLASS__ {
+  __INNER__
+  __PARAMETER__
+}