Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56220168 authored by John Wu's avatar John Wu Committed by Android (Google) Code Review
Browse files

Merge "[HostStubGen] Support ignore policy on more methods" into main

parents 582028f6 4c2182d4
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -70,7 +70,7 @@ enum class FilterPolicy {
        get() = this == SubstituteAndStub || this == SubstituteAndKeep
        get() = this == SubstituteAndStub || this == SubstituteAndKeep


    val needsInStub: Boolean
    val needsInStub: Boolean
        get() = this == Stub || this == StubClass || this == SubstituteAndStub
        get() = this == Stub || this == StubClass || this == SubstituteAndStub || this == Ignore


    val needsInImpl: Boolean
    val needsInImpl: Boolean
        get() = this != Remove
        get() = this != Remove
+1 −0
Original line number Original line Diff line number Diff line
@@ -330,6 +330,7 @@ private fun parsePolicy(s: String): FilterPolicy {
        "r", "remove" -> FilterPolicy.Remove
        "r", "remove" -> FilterPolicy.Remove
        "sc", "stubclass" -> FilterPolicy.StubClass
        "sc", "stubclass" -> FilterPolicy.StubClass
        "kc", "keepclass" -> FilterPolicy.KeepClass
        "kc", "keepclass" -> FilterPolicy.KeepClass
        "i", "ignore" -> FilterPolicy.Ignore
        else -> {
        else -> {
            if (s.startsWith("@")) {
            if (s.startsWith("@")) {
                FilterPolicy.SubstituteAndStub
                FilterPolicy.SubstituteAndStub
+30 −14
Original line number Original line Diff line number Diff line
@@ -211,18 +211,11 @@ class ImplGeneratingAdapter(
            }
            }


            if (policy.policy == FilterPolicy.Ignore) {
            if (policy.policy == FilterPolicy.Ignore) {
                when (Type.getReturnType(descriptor)) {
                    Type.VOID_TYPE -> {
                log.v("Making method ignored...")
                log.v("Making method ignored...")
                return IgnoreMethodAdapter(
                return IgnoreMethodAdapter(
                    access, name, descriptor, signature, exceptions, innerVisitor)
                    access, name, descriptor, signature, exceptions, innerVisitor)
                    .withAnnotation(HostStubGenProcessedAsIgnore.CLASS_DESCRIPTOR)
                    .withAnnotation(HostStubGenProcessedAsIgnore.CLASS_DESCRIPTOR)
            }
            }
                    else -> {
                        throw RuntimeException("Ignored policy only allowed for void methods")
                    }
                }
            }
        }
        }
        if (substituted) {
        if (substituted) {
            innerVisitor?.withAnnotation(HostStubGenProcessedAsSubstitute.CLASS_DESCRIPTOR)
            innerVisitor?.withAnnotation(HostStubGenProcessedAsSubstitute.CLASS_DESCRIPTOR)
@@ -290,14 +283,37 @@ class ImplGeneratingAdapter(
     */
     */
    private inner class IgnoreMethodAdapter(
    private inner class IgnoreMethodAdapter(
            access: Int,
            access: Int,
            val name: String,
            name: String,
            descriptor: String,
            val descriptor: String,
            signature: String?,
            signature: String?,
            exceptions: Array<String>?,
            exceptions: Array<String>?,
            next: MethodVisitor?
            next: MethodVisitor?
    ) : BodyReplacingMethodVisitor(access, name, descriptor, signature, exceptions, next) {
    ) : BodyReplacingMethodVisitor(access, name, descriptor, signature, exceptions, next) {
        override fun emitNewCode() {
        override fun emitNewCode() {
            visitInsn(Opcodes.RETURN)
            when (Type.getReturnType(descriptor)) {
                Type.VOID_TYPE -> visitInsn(Opcodes.RETURN)
                Type.BOOLEAN_TYPE, Type.BYTE_TYPE, Type.CHAR_TYPE, Type.SHORT_TYPE,
                Type.INT_TYPE -> {
                    visitInsn(Opcodes.ICONST_0)
                    visitInsn(Opcodes.IRETURN)
                }
                Type.LONG_TYPE -> {
                    visitInsn(Opcodes.LCONST_0)
                    visitInsn(Opcodes.LRETURN)
                }
                Type.FLOAT_TYPE -> {
                    visitInsn(Opcodes.FCONST_0)
                    visitInsn(Opcodes.FRETURN)
                }
                Type.DOUBLE_TYPE -> {
                    visitInsn(Opcodes.DCONST_0)
                    visitInsn(Opcodes.DRETURN)
                }
                else -> {
                    visitInsn(Opcodes.ACONST_NULL)
                    visitInsn(Opcodes.ARETURN)
                }
            }
            visitMaxs(0, 0) // We let ASM figure them out.
            visitMaxs(0, 0) // We let ASM figure them out.
        }
        }
    }
    }
+127 −1
Original line number Original line Diff line number Diff line
@@ -1436,7 +1436,7 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPoli
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy
  super_class: #x                         // java/lang/Object
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 3, methods: 10, attributes: 1
  interfaces: 0, fields: 3, methods: 19, attributes: 1
  public int stub;
  public int stub;
    descriptor: I
    descriptor: I
    flags: (0x0001) ACC_PUBLIC
    flags: (0x0001) ACC_PUBLIC
@@ -1513,6 +1513,132 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPoli
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;
            0       8     1   foo   Ljava/lang/String;
            0       8     1   foo   Ljava/lang/String;


  public java.lang.String toBeIgnoredObj();
    descriptor: ()Ljava/lang/String;
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public void toBeIgnoredV();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public boolean toBeIgnoredZ();
    descriptor: ()Z
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public byte toBeIgnoredB();
    descriptor: ()B
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public char toBeIgnoredC();
    descriptor: ()C
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public short toBeIgnoredS();
    descriptor: ()S
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public int toBeIgnoredI();
    descriptor: ()I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public float toBeIgnoredF();
    descriptor: ()F
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public double toBeIgnoredD();
    descriptor: ()D
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public int addTwo(int);
  public int addTwo(int);
    descriptor: (I)I
    descriptor: (I)I
    flags: (0x0001) ACC_PUBLIC
    flags: (0x0001) ACC_PUBLIC
+145 −1
Original line number Original line Diff line number Diff line
@@ -1197,7 +1197,7 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPoli
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy
  super_class: #x                         // java/lang/Object
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 1, methods: 5, attributes: 2
  interfaces: 0, fields: 1, methods: 14, attributes: 2
  public int stub;
  public int stub;
    descriptor: I
    descriptor: I
    flags: (0x0001) ACC_PUBLIC
    flags: (0x0001) ACC_PUBLIC
@@ -1239,6 +1239,150 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPoli
      x: #x()
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl


  public java.lang.String toBeIgnoredObj();
    descriptor: ()Ljava/lang/String;
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public void toBeIgnoredV();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public boolean toBeIgnoredZ();
    descriptor: ()Z
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public byte toBeIgnoredB();
    descriptor: ()B
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public char toBeIgnoredC();
    descriptor: ()C
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public short toBeIgnoredS();
    descriptor: ()S
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public int toBeIgnoredI();
    descriptor: ()I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public float toBeIgnoredF();
    descriptor: ()F
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public double toBeIgnoredD();
    descriptor: ()D
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public int addTwo(int);
  public int addTwo(int);
    descriptor: (I)I
    descriptor: (I)I
    flags: (0x0001) ACC_PUBLIC
    flags: (0x0001) ACC_PUBLIC
Loading