Skip to content

Commit

Permalink
Use LinkedHashMap to keep track of severities
Browse files Browse the repository at this point in the history
The order of these entries became significant after 48bbef0, which
allowed using -Xep flags to configure checks using alt names.

#3831

PiperOrigin-RevId: 519261645
  • Loading branch information
cushon authored and Error Prone Team committed Mar 24, 2023
1 parent ba51498 commit 861377b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Expand Up @@ -31,7 +31,7 @@
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -259,7 +259,7 @@ private static class Builder {
private boolean isTestOnlyTarget = false;
private boolean ignoreSuppressionAnnotations = false;
private boolean ignoreLargeCodeGenerators = true;
private Map<String, Severity> severityMap = new HashMap<>();
private final Map<String, Severity> severityMap = new LinkedHashMap<>();
private final ErrorProneFlags.Builder flagsBuilder = ErrorProneFlags.builder();
private final PatchingOptions.Builder patchingOptionsBuilder = PatchingOptions.builder();
private Pattern excludedPattern;
Expand Down
Expand Up @@ -16,13 +16,18 @@

package com.google.errorprone;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.ErrorProneOptions.Severity;
import com.google.errorprone.apply.ImportOrganizer;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.regex.Pattern;
import org.junit.Test;
Expand Down Expand Up @@ -276,4 +281,19 @@ public void noSuchXepFlag() {
InvalidCommandLineOptionException.class,
() -> ErrorProneOptions.processArgs(new String[] {"-XepNoSuchFlag"}));
}

@Test
public void severityOrder() {
for (Collection<String> permutation :
Collections2.permutations(ImmutableList.of("A", "B", "C"))) {
ImmutableMap<String, Severity> severityMap =
permutation.stream().collect(toImmutableMap(x -> x, x -> Severity.ERROR));
ErrorProneOptions options =
ErrorProneOptions.processArgs(
permutation.stream()
.map(x -> String.format("-Xep:%s:ERROR", x))
.collect(toImmutableList()));
assertThat(options.getSeverityMap()).containsExactlyEntriesIn(severityMap).inOrder();
}
}
}

0 comments on commit 861377b

Please sign in to comment.