Class Patterns


  • public final class Patterns
    extends Object
    Factory for common pattern matchers.
    • Method Detail

      • anyMethodCall

        public static PatternMatcher anyMethodCall()
        Matches any method call.
        Returns:
        a matcher accepting every invoke instruction
      • methodCallTo

        public static PatternMatcher methodCallTo​(String ownerClass)
        Matches method calls to a specific owner class.
        Parameters:
        ownerClass - the owner name an invoke must declare
        Returns:
        a matcher accepting invokes on that owner
      • methodCallNamed

        public static PatternMatcher methodCallNamed​(String methodName)
        Matches method calls with a specific name.
        Parameters:
        methodName - the method name an invoke must carry
        Returns:
        a matcher accepting invokes with that name
      • methodCall

        public static PatternMatcher methodCall​(String ownerClass,
                                                String methodName)
        Matches method calls to a specific owner and method name.
        Parameters:
        ownerClass - the owner name an invoke must declare
        methodName - the method name an invoke must carry
        Returns:
        a matcher accepting invokes matching both
      • methodCallOwnerMatching

        public static PatternMatcher methodCallOwnerMatching​(String regex)
        Matches method calls with owner matching a regex pattern.
        Parameters:
        regex - the expression the whole owner name must match
        Returns:
        a matcher accepting invokes whose owner matches
      • methodCallNameMatching

        public static PatternMatcher methodCallNameMatching​(String regex)
        Matches method calls with name matching a regex pattern.
        Parameters:
        regex - the expression the whole method name must match
        Returns:
        a matcher accepting invokes whose name matches
      • staticMethodCall

        public static PatternMatcher staticMethodCall()
        Matches static method calls.
        Returns:
        a matcher accepting invokestatic instructions
      • virtualMethodCall

        public static PatternMatcher virtualMethodCall()
        Matches virtual and interface method calls.
        Returns:
        a matcher accepting invokevirtual and invokeinterface instructions
      • dynamicCall

        public static PatternMatcher dynamicCall()
        Matches invokedynamic calls.
        Returns:
        a matcher accepting invokedynamic instructions
      • anyFieldRead

        public static PatternMatcher anyFieldRead()
        Matches any field read.
        Returns:
        a matcher accepting loading field accesses
      • anyFieldWrite

        public static PatternMatcher anyFieldWrite()
        Matches any field write.
        Returns:
        a matcher accepting storing field accesses
      • fieldAccessOn

        public static PatternMatcher fieldAccessOn​(String ownerClass)
        Matches field access (read or write) on a specific owner.
        Parameters:
        ownerClass - the owner name a field access must declare
        Returns:
        a matcher accepting field accesses on that owner
      • fieldNamed

        public static PatternMatcher fieldNamed​(String fieldName)
        Matches field access with a specific field name.
        Parameters:
        fieldName - the field name an access must carry
        Returns:
        a matcher accepting field accesses with that name
      • anyInstanceOf

        public static PatternMatcher anyInstanceOf()
        Matches instanceof checks.
        Returns:
        a matcher accepting instanceof type checks
      • instanceOf

        public static PatternMatcher instanceOf​(String typeName)
        Matches instanceof checks for a specific type.
        Parameters:
        typeName - the internal name the checked reference type must have
        Returns:
        a matcher accepting instanceof checks against that type
      • anyCast

        public static PatternMatcher anyCast()
        Matches cast instructions.
        Returns:
        a matcher accepting checkcast type checks
      • castTo

        public static PatternMatcher castTo​(String typeName)
        Matches casts to a specific type.
        Parameters:
        typeName - the internal name the cast target reference type must have
        Returns:
        a matcher accepting casts to that type
      • anyNew

        public static PatternMatcher anyNew()
        Matches any object allocation.
        Returns:
        a matcher accepting new instructions
      • newInstance

        public static PatternMatcher newInstance​(String className)
        Matches allocation of a specific class.
        Parameters:
        className - the allocated class name to match
        Returns:
        a matcher accepting allocations of that class
      • anyNewArray

        public static PatternMatcher anyNewArray()
        Matches any array allocation.
        Returns:
        a matcher accepting array allocation instructions
      • nullCheck

        public static PatternMatcher nullCheck()
        Matches null comparisons in branches.
        Returns:
        a matcher accepting equality branches with a null operand
      • anyThrow

        public static PatternMatcher anyThrow()
        Matches throw instructions.
        Returns:
        a matcher accepting athrow instructions
      • anyReturn

        public static PatternMatcher anyReturn()
        Matches return instructions.
        Returns:
        a matcher accepting return instructions
      • and

        public static PatternMatcher and​(PatternMatcher... matchers)
        Combines patterns with AND logic.
        Parameters:
        matchers - the matchers that must all accept
        Returns:
        a matcher accepting only when every operand accepts
      • or

        public static PatternMatcher or​(PatternMatcher... matchers)
        Combines patterns with OR logic.
        Parameters:
        matchers - the matchers of which one must accept
        Returns:
        a matcher accepting when any operand accepts
      • not

        public static PatternMatcher not​(PatternMatcher matcher)
        Negates a pattern.
        Parameters:
        matcher - the matcher to invert
        Returns:
        a matcher accepting exactly what the operand rejects