Class KotlinSafeCallOperatorFilter

java.lang.Object
org.jacoco.core.internal.analysis.filter.KotlinSafeCallOperatorFilter
All Implemented Interfaces:
IFilter

final class KotlinSafeCallOperatorFilter extends Object implements IFilter
Filters bytecode that Kotlin compiler generates for chains of safe call operators (?.).
  • Constructor Details

    • KotlinSafeCallOperatorFilter

      KotlinSafeCallOperatorFilter()
  • Method Details

    • filter

      public void filter(org.objectweb.asm.tree.MethodNode methodNode, IFilterContext context, IFilterOutput output)
      Description copied from interface: IFilter
      This method is called for every method. The filter implementation is expected to inspect the provided method and report its result to the given IFilterOutput instance.
      Specified by:
      filter in interface IFilter
      Parameters:
      methodNode - method to inspect
      context - context information for the method
      output - callback to report filtering results to
    • findChains

      private static Collection<ArrayList<org.objectweb.asm.tree.JumpInsnNode>> findChains(org.objectweb.asm.tree.MethodNode methodNode)
      "optimized" chain:
      DUP
      IFNULL label
      ... // call 0
      
      ...
      
      DUP
      IFNULL label
      ... // call N
      
      label:
      POP
      
      "unoptimized" chain:
      ALOAD v0
      IFNULL label
      ... // call 0
      
      ...
      
      ASTORE v1
      ALOAD v1
      IFNULL label
      ... // call N
      
      label:
      ACONST_NULL
      
      "unoptimized" safe call operator(s) followed by elvis operator:
      ALOAD v0
      IFNULL nullCase
      ... // call 0
      
      ASTORE v1
      ALOAD v1
      IFNULL nullCase
      ... // call 1
      
      ...
      
      ASTORE vN
      ALOAD vN
      IFNULL nullCase
      ALOAD vN
      GOTO nonNullCase
      nullCase:
      ... // right hand side of elvis operator
      nonNullCase:
      ...
      
    • isUnoptimizedSafeCallFollowedByElvis

      private static boolean isUnoptimizedSafeCallFollowedByElvis(org.objectweb.asm.tree.JumpInsnNode jump, org.objectweb.asm.tree.AbstractInsnNode target, ArrayList<org.objectweb.asm.tree.JumpInsnNode> chain)
    • preceding

      private static org.objectweb.asm.tree.AbstractInsnNode preceding(org.objectweb.asm.tree.AbstractInsnNode i, int opcode)
      Returns:
      non pseudo-instruction preceding given if it has given opcode, null otherwise