Class SuggestedFix.Builder
java.lang.Object
com.google.errorprone.fixes.SuggestedFix.Builder
- Enclosing class:
SuggestedFix
Builds
SuggestedFix
s.- Author:
- alexeagle@google.com (Alex Eagle)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdd an import statement as part of this SuggestedFix.addStaticImport
(String importString) Add a static import statement as part of this SuggestedFix.build()
delete
(com.sun.source.tree.Tree node) boolean
isEmpty()
merge
(@Nullable SuggestedFix other) Merges all edits fromother
intothis
.merge
(@Nullable SuggestedFix.Builder other) Merges all edits fromother
intothis
.postfixWith
(com.sun.source.tree.Tree node, String postfix) prefixWith
(com.sun.source.tree.Tree node, String prefix) removeImport
(String importString) Remove an import statement as part of this SuggestedFix.removeStaticImport
(String importString) Remove a static import statement as part of this SuggestedFix.Replace the characters from startPos, inclusive, until endPos, exclusive, with the given string.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.setCoalescePolicy
(Replacements.CoalescePolicy coalescePolicy) setShortDescription
(String shortDescription) Sets a custom short description for this fix.swap
(com.sun.source.tree.Tree node1, com.sun.source.tree.Tree node2)
-
Constructor Details
-
Builder
protected Builder()
-
-
Method Details
-
isEmpty
public boolean isEmpty() -
build
-
setShortDescription
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.
-
setCoalescePolicy
@CanIgnoreReturnValue public SuggestedFix.Builder setCoalescePolicy(Replacements.CoalescePolicy coalescePolicy) -
replace
@CanIgnoreReturnValue public SuggestedFix.Builder replace(com.sun.source.tree.Tree node, String replaceWith) -
replace
@CanIgnoreReturnValue 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, inclusiveendPos
- The position at which to end replacing, exclusivereplaceWith
- The string to replace with
-
replace
@CanIgnoreReturnValue 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 replacereplaceWith
- The string to replace withstartPosAdjustment
- The adjustment to add to the start position (negative is OK)endPosAdjustment
- The adjustment to add to the end position (negative is OK)
-
prefixWith
@CanIgnoreReturnValue public SuggestedFix.Builder prefixWith(com.sun.source.tree.Tree node, String prefix) -
postfixWith
@CanIgnoreReturnValue public SuggestedFix.Builder postfixWith(com.sun.source.tree.Tree node, String postfix) -
delete
-
swap
@CanIgnoreReturnValue public SuggestedFix.Builder swap(com.sun.source.tree.Tree node1, com.sun.source.tree.Tree node2) -
addImport
Add an import statement as part of this SuggestedFix. Import string should be of the form "foo.bar.SomeClass". -
addStaticImport
Add a static import statement as part of this SuggestedFix. Import string should be of the form "foo.bar.SomeClass.someMethod" or "foo.bar.SomeClass.SOME_FIELD". -
removeImport
Remove an import statement as part of this SuggestedFix. Import string should be of the form "foo.bar.SomeClass". -
removeStaticImport
Remove a static import statement as part of this SuggestedFix. Import string should be of the form "foo.bar.SomeClass.someMethod" or "foo.bar.SomeClass.SOME_FIELD". -
merge
Merges all edits fromother
intothis
. Ifother
is null, do nothing. -
merge
Merges all edits fromother
intothis
. Ifother
is null, do nothing.
-