Skip to content

Commit

Permalink
Tighten the return types in Fix.
Browse files Browse the repository at this point in the history
Remove the `default`ness of a method, given there's only one subclass.

PiperOrigin-RevId: 566989946
  • Loading branch information
graememorgan authored and Error Prone Team committed Sep 20, 2023
1 parent 58e5bb8 commit ac424d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
13 changes: 5 additions & 8 deletions check_api/src/main/java/com/google/errorprone/fixes/Fix.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

package com.google.errorprone.fixes;

import com.google.common.collect.ImmutableSet;
import com.sun.tools.javac.tree.EndPosTable;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import java.util.Collection;
import java.util.Set;

/**
* Represents a source code transformation, usually used to fix a bug detected by error-prone.
Expand All @@ -36,17 +35,15 @@ public interface Fix {
*
* <p>Empty string generates the default description.
*/
default String getShortDescription() {
return "";
}
String getShortDescription();

Replacements.CoalescePolicy getCoalescePolicy();

Set<Replacement> getReplacements(EndPosTable endPositions);
ImmutableSet<Replacement> getReplacements(EndPosTable endPositions);

Collection<String> getImportsToAdd();
ImmutableSet<String> getImportsToAdd();

Collection<String> getImportsToRemove();
ImmutableSet<String> getImportsToRemove();

boolean isEmpty();
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String toString(JCCompilationUnit compilationUnit) {
public abstract int hashCode();

@Override
public Set<Replacement> getReplacements(EndPosTable endPositions) {
public ImmutableSet<Replacement> getReplacements(EndPosTable endPositions) {
if (endPositions == null) {
throw new IllegalArgumentException(
"Cannot produce correct replacements without endPositions.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.google.common.collect.ImmutableSet;
import com.sun.source.tree.TreeVisitor;
import com.sun.tools.javac.tree.EndPosTable;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.util.Position;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -156,9 +155,8 @@ public void shouldSuggestToRemoveLastLineIfAsked() {
@Test
public void shouldApplyFixesInReverseOrder() {
// Have to use a mock Fix here in order to intentionally return Replacements in wrong order.
Set<Replacement> replacements = new LinkedHashSet<>();
replacements.add(Replacement.create(0, 1, ""));
replacements.add(Replacement.create(1, 1, ""));
ImmutableSet<Replacement> replacements =
ImmutableSet.of(Replacement.create(0, 1, ""), Replacement.create(1, 1, ""));

Fix mockFix = mock(Fix.class);
when(mockFix.getReplacements(any())).thenReturn(replacements);
Expand Down

0 comments on commit ac424d0

Please sign in to comment.