public static List < AbstractInsnNode > findInvocationsOf ( InsnList insnList , Method expectedMethod ) { Validate . notNull ( insnList ) ; Validate . notNull ( expectedMethod ) ; List < AbstractInsnNode > ret = new ArrayList <> ( ) ; Type expectedMethodDesc = Type . getType ( expectedMethod ) ; Type expectedMethodOwner = Type . getType ( expectedMethod . getDeclaringClass ( ) ) ; String expectedMethodName = expectedMethod . getName ( ) ; Iterator < AbstractInsnNode > it = insnList . iterator ( ) ; while ( it . hasNext ( ) ) { AbstractInsnNode instructionNode = it . next ( ) ; Type methodDesc ; Type methodOwner ; String methodName ; if ( instructionNode instanceof MethodInsnNode ) { MethodInsnNode methodInsnNode = ( MethodInsnNode ) instructionNode ; methodDesc = Type . getType ( methodInsnNode . desc ) ; methodOwner = Type . getObjectType ( methodInsnNode . owner ) ; methodName = expectedMethod . getName ( ) ; } else { continue ; } if ( methodDesc . equals ( expectedMethodDesc ) && methodOwner . equals ( expectedMethodOwner ) && methodName . equals ( expectedMethodName ) ) { ret . add ( instructionNode ) ; } } return ret ; }
Find invocations of a certain method .