public final class TemplateAstMatcher
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static interface |
TemplateAstMatcher.Visitor |
Modifier and Type | Field and Description |
---|---|
private AbstractCompiler |
compiler |
private boolean |
isLooseMatch
Record whether the last successful was a loosely matched type, only valid
for the last match if it was successful.
|
private java.util.ArrayList<java.lang.String> |
localVarMatches
Record the first name to match a template local variable, only valid for
the last match if it was successful.
|
private java.util.ArrayList<Node> |
paramNodeMatches
Record the first Node to match a template parameter, only valid for
the last match if it was successful.
|
private static int |
TEMPLATE_LOCAL_NAME |
private static int |
TEMPLATE_TYPE_PARAM |
private java.util.List<java.lang.String> |
templateLocals
The locals declared in the template (in order)
|
private java.util.List<java.lang.String> |
templateParams
The params declared in the template (in order)
|
private Node |
templateStart
The head of the Node list that should be used to start the matching
process.
|
private TypeMatchingStrategy |
typeMatchingStrategy
The strategy to use when matching the
JSType of nodes. |
Constructor and Description |
---|
TemplateAstMatcher(AbstractCompiler compiler,
Node templateFunctionNode)
Constructs this matcher with a Function node that serves as the template
to match all other nodes against.
|
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.
|
Modifier and Type | Method and Description |
---|---|
private Node |
createTemplateLocalNameNode(int index) |
private Node |
createTemplateParameterNode(int index,
JSType type) |
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.
|
private Node |
initTemplate(Node templateFunctionNode)
Prepare an template AST to use when performing matches.
|
boolean |
isLooseMatch() |
private boolean |
isTemplateLocalNameNode(Node n) |
private boolean |
isTemplateParameterNode(Node n) |
boolean |
matches(Node n) |
private boolean |
matchesNode(Node template,
Node ast)
Returns whether two nodes are equivalent, taking into account the template
parameters that were provided to this matcher.
|
private boolean |
matchesNodeShape(Node template,
Node ast) |
private boolean |
matchesTemplate(Node template,
Node ast) |
private boolean |
matchesTemplateShape(Node template,
Node ast)
Returns whether the template matches an AST structure node starting with
node, taking into account the template parameters that were provided to
this matcher.
|
private void |
prepTemplatePlaceholders(Node fn)
Build parameter and local information for the template and replace
the references in the template 'fn' with placeholder nodes use to
facility matching.
|
(package private) void |
replaceNodeInPlace(Node n,
Node replacement) |
private void |
reset() |
private void |
traverse(Node n,
TemplateAstMatcher.Visitor callback) |
private static final int TEMPLATE_TYPE_PARAM
private static final int TEMPLATE_LOCAL_NAME
private final AbstractCompiler compiler
private final Node templateStart
private final java.util.List<java.lang.String> templateParams
private final java.util.ArrayList<Node> paramNodeMatches
private final java.util.List<java.lang.String> templateLocals
private final java.util.ArrayList<java.lang.String> localVarMatches
private boolean isLooseMatch
private TypeMatchingStrategy typeMatchingStrategy
JSType
of nodes.public TemplateAstMatcher(AbstractCompiler compiler, Node templateFunctionNode)
public TemplateAstMatcher(AbstractCompiler compiler, Node templateFunctionNode, TypeMatchingStrategy typeMatchingStrategy)
public boolean matches(Node n)
n
- The node to check.public boolean isLooseMatch()
public java.util.Map<java.lang.String,Node> getTemplateNodeToMatchMap()
private Node initTemplate(Node templateFunctionNode)
templateFunctionNode
- The template declaration function to extract
the template AST from.private void prepTemplatePlaceholders(Node fn)
private void traverse(Node n, TemplateAstMatcher.Visitor callback)
private void reset()
private boolean isTemplateParameterNode(Node n)
private boolean isTemplateLocalNameNode(Node n)
private Node createTemplateLocalNameNode(int index)
private boolean matchesTemplateShape(Node template, Node ast)
private boolean matchesNode(Node template, Node ast)