Class SuggestedFix.Builder

java.lang.Object
com.google.errorprone.fixes.SuggestedFix.Builder
Enclosing class:
SuggestedFix

public static class SuggestedFix.Builder
extends Object
Builds SuggestedFixs.
  • Constructor Details

    • Builder

      protected Builder()
  • Method Details

    • isEmpty

      public boolean isEmpty()
    • build

      public SuggestedFix build()
    • setShortDescription

      public SuggestedFix.Builder setShortDescription​(String shortDescription)
      Sets a custom short description for this fix. This is useful for differentiating multiple fixes from the same finding.

      Should be limited to one sentence.

    • replace

      public SuggestedFix.Builder replace​(com.sun.source.tree.Tree node, String replaceWith)
    • replace

      public SuggestedFix.Builder replace​(int startPos, int endPos, String replaceWith)
      Replace the characters from startPos, inclusive, until endPos, exclusive, with the given string.
      Parameters:
      startPos - The position from which to start replacing, inclusive
      endPos - The position at which to end replacing, exclusive
      replaceWith - The string to replace with
    • replace

      public SuggestedFix.Builder replace​(com.sun.source.tree.Tree node, String replaceWith, int startPosAdjustment, int endPosAdjustment)
      Replace a tree node with a string, but adjust the start and end positions as well. For example, if the tree node begins at index 10 and ends at index 30, this call will replace the characters at index 15 through 25 with "replacement":
       fix.replace(node, "replacement", 5, -5)
       
      Parameters:
      node - The tree node to replace
      replaceWith - The string to replace with
      startPosAdjustment - The adjustment to add to the start position (negative is OK)
      endPosAdjustment - The adjustment to add to the end position (negative is OK)
    • prefixWith

      public SuggestedFix.Builder prefixWith​(com.sun.source.tree.Tree node, String prefix)
    • postfixWith

      public SuggestedFix.Builder postfixWith​(com.sun.source.tree.Tree node, String postfix)
    • delete

      public SuggestedFix.Builder delete​(com.sun.source.tree.Tree node)
    • swap

      public SuggestedFix.Builder swap​(com.sun.source.tree.Tree node1, com.sun.source.tree.Tree node2)
    • addImport

      public SuggestedFix.Builder addImport​(String importString)
      Add an import statement as part of this SuggestedFix. Import string should be of the form "foo.bar.baz".
    • addStaticImport

      public SuggestedFix.Builder addStaticImport​(String importString)
      Add a static import statement as part of this SuggestedFix. Import string should be of the form "foo.bar.baz".
    • removeImport

      public SuggestedFix.Builder removeImport​(String importString)
      Remove an import statement as part of this SuggestedFix. Import string should be of the form "foo.bar.baz".
    • removeStaticImport

      public SuggestedFix.Builder removeStaticImport​(String importString)
      Remove a static import statement as part of this SuggestedFix. Import string should be of the form "foo.bar.baz".
    • merge

      Merges all edits from other into this. If other is null, do nothing.
    • merge

      public SuggestedFix.Builder merge​(@Nullable SuggestedFix other)
      Merges all edits from other into this. If other is null, do nothing.