Add Android files for google-java-format am: 7aef6bcfd3 am: 0d08709b71

Original change: https://android-review.googlesource.com/c/platform/external/google-java-format/+/1342208

Change-Id: I2e16bfc65793e48dac731c7d4c61b8b2fc013f6a
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..b5cc060
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,56 @@
+java_library_host {
+    name: "google_java_format_android_annotation_stubs",
+    srcs: ["android-annotation-stubs/src/**/*.java"],
+}
+
+filegroup {
+    name: "google_java_format_main_srcs",
+    srcs: [
+        "core/src/main/java/com/google/googlejavaformat/java/Main.java",
+        "core/src/main/java/com/google/googlejavaformat/java/UsageException.java",
+    ],
+}
+
+java_library_host {
+    name: "google_java_format",
+    srcs: ["core/src/main/java/**/*.java"],
+    exclude_srcs: [
+        ":google_java_format_main_srcs",
+        "core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java",
+    ],
+    libs: [
+        "error_prone_annotations",
+        "google_java_format_android_annotation_stubs",
+        "guava",
+    ],
+    javacflags: [
+        "--add-modules=jdk.compiler",
+        "--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+    ],
+}
+
+java_library_host {
+    name: "google_java_format_filer",
+    srcs: ["core/src/main/java/filer/*.java"],
+    libs: [
+        "error_prone_annotations",
+        "google_java_format_android_annotation_stubs",
+        "guava",
+    ],
+    javacflags: [
+        "--add-modules=jdk.compiler",
+        "--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
+        "--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+    ],
+}
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..dc78f17
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,17 @@
+name: "google-java-format"
+description:
+    "Reformats Java source code to comply with Google Java Style."
+
+third_party {
+  url {
+    type: HOMEPAGE
+    value: "https://github.com/google/google-java-format"
+  }
+  url {
+    type: GIT
+    value: "https://github.com/google/google-java-format"
+  }
+  version: "google-java-format-1.8"
+  last_upgrade_date { year: 2020 month: 6 day: 12 }
+  license_type: NOTICE
+}
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/android-annotation-stubs/gen_annotations.sh b/android-annotation-stubs/gen_annotations.sh
new file mode 100755
index 0000000..5af699a
--- /dev/null
+++ b/android-annotation-stubs/gen_annotations.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+ANNOTATIONS=(
+    org.checkerframework.checker.nullness.qual.Nullable
+)
+
+for a in ${ANNOTATIONS[@]}; do
+    package=${a%.*}
+    class=${a##*.}
+    dir=$(dirname $0)/src/${package//.//}
+    file=${class}.java
+
+    mkdir -p ${dir}
+    sed -e"s/__PACKAGE__/${package}/" -e"s/__CLASS__/${class}/" tmpl.java > ${dir}/${file}
+done
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..21e2cb9
--- /dev/null
+++ b/android-annotation-stubs/src/org/checkerframework/checker/nullness/qual/Nullable.java
@@ -0,0 +1,39 @@
+/*
+ * 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..814c143
--- /dev/null
+++ b/android-annotation-stubs/tmpl.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/* 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__ {}