Class SuggestedFix.Builder

  • Enclosing class:
    SuggestedFix

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

      • Builder

        public Builder()
    • 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.
      • 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,
                                                 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, if replaceEntireName is false, then this.foo() will be renamed to this.bar(). However, if it is true, it will be renamed to bar().
      • replaceRange

        public SuggestedFix.Builder replaceRange​(Node first,
                                                 Node last,
                                                 java.lang.String newContent)
        Replaces a range of nodes with the given content.
      • addOrReplaceJsDoc

        public SuggestedFix.Builder addOrReplaceJsDoc​(Node n,
                                                      java.lang.String newJsDoc)
        Adds or replaces the JS Doc for 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.
      • 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.