Class RefasterJsScanner
- java.lang.Object
-
- com.google.javascript.refactoring.Scanner
-
- com.google.javascript.refactoring.RefasterJsScanner
-
- All Implemented Interfaces:
java.io.Serializable
public final class RefasterJsScanner extends Scanner
Class that drives the RefasterJs refactoring by matching against a provided template JS file and then applying a transformation based off the template JS.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RefasterJsScanner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearTemplates()
Clears the RefasterJs templates used for comparison.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.com.google.common.collect.ImmutableList<SuggestedFix>
processMatch(Match match)
Processes oneMatch
at a time.void
setTypeMatchingStrategy(TypeMatchingStrategy typeMatchingStrategy)
Sets the type matching strategy to use when matching templates.-
Methods inherited from class com.google.javascript.refactoring.Scanner
processAllMatches
-
-
-
-
Method Detail
-
loadRefasterJsTemplate
public void loadRefasterJsTemplate(java.lang.String refasterjsTemplate) throws java.io.IOException
Loads the RefasterJs template. This must be called before the scanner is used.- Throws:
java.io.IOException
-
setTypeMatchingStrategy
public void setTypeMatchingStrategy(TypeMatchingStrategy typeMatchingStrategy)
Sets the type matching strategy to use when matching templates.Defaults to
TypeMatchingStrategy.SUBTYPES
.
-
loadRefasterJsTemplateFromCode
public void loadRefasterJsTemplateFromCode(java.lang.String refasterJsTemplate) throws java.io.IOException
Loads the RefasterJs template. This must be called before the scanner is used.- Throws:
java.io.IOException
-
clearTemplates
public void clearTemplates()
Clears the RefasterJs templates used for comparison. This function should be called if this class is going to be used with multiple Compiler objects since type comparison is dependent on the compiler used to generate the types.
-
matches
public boolean matches(Node node, NodeMetadata metadata)
Description copied from class:Scanner
Returns true if the given node and node traversal should match for this particular scanner. Typically this function uses theMatcher
class or predefined matchers fromMatchers
to match against the Node and NodeMetadata. If this function returns true, aMatch
for this node will be passed toScanner.processMatch(Match)
and all matches will be passed toScanner.processAllMatches(Collection)
at the end of the traversal.
-
processMatch
public com.google.common.collect.ImmutableList<SuggestedFix> processMatch(Match match)
Description copied from class:Scanner
Processes oneMatch
at a time. There is no order guaranteed for when this function will be called with the Match.- Overrides:
processMatch
in classScanner
- Parameters:
match
- TheMatch
from the node and traversal for any match thatScanner.matches(com.google.javascript.rhino.Node, com.google.javascript.refactoring.NodeMetadata)
returned true for.- Returns:
- List of
SuggestedFix
classes that will be applied to the source files at the end of the run to create the refactoring CL.
-
-