Class SuggestedFix.Builder
java.lang.Object
com.google.javascript.refactoring.SuggestedFix.Builder
- Enclosing class:
SuggestedFix
Builder class for
SuggestedFix
that contains helper functions to manipulate JS nodes.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAlternative
(SuggestedFix alternative) addCast
(Node n, AbstractCompiler compiler, String type) Adds a cast of the given type to the provided node.addChildToFront
(Node parentNode, String content) Inserts a new node as the first child of the provided node.addGoogRequire
(Match m, String namespace, ScriptMetadata scriptMetadata) addGoogRequireType
(Match m, String namespace, ScriptMetadata scriptMetadata) addImport
(Match m, String namespace, com.google.javascript.refactoring.SuggestedFix.ImportType importType, ScriptMetadata scriptMetadata) Adds a goog.require/requireType for the given namespace if it does not already exist.addOrReplaceJsDoc
(Node n, String newJsDoc) Adds or replaces the JS Doc for the given node.attachMatchedNodeInfo
(Node node, AbstractCompiler compiler) Sets the node on this SuggestedFix that caused this SuggestedFix to be built in the first place.build()
changeJsDocType
(Node n, AbstractCompiler compiler, String type) Changes the JS Doc Type of the given node.Deletes a node and its contents from the source file.deleteArgument
(Node n, int position) Deletes an argument from an existing function call, including any JS doc that precedes it.Deletes a node without touching any surrounding whitespace.Deletes a node and its contents from the source file.generateCode
(AbstractCompiler compiler, Node node) insertAfter
(Node node, String text) Inserts the text after the given nodeinsertArguments
(Node n, int position, String... args) Inserts arguments into an existing function call.insertBefore
(Node nodeToInsertBefore, Node n, AbstractCompiler compiler) Inserts a new node before the provided node.insertBefore
(Node nodeToInsertBefore, String content) Inserts a string before the provided node.removeCast
(Node n, AbstractCompiler compiler) Removes a cast from the given node.removeGoogRequire
(Match m, String namespace) Removes a goog.require for the given namespace to the file if it already exists.Renames a given node to the provided name.Renames a given node to the provided name.replace
(Node original, Node newNode, AbstractCompiler compiler) Replaces the provided node with new node in the source file.replaceRange
(Node first, Node last, String newContent) Replaces a range of nodes with the given content.setDescription
(String description)
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
attachMatchedNodeInfo
Sets the node on this SuggestedFix that caused this SuggestedFix to be built in the first place. -
addAlternative
-
addChildToFront
Inserts a new node as the first child of the provided node. -
insertAfter
Inserts the text after the given node -
insertBefore
public SuggestedFix.Builder insertBefore(Node nodeToInsertBefore, Node n, AbstractCompiler compiler) Inserts a new node before the provided node. -
insertBefore
Inserts a string before the provided node. This is useful for inserting comments into a file since the JS Compiler doesn't currently support printing comments. -
delete
Deletes a node and its contents from the source file. If the node is a child of a block or top level statement, this will also delete the whitespace before the node. -
deleteWithoutRemovingWhitespaceBefore
Deletes a node and its contents from the source file. -
deleteWithoutRemovingWhitespace
Deletes a node without touching any surrounding whitespace. -
rename
Renames a given node to the provided name.- Parameters:
n
- The node to rename.name
- The new name for the node.
-
rename
Renames a given node to the provided name.- Parameters:
n
- The node to rename.name
- The new name for the node.replaceNameSubtree
- True to replace the entire name subtree below the node. The default is to replace just the last property in the node with the new name. For instance, ifreplaceNameSubtree
is false, thenthis.foo()
will be renamed tothis.bar()
. However, if it is true, it will be renamed tobar()
.
-
replaceRange
Replaces a range of nodes with the given content. -
replace
Replaces the provided node with new node in the source file. -
addCast
Adds a cast of the given type to the provided node. -
removeCast
Removes a cast from the given node. -
addOrReplaceJsDoc
Adds or replaces the JS Doc for the given node. -
changeJsDocType
Changes the JS Doc Type of the given node. -
insertArguments
Inserts arguments into an existing function call. -
deleteArgument
Deletes an argument from an existing function call, including any JS doc that precedes it. WARNING: If jsdoc erroneously follows the argument, it will not be removed as the parser considers the comment to belong to the next argument. -
addGoogRequire
public SuggestedFix.Builder addGoogRequire(Match m, String namespace, ScriptMetadata scriptMetadata) -
addGoogRequireType
public SuggestedFix.Builder addGoogRequireType(Match m, String namespace, ScriptMetadata scriptMetadata) -
addImport
public SuggestedFix.Builder addImport(Match m, String namespace, com.google.javascript.refactoring.SuggestedFix.ImportType importType, ScriptMetadata scriptMetadata) Adds a goog.require/requireType for the given namespace if it does not already exist. -
removeGoogRequire
Removes a goog.require for the given namespace to the file if it already exists. -
generateCode
-
setDescription
-
build
-