Skip to content

Commit

Permalink
Fix a bunch of error prone errors in error prone.
Browse files Browse the repository at this point in the history
RELNOTES: None

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=212780735
  • Loading branch information
awturner authored and cushon committed Sep 14, 2018
1 parent 70a7f49 commit 41a5586
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 31 deletions.
Expand Up @@ -185,10 +185,9 @@ private static String createLinkUrl(BugPattern pattern) {
return pattern.link();
case NONE:
return null;
default:
throw new IllegalStateException(
"Unexpected value for linkType element of @BugPattern: " + pattern.linkType());
}
throw new AssertionError(
"Unexpected value for linkType element of @BugPattern: " + pattern.linkType());
}

/**
Expand Down
Expand Up @@ -36,7 +36,6 @@
import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher;
import com.google.errorprone.fixes.Fix;
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.fixes.SuggestedFix.Builder;
import com.google.errorprone.fixes.SuggestedFixes;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
Expand Down Expand Up @@ -145,7 +144,7 @@ protected BaseFix buildBaseFix(
String exceptionClassExpr = "Throwable.class";
// additional assertions to perform on the captured exception (if any)
List<String> newAsserts = new ArrayList<>();
Builder fix = SuggestedFix.builder();
SuggestedFix.Builder fix = SuggestedFix.builder();
for (Tree expectation : expectations) {
MethodInvocationTree invocation =
(MethodInvocationTree) ((ExpressionStatementTree) expectation).getExpression();
Expand Down
Expand Up @@ -26,7 +26,6 @@
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher;
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.fixes.SuggestedFix.Builder;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.matchers.Matchers;
Expand Down Expand Up @@ -131,7 +130,7 @@ public Description matchMethod(MethodTree methodTree, VisitorState state) {
}

private void makeProtectedPublic(
MethodTree methodTree, VisitorState state, Builder suggestedFix) {
MethodTree methodTree, VisitorState state, SuggestedFix.Builder suggestedFix) {
if (Matchers.<MethodTree>hasModifier(Modifier.PROTECTED).matches(methodTree, state)) {
ModifiersTree modifiers = methodTree.getModifiers();
CharSequence modifiersSource = state.getSourceForNode(modifiers);
Expand Down
Expand Up @@ -24,7 +24,6 @@
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Description.Builder;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.VariableTree;
Expand Down Expand Up @@ -114,7 +113,7 @@ private void checkForHiddenFields(
continue;
}

Builder matchDesc = buildDescription(origVariable);
Description.Builder matchDesc = buildDescription(origVariable);

matchDesc.setMessage(
"Hiding fields of superclasses may cause confusion and errors. "
Expand Down
Expand Up @@ -39,7 +39,6 @@
import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher;
import com.google.errorprone.fixes.Fix;
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.fixes.SuggestedFix.Builder;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.sun.source.tree.MethodTree;
Expand Down Expand Up @@ -129,7 +128,7 @@ public Description matchMethod(MethodTree methodTree, VisitorState state) {
}

private static Fix mergeFixes(List<SuggestedFix> fixesToMerge) {
Builder builderForResult = SuggestedFix.builder();
SuggestedFix.Builder builderForResult = SuggestedFix.builder();
for (SuggestedFix fix : fixesToMerge) {
if (fix != null) {
builderForResult.merge(fix);
Expand Down
Expand Up @@ -42,7 +42,7 @@ public static ClassMemberKey create(String identifier, String descriptor) {
}

@Override
public String toString() {
public final String toString() {
return String.format("%s:%s", identifier(), descriptor());
}
}
Expand Down
Expand Up @@ -71,7 +71,7 @@ private static boolean isValidParameterTree(VariableTree variableTree) {
}

@Override
public String toString() {
public final String toString() {
String type = getType().toString();
String name = getName().toString();

Expand Down
Expand Up @@ -217,7 +217,7 @@ public void noPolicyGiven() throws IOException {
ImmutableList.of("-Xplugin:ErrorProne"),
ImmutableList.of(),
fileManager.getJavaFileObjects(source));
Throwable expected = assertThrows(Throwable.class, () -> task.call());
RuntimeException expected = assertThrows(RuntimeException.class, () -> task.call());
assertThat(expected)
.hasMessageThat()
.contains("The default compilation policy (by-todo) is not supported");
Expand All @@ -240,7 +240,7 @@ public void explicitBadPolicyGiven() throws IOException {
ImmutableList.of("-XDcompilePolicy=bytodo", "-Xplugin:ErrorProne"),
ImmutableList.of(),
fileManager.getJavaFileObjects(source));
Throwable expected = assertThrows(Throwable.class, () -> task.call());
RuntimeException expected = assertThrows(RuntimeException.class, () -> task.call());
assertThat(expected).hasMessageThat().contains("-XDcompilePolicy=bytodo is not supported");
}

Expand Down
Expand Up @@ -28,7 +28,7 @@
import com.sun.source.tree.TryTree;
import com.sun.tools.javac.tree.EndPosTable;
import com.sun.tools.javac.tree.JCTree;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -169,7 +169,7 @@ private Fix getOnlyFix(TestScanner scanner) {

private static class TestScanner extends Scanner {

final List<Description> suggestedChanges = new LinkedList<>();
final List<Description> suggestedChanges = new ArrayList<>();

@Override
public Void visitTry(TryTree node, VisitorState visitorState) {
Expand Down
Expand Up @@ -32,7 +32,6 @@
import java.util.List;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -47,7 +46,6 @@
public class DescendantOfTransitiveTest extends DescendantOfAbstractTest {

@Rule public final TemporaryFolder tempDir = new TemporaryFolder();
final List<ScannerTest> tests = new ArrayList<ScannerTest>();
final List<String> filesToCompile = new ArrayList<String>();

private void writeFileToLocalDisk(String fileName, String... lines) throws IOException {
Expand Down Expand Up @@ -96,14 +94,6 @@ public void setUp() throws IOException {
"}");
}

@Override
@After
public void tearDown() {
for (ScannerTest test : tests) {
test.assertDone();
}
}

@Test
public void shouldMatchTransitively() throws Exception {
writeFileToLocalDisk(
Expand Down
Expand Up @@ -104,7 +104,7 @@ public void regressionTest_frontmatter_pygments() throws Exception {
UTF_8));
String actual =
CharStreams.toString(Files.newBufferedReader(wikiDir.resolve("DeadException.md"), UTF_8));
assertThat(expected.trim()).isEqualTo(actual.trim());
assertThat(actual.trim()).isEqualTo(expected.trim());
}

@Test
Expand All @@ -125,7 +125,7 @@ public void regressionTest_nofrontmatter_gfm() throws Exception {
getClass().getResourceAsStream("testdata/DeadException_nofrontmatter_gfm.md"),
UTF_8));
String actual = new String(Files.readAllBytes(wikiDir.resolve("DeadException.md")), UTF_8);
assertThat(expected.trim()).isEqualTo(actual.trim());
assertThat(actual.trim()).isEqualTo(expected.trim());
}

@Test
Expand All @@ -151,7 +151,7 @@ public void regressionTest_sidecar() throws Exception {
getClass().getResourceAsStream("testdata/DeadException_nofrontmatter_gfm.md"),
UTF_8));
String actual = new String(Files.readAllBytes(wikiDir.resolve("DeadException.md")), UTF_8);
assertThat(expected.trim()).isEqualTo(actual.trim());
assertThat(actual.trim()).isEqualTo(expected.trim());
}

@Test
Expand Down Expand Up @@ -184,6 +184,6 @@ public void testEscapeAngleBracketsInSummary() throws Exception {
new InputStreamReader(
getClass().getResourceAsStream("testdata/DontDoThis_nofrontmatter_gfm.md"), UTF_8));
String actual = new String(Files.readAllBytes(wikiDir.resolve("DontDoThis.md")), UTF_8);
assertThat(expected.trim()).isEqualTo(actual.trim());
assertThat(actual.trim()).isEqualTo(expected.trim());
}
}

0 comments on commit 41a5586

Please sign in to comment.