Class Matchers

java.lang.Object
com.google.javascript.refactoring.Matchers

public final class Matchers extends Object
Class that contains common Matchers that are useful to everyone.
  • Method Details

    • anything

      public static Matcher anything()
      Returns a Matcher that matches every node.
    • allOf

      public static Matcher allOf(Matcher... matchers)
      Returns a Matcher that returns true only if all of the provided matchers match.
    • anyOf

      public static Matcher anyOf(Matcher... matchers)
      Returns a Matcher that returns true if any of the provided matchers match.
    • not

      public static Matcher not(Matcher matcher)
      Returns a Matcher that matches the opposite of the provided matcher.
    • constructor

      public static Matcher constructor()
      Returns a matcher that matches any constructor definitions.
    • constructor

      public static Matcher constructor(@Nullable String name)
      Returns a matcher that matches constructor definitions of the specified name.
      Parameters:
      name - The name of the class constructor to match.
    • newClass

      public static Matcher newClass()
      Returns a Matcher that matches constructing new objects. This will match the NEW node of the JS Compiler AST.
    • newClass

      public static Matcher newClass(String className)
      Returns a Matcher that matches constructing objects of the provided class name. This will match the NEW node of the JS Compiler AST.
      Parameters:
      className - The name of the class to return matching NEW nodes.
    • functionCall

      public static Matcher functionCall()
      Returns a Matcher that matches any function call.
    • functionCall

      public static Matcher functionCall(@Nullable String name)
      Returns a Matcher that matches all nodes that are function calls that match the provided name.
      Parameters:
      name - The name of the function to match. For non-static functions, this must be the fully qualified name that includes the type of the object. For instance: ns.AppContext.prototype.get will match appContext.get and this.get when called from the AppContext class.
    • functionCallWithNumArgs

      public static Matcher functionCallWithNumArgs(int numArgs)
      Returns a Matcher that matches any function call that has the given number of arguments.
    • functionCallWithNumArgs

      public static Matcher functionCallWithNumArgs(String name, int numArgs)
      Returns a Matcher that matches any function call that has the given number of arguments and the given name.
      Parameters:
      name - The name of the function to match. For non-static functions, this must be the fully qualified name that includes the type of the object. For instance: ns.AppContext.prototype.get will match appContext.get and this.get when called from the AppContext class.
    • googRequirelike

      public static Matcher googRequirelike(String namespace)
    • googRequirelike

      public static Matcher googRequirelike()
    • googRequire

      public static Matcher googRequire()
    • googRequireType

      public static Matcher googRequireType()
    • googForwardDeclare

      public static Matcher googForwardDeclare()
    • googModule

      public static Matcher googModule()
    • googModuleOrProvide

      public static Matcher googModuleOrProvide()
    • propertyAccess

      public static Matcher propertyAccess()
      Returns a Matcher that matches any property access.
    • propertyAccess

      public static Matcher propertyAccess(@Nullable String name)
      Returns a Matcher that matches nodes representing a GETPROP access of an object property.
      Parameters:
      name - The name of the property to match. For non-static properties, this must be the fully qualified name that includes the type of the object. For instance: ns.AppContext.prototype.root will match appContext.root and this.root when accessed from the AppContext.
    • enumDefinition

      public static Matcher enumDefinition()
      Returns a Matcher that matches definitions of any enum.
    • enumDefinitionOfType

      public static Matcher enumDefinitionOfType(String type)
      Returns a Matcher that matches definitions of an enum of the given type.
    • assignmentWithRhs

      public static Matcher assignmentWithRhs(Matcher rhsMatcher)
      Returns a Matcher that matches an ASSIGN node where the RHS of the assignment matches the given rhsMatcher.
    • prototypeVariableDeclaration

      public static Matcher prototypeVariableDeclaration()
      Returns a Matcher that matches a declaration of a variable on the prototype of a class.
    • prototypeMethodDeclaration

      public static Matcher prototypeMethodDeclaration()
      Returns a Matcher that matches a declaration of a method on the prototype of a class.
    • jsDocType

      public static Matcher jsDocType(String type)
      Returns a Matcher that matches nodes that contain JS Doc that specify the @type annotation equivalent to the provided type.
    • constructorPropertyDeclaration

      public static Matcher constructorPropertyDeclaration()
      Returns a Matcher that matches against properties that are declared in the constructor.
    • isPrivate

      public static Matcher isPrivate()
      Returns a Matcher that matches against nodes that are declared @private.