Class TemplateAstMatcher

java.lang.Object
com.google.javascript.jscomp.TemplateAstMatcher

public final class TemplateAstMatcher extends 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 Details

    • 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 Details

    • 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 Map<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.