public final class RefasterJsScanner extends Scanner
Modifier and Type | Class and Description |
---|---|
private static class |
RefasterJsScanner.RefasterJsTemplate
Class that holds the before and after templates for a given RefasterJs refactoring.
|
Modifier and Type | Field and Description |
---|---|
private RefasterJsScanner.RefasterJsTemplate |
matchedTemplate
The RefasterJsTemplate that matched the last Match.
|
private java.lang.String |
templateJs
The JS code that contains the RefasterJs templates.
|
private com.google.common.collect.ImmutableList<RefasterJsScanner.RefasterJsTemplate> |
templates
All templates that were found in the template file.
|
Constructor and Description |
---|
RefasterJsScanner() |
Modifier and Type | Method and Description |
---|---|
(package private) void |
initialize(AbstractCompiler compiler)
Initializes the Scanner class by loading the template JS file, compiling it, and then
finding all matching RefasterJs template functions in the file.
|
void |
loadRefasterJsTemplate(java.lang.String refasterjsTemplate)
Loads the RefasterJs template.
|
void |
loadRefasterJsTemplateFromCode(java.lang.String refasterJsTemplate)
Loads the RefasterJs template.
|
boolean |
matches(Node node,
NodeMetadata metadata)
Returns true if the given node and node traversal should match for this
particular scanner.
|
java.util.List<SuggestedFix> |
processMatch(Match match)
Processes one
Match at a time. |
private Node |
transformNode(Node templateNode,
java.util.Map<java.lang.String,Node> templateNodeToMatchMap)
Transforms the template node to a replacement node by mapping the template names to
the ones that were matched against in the JsSourceMatcher.
|
processAllMatches
private java.lang.String templateJs
private com.google.common.collect.ImmutableList<RefasterJsScanner.RefasterJsTemplate> templates
private RefasterJsScanner.RefasterJsTemplate matchedTemplate
public void loadRefasterJsTemplate(java.lang.String refasterjsTemplate) throws java.io.IOException
java.io.IOException
public void loadRefasterJsTemplateFromCode(java.lang.String refasterJsTemplate) throws java.io.IOException
java.io.IOException
public boolean matches(Node node, NodeMetadata metadata)
Scanner
Matcher
class
or predefined matchers from Matchers
to match against the Node and
NodeMetadata.
If this function returns true, a Match
for this node will be passed
to Scanner.processMatch(Match)
and all matches will be passed to
Scanner.processAllMatches(Collection)
at the end of the traversal.public java.util.List<SuggestedFix> processMatch(Match match)
Scanner
Match
at a time. There is no order guaranteed for
when this function will be called with the Match.processMatch
in class Scanner
match
- The Match
from the node and traversal for any match
that Scanner.matches(com.google.javascript.rhino.Node, com.google.javascript.refactoring.NodeMetadata)
returned true for.SuggestedFix
classes that will be applied to the
source files at the end of the run to create the refactoring CL.private Node transformNode(Node templateNode, java.util.Map<java.lang.String,Node> templateNodeToMatchMap)
void initialize(AbstractCompiler compiler) throws java.lang.Exception
java.lang.Exception