Emit onJavaLangClassNewInstance event from reflective identification

Change-Id: Ia284ba2e5a37d182554948e5a7399f3984a0b8dd
diff --git a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
index 4dc8598..0c192c8 100644
--- a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
+++ b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
@@ -138,6 +138,7 @@
 import com.android.tools.r8.shaking.RootSetUtils.RootSetBuilder;
 import com.android.tools.r8.shaking.ScopedDexMethodSet.AddMethodIfMoreVisibleResult;
 import com.android.tools.r8.shaking.reflectiveidentification.EnqueuerReflectiveIdentificationAnalysis;
+import com.android.tools.r8.shaking.reflectiveidentification.EnqueuerReflectiveIdentificationEventConsumer;
 import com.android.tools.r8.shaking.rules.ApplicableRulesEvaluator;
 import com.android.tools.r8.shaking.rules.KeepAnnotationFakeProguardRule;
 import com.android.tools.r8.shaking.rules.KeepAnnotationMatcher;
@@ -504,7 +505,8 @@
     this.options = options;
     this.keepInfo = new MutableKeepInfoCollection(options);
     this.reflectiveIdentificationAnalysis =
-        new EnqueuerReflectiveIdentificationAnalysis(appView, this);
+        new EnqueuerReflectiveIdentificationAnalysis(
+            appView, this, new EnqueuerReflectiveIdentificationEventConsumer(this));
     this.useRegistryFactory = createUseRegistryFactory();
     this.worklist =
         EnqueuerWorklist.createWorklist(this, executorService, options.getThreadingModule());
diff --git a/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/EnqueuerReflectiveIdentificationAnalysis.java b/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/EnqueuerReflectiveIdentificationAnalysis.java
index 0d4e6b5..bf4cbb4 100644
--- a/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/EnqueuerReflectiveIdentificationAnalysis.java
+++ b/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/EnqueuerReflectiveIdentificationAnalysis.java
@@ -53,16 +53,20 @@
   private final AppView<? extends AppInfoWithClassHierarchy> appView;
   private final DexItemFactory factory;
   private final Enqueuer enqueuer;
+  private final ReflectiveIdentificationEventConsumer eventConsumer;
   private final InternalOptions options;
 
   private final Set<DexMember<?, ?>> identifierNameStrings = Sets.newIdentityHashSet();
   private final ProgramMethodSet worklist = ProgramMethodSet.create();
 
   public EnqueuerReflectiveIdentificationAnalysis(
-      AppView<? extends AppInfoWithClassHierarchy> appView, Enqueuer enqueuer) {
+      AppView<? extends AppInfoWithClassHierarchy> appView,
+      Enqueuer enqueuer,
+      ReflectiveIdentificationEventConsumer eventConsumer) {
     this.appView = appView;
     this.factory = appView.dexItemFactory();
     this.enqueuer = enqueuer;
+    this.eventConsumer = eventConsumer;
     this.options = appView.options();
   }
 
@@ -170,12 +174,8 @@
 
     DexProgramClass clazz =
         enqueuer.getProgramClassOrNullFromReflectiveAccess(instantiatedType, method);
-    if (clazz == null) {
-      return;
-    }
-    ProgramMethod defaultInitializer = clazz.getProgramDefaultInitializer();
-    if (defaultInitializer != null) {
-      enqueuer.traceReflectiveNewInstance(method, clazz, defaultInitializer);
+    if (clazz != null) {
+      eventConsumer.onJavaLangClassNewInstance(clazz, method);
     }
   }
 
diff --git a/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/EnqueuerReflectiveIdentificationEventConsumer.java b/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/EnqueuerReflectiveIdentificationEventConsumer.java
new file mode 100644
index 0000000..784ee2f
--- /dev/null
+++ b/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/EnqueuerReflectiveIdentificationEventConsumer.java
@@ -0,0 +1,26 @@
+// Copyright (c) 2025, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.shaking.reflectiveidentification;
+
+import com.android.tools.r8.graph.DexProgramClass;
+import com.android.tools.r8.graph.ProgramMethod;
+import com.android.tools.r8.shaking.Enqueuer;
+
+public class EnqueuerReflectiveIdentificationEventConsumer
+    implements ReflectiveIdentificationEventConsumer {
+
+  private final Enqueuer enqueuer;
+
+  public EnqueuerReflectiveIdentificationEventConsumer(Enqueuer enqueuer) {
+    this.enqueuer = enqueuer;
+  }
+
+  @Override
+  public void onJavaLangClassNewInstance(DexProgramClass clazz, ProgramMethod context) {
+    ProgramMethod defaultInitializer = clazz.getProgramDefaultInitializer();
+    if (defaultInitializer != null) {
+      enqueuer.traceReflectiveNewInstance(context, clazz, defaultInitializer);
+    }
+  }
+}
diff --git a/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/ReflectiveIdentificationEventConsumer.java b/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/ReflectiveIdentificationEventConsumer.java
new file mode 100644
index 0000000..5e850d6
--- /dev/null
+++ b/src/main/java/com/android/tools/r8/shaking/reflectiveidentification/ReflectiveIdentificationEventConsumer.java
@@ -0,0 +1,12 @@
+// Copyright (c) 2025, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.shaking.reflectiveidentification;
+
+import com.android.tools.r8.graph.DexProgramClass;
+import com.android.tools.r8.graph.ProgramMethod;
+
+public interface ReflectiveIdentificationEventConsumer {
+
+  void onJavaLangClassNewInstance(DexProgramClass clazz, ProgramMethod context);
+}