Class Matchers
- java.lang.Object
-
- com.google.javascript.refactoring.Matchers
-
public final class Matchers extends java.lang.Object
Class that contains common Matchers that are useful to everyone.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Matcher
allOf(Matcher... matchers)
Returns a Matcher that returns true only if all of the provided matchers match.static Matcher
anyOf(Matcher... matchers)
Returns a Matcher that returns true if any of the provided matchers match.static Matcher
anything()
Returns a Matcher that matches every node.static Matcher
assignmentWithRhs(Matcher rhsMatcher)
Returns a Matcher that matches an ASSIGN node where the RHS of the assignment matches the given rhsMatcher.static Matcher
constructor()
Returns a matcher that matches any constructor definitions.static Matcher
constructor(@Nullable java.lang.String name)
Returns a matcher that matches constructor definitions of the specified name.static Matcher
constructorPropertyDeclaration()
Returns a Matcher that matches against properties that are declared in the constructor.static Matcher
enumDefinition()
Returns a Matcher that matches definitions of any enum.static Matcher
enumDefinitionOfType(java.lang.String type)
Returns a Matcher that matches definitions of an enum of the given type.static Matcher
functionCall()
Returns a Matcher that matches any function call.static Matcher
functionCall(@Nullable java.lang.String name)
Returns a Matcher that matches all nodes that are function calls that match the provided name.static Matcher
functionCallWithNumArgs(int numArgs)
Returns a Matcher that matches any function call that has the given number of arguments.static Matcher
functionCallWithNumArgs(java.lang.String name, int numArgs)
Returns a Matcher that matches any function call that has the given number of arguments and the given name.static Matcher
googForwardDeclare()
static Matcher
googModule()
static Matcher
googModuleOrProvide()
static Matcher
googRequire()
static Matcher
googRequirelike()
static Matcher
googRequirelike(java.lang.String namespace)
static Matcher
googRequireType()
static Matcher
isPrivate()
Returns a Matcher that matches against nodes that are declared@private
.static Matcher
jsDocType(java.lang.String type)
Returns a Matcher that matches nodes that contain JS Doc that specify the@type
annotation equivalent to the provided type.static Matcher
newClass()
Returns a Matcher that matches constructing new objects.static Matcher
newClass(java.lang.String className)
Returns a Matcher that matches constructing objects of the provided class name.static Matcher
not(Matcher matcher)
Returns a Matcher that matches the opposite of the provided matcher.static Matcher
propertyAccess()
Returns a Matcher that matches any property access.static Matcher
propertyAccess(@Nullable java.lang.String name)
Returns a Matcher that matches nodes representing a GETPROP access of an object property.static Matcher
prototypeMethodDeclaration()
Returns a Matcher that matches a declaration of a method on the prototype of a class.static Matcher
prototypeVariableDeclaration()
Returns a Matcher that matches a declaration of a variable on the prototype of a class.
-
-
-
Method Detail
-
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 java.lang.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(java.lang.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 java.lang.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 matchappContext.get
andthis.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(java.lang.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 matchappContext.get
andthis.get
when called from the AppContext class.
-
googRequirelike
public static Matcher googRequirelike(java.lang.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 java.lang.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 matchappContext.root
andthis.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(java.lang.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(java.lang.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
.
-
-