Apply minification to enum default values in annotations

Change-Id: I8f5a2b044eaa9ed508370623b082f9e5e0e94272
diff --git a/src/main/java/com/android/tools/r8/jar/CfApplicationWriter.java b/src/main/java/com/android/tools/r8/jar/CfApplicationWriter.java
index 0206e81..74d7686 100644
--- a/src/main/java/com/android/tools/r8/jar/CfApplicationWriter.java
+++ b/src/main/java/com/android/tools/r8/jar/CfApplicationWriter.java
@@ -22,6 +22,7 @@
 import com.android.tools.r8.graph.DexEncodedAnnotation;
 import com.android.tools.r8.graph.DexEncodedField;
 import com.android.tools.r8.graph.DexEncodedMethod;
+import com.android.tools.r8.graph.DexField;
 import com.android.tools.r8.graph.DexMethod;
 import com.android.tools.r8.graph.DexProgramClass;
 import com.android.tools.r8.graph.DexString;
@@ -29,7 +30,6 @@
 import com.android.tools.r8.graph.DexValue;
 import com.android.tools.r8.graph.DexValue.DexValueAnnotation;
 import com.android.tools.r8.graph.DexValue.DexValueArray;
-import com.android.tools.r8.graph.DexValue.DexValueEnum;
 import com.android.tools.r8.graph.DexValue.DexValueInt;
 import com.android.tools.r8.graph.DexValue.DexValueString;
 import com.android.tools.r8.graph.GraphLens;
@@ -522,9 +522,11 @@
         break;
 
       case ENUM:
-        DexValueEnum en = value.asDexValueEnum();
+        DexField enumField = value.asDexValueEnum().getValue();
         visitor.visitEnum(
-            name, namingLens.lookupDescriptor(en.value.type).toString(), en.value.name.toString());
+            name,
+            namingLens.lookupDescriptor(enumField.getType()).toString(),
+            namingLens.lookupName(enumField).toString());
         break;
 
       case FIELD:
diff --git a/src/test/java/com/android/tools/r8/shaking/annotations/b137392797/B137392797.java b/src/test/java/com/android/tools/r8/shaking/annotations/b137392797/B137392797.java
index ddc9a2b..184cd68 100644
--- a/src/test/java/com/android/tools/r8/shaking/annotations/b137392797/B137392797.java
+++ b/src/test/java/com/android/tools/r8/shaking/annotations/b137392797/B137392797.java
@@ -71,6 +71,16 @@
             "com.squareup.wire.WireField", "com.squareup.demo.myapplication.Test")
         .addKeepMainRule(TestClass.class)
         .addKeepAttributes("*Annotation*")
+        .applyIf(
+            parameters.isCfRuntime(),
+            builder ->
+                // When parsing the enum default value, the JVM tries to find the enum with the
+                // given name, but after shrinking the enum field names and the enum instance names
+                // no longer match.
+                builder.addKeepRules(
+                    "-keepclassmembers,allowshrinking class com.squareup.wire.WireField$Label {",
+                    "  static com.squareup.wire.WireField$Label OPTIONAL;",
+                    "}"))
         .setMinApi(parameters.getApiLevel())
         .compile()
         .inspect(this::checkEnumUses)
diff --git a/src/test/java/com/android/tools/r8/shaking/enums/EnumInAnnotationTest.java b/src/test/java/com/android/tools/r8/shaking/enums/EnumInAnnotationTest.java
index d42d3ad..61a9845 100644
--- a/src/test/java/com/android/tools/r8/shaking/enums/EnumInAnnotationTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/enums/EnumInAnnotationTest.java
@@ -43,6 +43,11 @@
     testForR8(parameters.getBackend())
         .addInnerClasses(EnumInAnnotationTest.class)
         .addKeepMainRule(Main.class)
+        .applyIf(
+            parameters.isCfRuntime(),
+            builder ->
+                builder.addKeepRules(
+                    "-keepclassmembernames class " + Enum.class.getTypeName() + " { <fields>; }"))
         .setMinApi(parameters.getApiLevel())
         .addKeepRuntimeVisibleAnnotations()
         .run(parameters.getRuntime(), Main.class)