Class SuggestedFix.Builder
- java.lang.Object
-
- com.google.javascript.refactoring.SuggestedFix.Builder
-
- Enclosing class:
- SuggestedFix
public static final class SuggestedFix.Builder extends java.lang.Object
Builder class forSuggestedFix
that contains helper functions to manipulate JS nodes.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SuggestedFix.Builder
addAlternative(SuggestedFix alternative)
SuggestedFix.Builder
addCast(Node n, AbstractCompiler compiler, java.lang.String type)
Adds a cast of the given type to the provided node.SuggestedFix.Builder
addChildToFront(Node parentNode, java.lang.String content)
Inserts a new node as the first child of the provided node.SuggestedFix.Builder
addGoogRequire(Match m, java.lang.String namespace, ScriptMetadata scriptMetadata)
SuggestedFix.Builder
addGoogRequireType(Match m, java.lang.String namespace, ScriptMetadata scriptMetadata)
SuggestedFix.Builder
addImport(Match m, java.lang.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.SuggestedFix.Builder
addOrReplaceJsDoc(Node n, java.lang.String newJsDoc)
Adds or replaces the JS Doc for the given node.SuggestedFix.Builder
attachMatchedNodeInfo(Node node, AbstractCompiler compiler)
Sets the node on this SuggestedFix that caused this SuggestedFix to be built in the first place.SuggestedFix
build()
SuggestedFix.Builder
changeJsDocType(Node n, AbstractCompiler compiler, java.lang.String type)
Changes the JS Doc Type of the given node.SuggestedFix.Builder
delete(Node n)
Deletes a node and its contents from the source file.SuggestedFix.Builder
deleteArgument(Node n, int position)
Deletes an argument from an existing function call, including any JS doc that precedes it.SuggestedFix.Builder
deleteWithoutRemovingWhitespace(Node n)
Deletes a node without touching any surrounding whitespace.SuggestedFix.Builder
deleteWithoutRemovingWhitespaceBefore(Node n)
Deletes a node and its contents from the source file.java.lang.String
generateCode(AbstractCompiler compiler, Node node)
SuggestedFix.Builder
insertAfter(Node node, java.lang.String text)
Inserts the text after the given nodeSuggestedFix.Builder
insertArguments(Node n, int position, java.lang.String... args)
Inserts arguments into an existing function call.SuggestedFix.Builder
insertBefore(Node nodeToInsertBefore, Node n, AbstractCompiler compiler)
Inserts a new node before the provided node.SuggestedFix.Builder
insertBefore(Node nodeToInsertBefore, java.lang.String content)
Inserts a string before the provided node.SuggestedFix.Builder
removeCast(Node n, AbstractCompiler compiler)
Removes a cast from the given node.SuggestedFix.Builder
removeGoogRequire(Match m, java.lang.String namespace)
Removes a goog.require for the given namespace to the file if it already exists.SuggestedFix.Builder
rename(Node n, java.lang.String name)
Renames a given node to the provided name.SuggestedFix.Builder
rename(Node n, java.lang.String name, boolean replaceEntireName)
Renames a given node to the provided name.SuggestedFix.Builder
replace(Node original, Node newNode, AbstractCompiler compiler)
Replaces the provided node with new node in the source file.SuggestedFix.Builder
replaceRange(Node first, Node last, java.lang.String newContent)
Replaces a range of nodes with the given content.SuggestedFix.Builder
setDescription(java.lang.String description)
-
-
-
Method Detail
-
attachMatchedNodeInfo
public SuggestedFix.Builder attachMatchedNodeInfo(Node node, AbstractCompiler compiler)
Sets the node on this SuggestedFix that caused this SuggestedFix to be built in the first place.
-
addAlternative
public SuggestedFix.Builder addAlternative(SuggestedFix alternative)
-
addChildToFront
public SuggestedFix.Builder addChildToFront(Node parentNode, java.lang.String content)
Inserts a new node as the first child of the provided node.
-
insertAfter
public SuggestedFix.Builder insertAfter(Node node, java.lang.String text)
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
public SuggestedFix.Builder insertBefore(Node nodeToInsertBefore, java.lang.String content)
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
public SuggestedFix.Builder delete(Node n)
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
public SuggestedFix.Builder deleteWithoutRemovingWhitespaceBefore(Node n)
Deletes a node and its contents from the source file.
-
deleteWithoutRemovingWhitespace
public SuggestedFix.Builder deleteWithoutRemovingWhitespace(Node n)
Deletes a node without touching any surrounding whitespace.
-
rename
public SuggestedFix.Builder rename(Node n, java.lang.String name)
Renames a given node to the provided name.- Parameters:
n
- The node to rename.name
- The new name for the node.
-
rename
public SuggestedFix.Builder rename(Node n, java.lang.String name, boolean replaceEntireName)
Renames a given node to the provided name.- Parameters:
n
- The node to rename.name
- The new name for the node.replaceEntireName
- True to replace the entire name of the node. The default is to replace just the last property in the node with the new name. For instance, ifreplaceEntireName
is false, thenthis.foo()
will be renamed tothis.bar()
. However, if it is true, it will be renamed tobar()
.
-
replaceRange
public SuggestedFix.Builder replaceRange(Node first, Node last, java.lang.String newContent)
Replaces a range of nodes with the given content.
-
replace
public SuggestedFix.Builder replace(Node original, Node newNode, AbstractCompiler compiler)
Replaces the provided node with new node in the source file.
-
addCast
public SuggestedFix.Builder addCast(Node n, AbstractCompiler compiler, java.lang.String type)
Adds a cast of the given type to the provided node.
-
removeCast
public SuggestedFix.Builder removeCast(Node n, AbstractCompiler compiler)
Removes a cast from the given node.
-
addOrReplaceJsDoc
public SuggestedFix.Builder addOrReplaceJsDoc(Node n, java.lang.String newJsDoc)
Adds or replaces the JS Doc for the given node.
-
changeJsDocType
public SuggestedFix.Builder changeJsDocType(Node n, AbstractCompiler compiler, java.lang.String type)
Changes the JS Doc Type of the given node.
-
insertArguments
public SuggestedFix.Builder insertArguments(Node n, int position, java.lang.String... args)
Inserts arguments into an existing function call.
-
deleteArgument
public SuggestedFix.Builder deleteArgument(Node n, int position)
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, java.lang.String namespace, ScriptMetadata scriptMetadata)
-
addGoogRequireType
public SuggestedFix.Builder addGoogRequireType(Match m, java.lang.String namespace, ScriptMetadata scriptMetadata)
-
addImport
public SuggestedFix.Builder addImport(Match m, java.lang.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
public SuggestedFix.Builder removeGoogRequire(Match m, java.lang.String namespace)
Removes a goog.require for the given namespace to the file if it already exists.
-
generateCode
public java.lang.String generateCode(AbstractCompiler compiler, Node node)
-
setDescription
public SuggestedFix.Builder setDescription(java.lang.String description)
-
build
public SuggestedFix build()
-
-