Lookup target holder during lens code rewriting to set interface bit

Bug: 157111832
Change-Id: Iac61263d2ecbd61f6e354c58905544b1c3935fb5
diff --git a/src/main/java/com/android/tools/r8/ir/code/Invoke.java b/src/main/java/com/android/tools/r8/ir/code/Invoke.java
index 8fad9af..1c19488 100644
--- a/src/main/java/com/android/tools/r8/ir/code/Invoke.java
+++ b/src/main/java/com/android/tools/r8/ir/code/Invoke.java
@@ -61,6 +61,7 @@
     super(result, arguments);
   }
 
+  @Deprecated
   public static Invoke create(
       Type type, DexItem target, DexProto proto, Value result, List<Value> arguments) {
     return create(type, target, proto, result, arguments, false);
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/LensCodeRewriter.java b/src/main/java/com/android/tools/r8/ir/conversion/LensCodeRewriter.java
index e94d07e..f83952c 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/LensCodeRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/LensCodeRewriter.java
@@ -29,6 +29,7 @@
 import static com.android.tools.r8.ir.code.Opcodes.RETURN;
 import static com.android.tools.r8.ir.code.Opcodes.STATIC_GET;
 import static com.android.tools.r8.ir.code.Opcodes.STATIC_PUT;
+import static com.android.tools.r8.utils.ObjectUtils.getBooleanOrElse;
 
 import com.android.tools.r8.errors.Unreachable;
 import com.android.tools.r8.graph.AppInfoWithClassHierarchy;
@@ -293,8 +294,18 @@
                 assert newInValues.size()
                     == actualTarget.proto.parameters.size() + (actualInvokeType == STATIC ? 0 : 1);
 
+                // TODO(b/157111832): This bit should be part of the graph lens lookup result.
+                boolean isInterface =
+                    getBooleanOrElse(
+                        appView.definitionFor(actualTarget.holder), DexClass::isInterface, false);
                 Invoke newInvoke =
-                    Invoke.create(actualInvokeType, actualTarget, null, newOutValue, newInValues);
+                    Invoke.create(
+                        actualInvokeType,
+                        actualTarget,
+                        null,
+                        newOutValue,
+                        newInValues,
+                        isInterface);
                 iterator.replaceCurrentInstruction(newInvoke);
                 if (newOutValue != null && newOutValue.getType() != current.getOutType()) {
                   affectedPhis.addAll(newOutValue.uniquePhiUsers());
diff --git a/src/main/java/com/android/tools/r8/utils/ObjectUtils.java b/src/main/java/com/android/tools/r8/utils/ObjectUtils.java
new file mode 100644
index 0000000..ac07151
--- /dev/null
+++ b/src/main/java/com/android/tools/r8/utils/ObjectUtils.java
@@ -0,0 +1,17 @@
+// Copyright (c) 2020, 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.utils;
+
+import java.util.function.Predicate;
+
+public class ObjectUtils {
+
+  public static <T> boolean getBooleanOrElse(T object, Predicate<T> fn, boolean orElse) {
+    if (object != null) {
+      return fn.test(object);
+    }
+    return orElse;
+  }
+}