Remove unused code: Legacy Android core library constructor invocations
@@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkState;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
/**
* Rewriter of default and static interface methods defined in some core libraries.
@@ -33,22 +32,6 @@ public class CoreLibraryInvocationRewriter extends ClassVisitor {
private final CoreLibrarySupport support;
- @Override
- public void visit(
- int version,
- int access,
- String name,
- String signature,
- String superName,
- String[] interfaces) {
- super.visit(version, access, name, signature, superName, interfaces);
- if (support.getMoveTarget(superName, "<init>") != null) {
- throw new UnsupportedOperationException(
- String.format(
- "Subclassing %s is unsupported: Contains a desugared factory method.", superName));
- }
- }
-
public CoreLibraryInvocationRewriter(ClassVisitor cv, CoreLibrarySupport support) {
super(Opcodes.ASM8, cv);
this.support = support;
@@ -71,7 +54,6 @@ public class CoreLibraryInvocationRewriter extends ClassVisitor {
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
Class<?> coreInterface =
support.getCoreInterfaceRewritingTarget(opcode, owner, name, desc, itf);
- boolean replaceConstructorUseWithFactoryMethod = false;
if (coreInterface != null) {
String coreInterfaceName = coreInterface.getName().replace('.', '/');
if (opcode == Opcodes.INVOKESTATIC) {
@@ -105,17 +87,7 @@ public class CoreLibraryInvocationRewriter extends ClassVisitor {
} else {
String newOwner = support.getMoveTarget(owner, name);
if (newOwner != null) {
- if ("<init>".equals(name)) {
- // Replace the invocation of a constructor with that of a static factory method.
- replaceConstructorUseWithFactoryMethod = true;
- opcode = Opcodes.INVOKESTATIC;
- // Assumes the re-mapped factory method names are in the convention create$<simplename>
- // defined in the desugar runtime library.
- name = "create$" + owner.substring(owner.lastIndexOf('/') + 1);
- desc =
- Type.getMethodType(Type.getObjectType(owner), Type.getArgumentTypes(desc))
- .getDescriptor();
- } else if (opcode != Opcodes.INVOKESTATIC) {
+ if (opcode != Opcodes.INVOKESTATIC) {
// assuming a static method
desc = InterfaceDesugaring.companionDefaultMethodDescriptor(owner, desc);
opcode = Opcodes.INVOKESTATIC;
@@ -125,19 +97,6 @@ public class CoreLibraryInvocationRewriter extends ClassVisitor {
}
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
-
- // Compared with the constructor invocation, a factory method invocation pushes (areturn) the
- // constructed object reference onto the operand stack of the invoker frame, leaving the
- // operand stack in state {uninitialized 0, uninitialized 0, objectref}, the following
- // instructions clears the extra values on the stack.
- //
- // TODO(b/144304047): Remove these extra byte code instructions once the preceding consecutive
- // {new, dup} instructions are stripped out.
- if (replaceConstructorUseWithFactoryMethod) {
- super.visitInsn(Opcodes.DUP_X2);
- super.visitInsn(Opcodes.POP);
- super.visitInsn(Opcodes.POP2);
- }
}
}
}
