Add metadata for the dimension annotation, and strip typedefs

The support annotations library is a plain Java library, it's not an
Android library, which means it gets built by the Gradle java plugin,
and packaged as a plain jar file. That means that the typedef
annotations (on VisibleForTesting and Dimension) were getting included
in the .jar file, which is pointless.

This CL removes these classes at build time (and to do that, they had
to be top level classes rather than inner classes; removing inner
classes at packaging isn't safe since the outerclass contains
references to its inner classes). This CL also adds external metadata
information about the Dimension's unit attribute, which was missing.

It's unfortunate that we can't just use the android library build
support that handles all this automatically, but a number of users
like that the annotations library is a plain .jar such that they can
include it not just in their Android apps, but in plain Java modules
as well which are contain shared server and app code.

Change-Id: If6ac38f1e5aad7091001ff3749c804b5c0a2452b
diff --git a/annotations/build.gradle b/annotations/build.gradle
index d7e8532..4907e2a 100644
--- a/annotations/build.gradle
+++ b/annotations/build.gradle
@@ -12,6 +12,14 @@
 
 jar {
     from sourceSets.main.output
+    // Strip out typedef classes. For Android libraries, this is done
+    // automatically by the Gradle plugin, but the Annotation library is a
+    // plain jar, built by the regular Gradle java plugin. The typedefs
+    // themselves have been manually extracted into the
+    // external-annotations directory, and those are packaged separately
+    // below by the annotationsZip task.
+    exclude('android/support/annotation/ProductionVisibility.class')
+    exclude('android/support/annotation/DimensionUnit.class')
 }
 
 uploadArchives {
diff --git a/annotations/external-annotations/android/support/annotation/annotations.xml b/annotations/external-annotations/android/support/annotation/annotations.xml
index 284d0f4..23e9a01 100644
--- a/annotations/external-annotations/android/support/annotation/annotations.xml
+++ b/annotations/external-annotations/android/support/annotation/annotations.xml
@@ -4,4 +4,9 @@
             <val name="value" val="{android.support.annotation.VisibleForTesting.PRIVATE, android.support.annotation.VisibleForTesting.PACKAGE_PRIVATE, android.support.annotation.VisibleForTesting.PROTECTED, android.support.annotation.VisibleForTesting.NONE}" />
         </annotation>
     </item>
-</root>
\ No newline at end of file
+    <item name="android.support.annotation.Dimension int unit()">
+        <annotation name="android.support.annotation.IntDef">
+            <val name="value" val="{android.support.annotation.Dimension.DP, android.support.annotation.Dimension.PX, android.support.annotation.Dimension.SP}" />
+        </annotation>
+    </item>
+</root>
diff --git a/annotations/src/android/support/annotation/Dimension.java b/annotations/src/android/support/annotation/Dimension.java
index cb4fb5e..b8c5590 100644
--- a/annotations/src/android/support/annotation/Dimension.java
+++ b/annotations/src/android/support/annotation/Dimension.java
@@ -18,7 +18,6 @@
 
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
 import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
@@ -36,14 +35,10 @@
 @Retention(CLASS)
 @Target({METHOD,PARAMETER,FIELD,LOCAL_VARIABLE,ANNOTATION_TYPE})
 public @interface Dimension {
-    @Unit
+    @DimensionUnit
     int unit() default PX;
 
     int DP = 0;
     int PX = 1;
     int SP = 2;
-
-    @IntDef({PX, DP, SP})
-    @Retention(RetentionPolicy.SOURCE)
-    @interface Unit {}
 }
diff --git a/annotations/src/android/support/annotation/DimensionUnit.java b/annotations/src/android/support/annotation/DimensionUnit.java
new file mode 100644
index 0000000..d4d6398
--- /dev/null
+++ b/annotations/src/android/support/annotation/DimensionUnit.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 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 android.support.annotation;
+
+import java.lang.annotation.Retention;
+
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+/**
+ * Typedef for the {@link Dimension#unit} attribute.
+ *
+ * @hide
+ */
+@IntDef({Dimension.PX,
+         Dimension.DP,
+         Dimension.SP}
+// Important: If updating these constants, also update
+// ../../../../external-annotations/android/support/annotation/annotations.xml
+)
+@Retention(SOURCE)
+@interface DimensionUnit {
+}
diff --git a/annotations/src/android/support/annotation/ProductionVisibility.java b/annotations/src/android/support/annotation/ProductionVisibility.java
new file mode 100644
index 0000000..6bd978e
--- /dev/null
+++ b/annotations/src/android/support/annotation/ProductionVisibility.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 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 android.support.annotation;
+
+import java.lang.annotation.Retention;
+
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+/**
+ * Typedef for the {@link VisibleForTesting#otherwise} attribute.
+ *
+ * @hide
+ */
+@IntDef({VisibleForTesting.PRIVATE,
+         VisibleForTesting.PACKAGE_PRIVATE,
+         VisibleForTesting.PROTECTED,
+         VisibleForTesting.NONE}
+// Important: If updating these constants, also update
+// ../../../../external-annotations/android/support/annotation/annotations.xml
+)
+@Retention(SOURCE)
+@interface ProductionVisibility {
+}
diff --git a/annotations/src/android/support/annotation/VisibleForTesting.java b/annotations/src/android/support/annotation/VisibleForTesting.java
index ddce1d5..16d915a 100644
--- a/annotations/src/android/support/annotation/VisibleForTesting.java
+++ b/annotations/src/android/support/annotation/VisibleForTesting.java
@@ -18,7 +18,6 @@
 import java.lang.annotation.Retention;
 
 import static java.lang.annotation.RetentionPolicy.CLASS;
-import static java.lang.annotation.RetentionPolicy.SOURCE;
 
 /**
  * Denotes that the class, method or field has its visibility relaxed, so that it is more widely
@@ -66,9 +65,4 @@
      * This is equivalent to {@code @RestrictTo.Scope.TESTS}.
      */
     int NONE = 5;
-
-    @IntDef({PRIVATE, PACKAGE_PRIVATE, PROTECTED, NONE})
-    @Retention(SOURCE)
-    @interface ProductionVisibility {
-    }
 }