Skip to content

Commit

Permalink
Make SuggestedFix and SuggestedFix.Builder methods
Browse files Browse the repository at this point in the history
return a SuggestedFix instead of a Fix so that merge(SuggestedFix) makes sense.

MOE_MIGRATED_REVID=133124229
  • Loading branch information
netdpb authored and cushon committed Sep 15, 2016
1 parent 06559c6 commit 1e68910
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
31 changes: 16 additions & 15 deletions core/src/main/java/com/google/errorprone/fixes/SuggestedFix.java
Expand Up @@ -94,26 +94,27 @@ public Set<Replacement> getReplacements(EndPosTable endPositions) {
}

/** {@link Builder#replace(Tree, String)} */
public static Fix replace(Tree tree, String replaceWith) {
public static SuggestedFix replace(Tree tree, String replaceWith) {
return builder().replace(tree, replaceWith).build();
}

/**
* Replace the characters from startPos, inclusive, until endPos, exclusive, with the
* given string.
* Replace the characters from startPos, inclusive, until endPos, exclusive, with the given
* string.
*
* @param startPos The position from which to start replacing, inclusive
* @param endPos The position at which to end replacing, exclusive
* @param replaceWith The string to replace with
*/
public static Fix replace(int startPos, int endPos, String replaceWith) {
public static SuggestedFix replace(int startPos, int endPos, String replaceWith) {
return builder().replace(startPos, endPos, replaceWith).build();
}

/**
* 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":
* 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":
*
* <pre>
* {@code fix.replace(node, "replacement", 5, -5)}
* </pre>
Expand All @@ -123,28 +124,28 @@ public static Fix replace(int startPos, int endPos, String replaceWith) {
* @param startPosAdjustment The adjustment to add to the start position (negative is OK)
* @param endPosAdjustment The adjustment to add to the end position (negative is OK)
*/
public static Fix replace(Tree node, String replaceWith, int startPosAdjustment,
int endPosAdjustment) {
public static SuggestedFix replace(
Tree node, String replaceWith, int startPosAdjustment, int endPosAdjustment) {
return builder().replace(node, replaceWith, startPosAdjustment, endPosAdjustment).build();
}

/** {@link Builder#prefixWith(Tree, String)} */
public static Fix prefixWith(Tree node, String prefix) {
/** {@link Builder#prefixWith(Tree, String)} */
public static SuggestedFix prefixWith(Tree node, String prefix) {
return builder().prefixWith(node, prefix).build();
}

/** {@link Builder#postfixWith(Tree, String)} */
public static Fix postfixWith(Tree node, String postfix) {
public static SuggestedFix postfixWith(Tree node, String postfix) {
return builder().postfixWith(node, postfix).build();
}

/** {@link Builder#delete(Tree)} */
public static Fix delete(Tree node) {
public static SuggestedFix delete(Tree node) {
return builder().delete(node).build();
}

/** {@link Builder#swap(Tree, Tree)} */
public static Fix swap(Tree node1, Tree node2) {
public static SuggestedFix swap(Tree node1, Tree node2) {
return builder().swap(node1, node2).build();
}

Expand All @@ -165,7 +166,7 @@ public boolean isEmpty() {
return fixes.isEmpty() && importsToAdd.isEmpty() && importsToRemove.isEmpty();
}

public Fix build() {
public SuggestedFix build() {
return new SuggestedFix(fixes, importsToAdd, importsToRemove);
}

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -118,8 +118,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
<testExcludes>
<exclude>**/testdata/**</exclude>
</testExcludes>
Expand Down

0 comments on commit 1e68910

Please sign in to comment.