Package com.google.javascript.jscomp
Class TemplateAstMatcher
- java.lang.Object
-
- com.google.javascript.jscomp.TemplateAstMatcher
-
public final class TemplateAstMatcher extends java.lang.Object
A matcher that can take an arbitrary AST and use it as a template to find matches in another. As this matcher potentially matches against every node in the AST it is tuned to avoid generating GC garbage. It first checks the AST shape without types and then successful checks the associated types.
-
-
Constructor Summary
Constructors Constructor Description TemplateAstMatcher(AbstractCompiler compiler, Node templateFunctionNode, TypeMatchingStrategy typeMatchingStrategy)
Constructs this matcher with a Function node that serves as the template to match all other nodes against.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,Node>
getTemplateNodeToMatchMap()
Returns a map from named template Nodes (such as parameters or local variables) to Nodes that were matches from the last matched template.boolean
isLooseMatch()
boolean
matches(Node n)
-
-
-
Constructor Detail
-
TemplateAstMatcher
public TemplateAstMatcher(AbstractCompiler compiler, Node templateFunctionNode, TypeMatchingStrategy typeMatchingStrategy)
Constructs this matcher with a Function node that serves as the template to match all other nodes against. The body of the function will be used to match against.
-
-
Method Detail
-
matches
public boolean matches(Node n)
- Parameters:
n
- The node to check.- Returns:
- Whether the node is matches the template.
-
isLooseMatch
public boolean isLooseMatch()
- Returns:
- Whether the last match succeeded due to loose type information.
-
getTemplateNodeToMatchMap
public java.util.Map<java.lang.String,Node> getTemplateNodeToMatchMap()
Returns a map from named template Nodes (such as parameters or local variables) to Nodes that were matches from the last matched template.
-
-