Class SuggestedFix.Builder

java.lang.Object
com.google.javascript.refactoring.SuggestedFix.Builder
Enclosing class:
SuggestedFix

public static final class SuggestedFix.Builder extends Object
Builder class for SuggestedFix that contains helper functions to manipulate JS nodes.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • attachMatchedNodeInfo

      @CanIgnoreReturnValue 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

      @CanIgnoreReturnValue public SuggestedFix.Builder addAlternative(SuggestedFix alternative)
    • addChildToFront

      @CanIgnoreReturnValue public SuggestedFix.Builder addChildToFront(Node parentNode, String content)
      Inserts a new node as the first child of the provided node.
    • insertAfter

      @CanIgnoreReturnValue public SuggestedFix.Builder insertAfter(Node node, String text)
      Inserts the text after the given node
    • insertBefore

      @CanIgnoreReturnValue public SuggestedFix.Builder insertBefore(Node nodeToInsertBefore, Node n, AbstractCompiler compiler)
      Inserts a new node before the provided node.
    • insertBefore

      @CanIgnoreReturnValue public SuggestedFix.Builder insertBefore(Node nodeToInsertBefore, 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

      @CanIgnoreReturnValue 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

      @CanIgnoreReturnValue public SuggestedFix.Builder deleteWithoutRemovingWhitespaceBefore(Node n)
      Deletes a node and its contents from the source file.
    • deleteWithoutRemovingWhitespace

      @CanIgnoreReturnValue public SuggestedFix.Builder deleteWithoutRemovingWhitespace(Node n)
      Deletes a node without touching any surrounding whitespace.
    • rename

      @CanIgnoreReturnValue public SuggestedFix.Builder rename(Node n, String name)
      Renames a given node to the provided name.
      Parameters:
      n - The node to rename.
      name - The new name for the node.
    • rename

      @CanIgnoreReturnValue public SuggestedFix.Builder rename(Node n, String name, boolean replaceNameSubtree)
      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, if replaceNameSubtree is false, then this.foo() will be renamed to this.bar(). However, if it is true, it will be renamed to bar().
    • replaceRange

      @CanIgnoreReturnValue public SuggestedFix.Builder replaceRange(Node first, Node last, String newContent)
      Replaces a range of nodes with the given content.
    • replace

      @CanIgnoreReturnValue public SuggestedFix.Builder replace(Node original, Node newNode, AbstractCompiler compiler)
      Replaces the provided node with new node in the source file.
    • addCast

      @CanIgnoreReturnValue public SuggestedFix.Builder addCast(Node n, AbstractCompiler compiler, String type)
      Adds a cast of the given type to the provided node.
    • removeCast

      @CanIgnoreReturnValue public SuggestedFix.Builder removeCast(Node n, AbstractCompiler compiler)
      Removes a cast from the given node.
    • addOrReplaceJsDoc

      @CanIgnoreReturnValue public SuggestedFix.Builder addOrReplaceJsDoc(Node n, String newJsDoc)
      Adds or replaces the JS Doc for the given node.
    • changeJsDocType

      @CanIgnoreReturnValue public SuggestedFix.Builder changeJsDocType(Node n, AbstractCompiler compiler, String type)
      Changes the JS Doc Type of the given node.
    • insertArguments

      @CanIgnoreReturnValue public SuggestedFix.Builder insertArguments(Node n, int position, String... args)
      Inserts arguments into an existing function call.
    • deleteArgument

      @CanIgnoreReturnValue 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

      @CanIgnoreReturnValue public SuggestedFix.Builder addGoogRequire(Match m, String namespace, ScriptMetadata scriptMetadata)
    • addGoogRequireType

      @CanIgnoreReturnValue public SuggestedFix.Builder addGoogRequireType(Match m, String namespace, ScriptMetadata scriptMetadata)
    • addImport

      @CanIgnoreReturnValue 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

      @CanIgnoreReturnValue public SuggestedFix.Builder removeGoogRequire(Match m, String namespace)
      Removes a goog.require for the given namespace to the file if it already exists.
    • generateCode

      public String generateCode(AbstractCompiler compiler, Node node)
    • setDescription

      @CanIgnoreReturnValue public SuggestedFix.Builder setDescription(String description)
    • build

      public SuggestedFix build()