mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Extend ImmutableMapRules Refaster rule collection (#1488)
Resolves #1223.
This commit is contained in:
committed by
GitHub
parent
9493f2d59a
commit
19d3ba0505
@@ -54,7 +54,7 @@ public final class SpringMvcAnnotation extends BugChecker implements AnnotationT
|
||||
.put("PATCH", "PatchMapping")
|
||||
.put("POST", "PostMapping")
|
||||
.put("PUT", "PutMapping")
|
||||
.build();
|
||||
.buildOrThrow();
|
||||
|
||||
/** Instantiates a new {@link SpringMvcAnnotation} instance. */
|
||||
public SpringMvcAnnotation() {}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.google.errorprone.refaster.annotation.BeforeTemplate;
|
||||
import com.google.errorprone.refaster.annotation.Matches;
|
||||
import com.google.errorprone.refaster.annotation.MayOptionallyUse;
|
||||
import com.google.errorprone.refaster.annotation.Placeholder;
|
||||
import com.google.errorprone.refaster.annotation.Repeated;
|
||||
import com.google.errorprone.refaster.annotation.UseImportPolicy;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@@ -44,12 +45,28 @@ final class ImmutableMapRules {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link ImmutableMap.Builder#buildOrThrow()} over the less explicit {@link
|
||||
* ImmutableMap.Builder#build()}.
|
||||
*/
|
||||
static final class ImmutableMapBuilderBuildOrThrow<K, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableMap<K, V> before(ImmutableMap.Builder<K, V> builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
ImmutableMap<K, V> after(ImmutableMap.Builder<K, V> builder) {
|
||||
return builder.buildOrThrow();
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link ImmutableMap#of(Object, Object)} over more contrived alternatives. */
|
||||
static final class EntryToImmutableMap<K, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableMap<K, V> before(Map.Entry<? extends K, ? extends V> entry) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableMap.<K, V>builder().put(entry).build(),
|
||||
ImmutableMap.<K, V>builder().put(entry).buildOrThrow(),
|
||||
Stream.of(entry).collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)));
|
||||
}
|
||||
|
||||
@@ -104,16 +121,17 @@ final class ImmutableMapRules {
|
||||
/** Prefer {@link ImmutableMap#copyOf(Iterable)} over more contrived alternatives. */
|
||||
static final class EntryIterableToImmutableMap<K, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableMap<K, V> before(Map<? extends K, ? extends V> iterable) {
|
||||
Map<K, V> before(Map<? extends K, ? extends V> iterable) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableMap.copyOf(iterable.entrySet()),
|
||||
ImmutableMap.<K, V>builder().putAll(iterable).build());
|
||||
ImmutableMap.<K, V>builder().putAll(iterable).buildOrThrow(),
|
||||
Map.copyOf(iterable));
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
ImmutableMap<K, V> before(Iterable<? extends Map.Entry<? extends K, ? extends V>> iterable) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableMap.<K, V>builder().putAll(iterable).build(),
|
||||
ImmutableMap.<K, V>builder().putAll(iterable).buildOrThrow(),
|
||||
Streams.stream(iterable).collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)));
|
||||
}
|
||||
|
||||
@@ -139,8 +157,6 @@ final class ImmutableMapRules {
|
||||
@Placeholder(allowsIdentity = true)
|
||||
abstract V valueFunction(@MayOptionallyUse E element);
|
||||
|
||||
// XXX: We could add variants in which the entry is created some other way, but we have another
|
||||
// rule that covers canonicalization to `Map.entry`.
|
||||
@BeforeTemplate
|
||||
ImmutableMap<K, V> before(Stream<E> stream) {
|
||||
return stream
|
||||
@@ -224,7 +240,11 @@ final class ImmutableMapRules {
|
||||
static final class ImmutableMapOf<K, V> {
|
||||
@BeforeTemplate
|
||||
Map<K, V> before() {
|
||||
return Refaster.anyOf(ImmutableMap.<K, V>builder().build(), emptyMap(), Map.of());
|
||||
return Refaster.anyOf(
|
||||
ImmutableMap.<K, V>builder().buildOrThrow(),
|
||||
ImmutableMap.ofEntries(),
|
||||
emptyMap(),
|
||||
Map.of());
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@@ -243,7 +263,10 @@ final class ImmutableMapRules {
|
||||
@BeforeTemplate
|
||||
Map<K, V> before(K k1, V v1) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableMap.<K, V>builder().put(k1, v1).build(), singletonMap(k1, v1), Map.of(k1, v1));
|
||||
ImmutableMap.<K, V>builder().put(k1, v1).buildOrThrow(),
|
||||
ImmutableMap.ofEntries(Map.entry(k1, v1)),
|
||||
singletonMap(k1, v1),
|
||||
Map.of(k1, v1));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@@ -261,7 +284,8 @@ final class ImmutableMapRules {
|
||||
static final class ImmutableMapOf2<K, V> {
|
||||
@BeforeTemplate
|
||||
Map<K, V> before(K k1, V v1, K k2, V v2) {
|
||||
return Map.of(k1, v1, k2, v2);
|
||||
return Refaster.anyOf(
|
||||
ImmutableMap.ofEntries(Map.entry(k1, v1), Map.entry(k2, v2)), Map.of(k1, v1, k2, v2));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@@ -279,7 +303,9 @@ final class ImmutableMapRules {
|
||||
static final class ImmutableMapOf3<K, V> {
|
||||
@BeforeTemplate
|
||||
Map<K, V> before(K k1, V v1, K k2, V v2, K k3, V v3) {
|
||||
return Map.of(k1, v1, k2, v2, k3, v3);
|
||||
return Refaster.anyOf(
|
||||
ImmutableMap.ofEntries(Map.entry(k1, v1), Map.entry(k2, v2), Map.entry(k3, v3)),
|
||||
Map.of(k1, v1, k2, v2, k3, v3));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@@ -299,7 +325,10 @@ final class ImmutableMapRules {
|
||||
static final class ImmutableMapOf4<K, V> {
|
||||
@BeforeTemplate
|
||||
Map<K, V> before(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
|
||||
return Map.of(k1, v1, k2, v2, k3, v3, k4, v4);
|
||||
return Refaster.anyOf(
|
||||
ImmutableMap.ofEntries(
|
||||
Map.entry(k1, v1), Map.entry(k2, v2), Map.entry(k3, v3), Map.entry(k4, v4)),
|
||||
Map.of(k1, v1, k2, v2, k3, v3, k4, v4));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@@ -319,7 +348,14 @@ final class ImmutableMapRules {
|
||||
static final class ImmutableMapOf5<K, V> {
|
||||
@BeforeTemplate
|
||||
Map<K, V> before(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
|
||||
return Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5);
|
||||
return Refaster.anyOf(
|
||||
ImmutableMap.ofEntries(
|
||||
Map.entry(k1, v1),
|
||||
Map.entry(k2, v2),
|
||||
Map.entry(k3, v3),
|
||||
Map.entry(k4, v4),
|
||||
Map.entry(k5, v5)),
|
||||
Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@@ -370,6 +406,22 @@ final class ImmutableMapRules {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link ImmutableMap#ofEntries(Map.Entry[])} over alternatives that don't communicate the
|
||||
* immutability of the resulting map at the type level.
|
||||
*/
|
||||
static final class ImmutableMapOfEntries<K, V> {
|
||||
@BeforeTemplate
|
||||
Map<K, V> before(@Repeated Map.Entry<? extends K, ? extends V> entries) {
|
||||
return Map.ofEntries(entries);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
ImmutableMap<K, V> after(@Repeated Map.Entry<? extends K, ? extends V> entries) {
|
||||
return ImmutableMap.ofEntries(entries);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add a rule for this:
|
||||
// Maps.transformValues(streamOfEntries.collect(groupBy(fun)), ImmutableMap::copyOf)
|
||||
// ->
|
||||
|
||||
@@ -71,7 +71,7 @@ final class ImmutableSortedMapRules {
|
||||
static final class EmptyImmutableSortedMap<K extends Comparable<? super K>, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableSortedMap<K, V> before() {
|
||||
return ImmutableSortedMap.<K, V>naturalOrder().build();
|
||||
return ImmutableSortedMap.<K, V>naturalOrder().buildOrThrow();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@@ -89,7 +89,7 @@ final class ImmutableSortedMapRules {
|
||||
static final class PairToImmutableSortedMap<K extends Comparable<? super K>, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableSortedMap<K, V> before(K key, V value) {
|
||||
return ImmutableSortedMap.<K, V>naturalOrder().put(key, value).build();
|
||||
return ImmutableSortedMap.<K, V>naturalOrder().put(key, value).buildOrThrow();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@@ -105,7 +105,7 @@ final class ImmutableSortedMapRules {
|
||||
@BeforeTemplate
|
||||
ImmutableSortedMap<K, V> before(Map.Entry<? extends K, ? extends V> entry) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedMap.<K, V>naturalOrder().put(entry).build(),
|
||||
ImmutableSortedMap.<K, V>naturalOrder().put(entry).buildOrThrow(),
|
||||
Stream.of(entry)
|
||||
.collect(
|
||||
toImmutableSortedMap(naturalOrder(), Map.Entry::getKey, Map.Entry::getValue)));
|
||||
@@ -126,7 +126,7 @@ final class ImmutableSortedMapRules {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedMap.copyOf(iterable, naturalOrder()),
|
||||
ImmutableSortedMap.copyOf(iterable.entrySet()),
|
||||
ImmutableSortedMap.<K, V>naturalOrder().putAll(iterable).build());
|
||||
ImmutableSortedMap.<K, V>naturalOrder().putAll(iterable).buildOrThrow());
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
@@ -134,7 +134,7 @@ final class ImmutableSortedMapRules {
|
||||
Iterable<? extends Map.Entry<? extends K, ? extends V>> iterable) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedMap.copyOf(iterable, naturalOrder()),
|
||||
ImmutableSortedMap.<K, V>naturalOrder().putAll(iterable).build(),
|
||||
ImmutableSortedMap.<K, V>naturalOrder().putAll(iterable).buildOrThrow(),
|
||||
Streams.stream(iterable)
|
||||
.collect(
|
||||
toImmutableSortedMap(
|
||||
|
||||
@@ -24,9 +24,13 @@ final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return new ImmutableMap.Builder<>();
|
||||
}
|
||||
|
||||
ImmutableMap<Object, Object> testImmutableMapBuilderBuildOrThrow() {
|
||||
return ImmutableMap.builder().build();
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableMap<String, Integer>> testEntryToImmutableMap() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.<String, Integer>builder().put(Map.entry("foo", 1)).build(),
|
||||
ImmutableMap.<String, Integer>builder().put(Map.entry("foo", 1)).buildOrThrow(),
|
||||
Stream.of(Map.entry("foo", 1))
|
||||
.collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)));
|
||||
}
|
||||
@@ -51,13 +55,14 @@ final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase {
|
||||
ImmutableMap.copyOf(Maps.asMap(ImmutableSet.of(10), Integer::valueOf)));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableMap<String, Integer>> testEntryIterableToImmutableMap() {
|
||||
ImmutableSet<Map<String, Integer>> testEntryIterableToImmutableMap() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.copyOf(ImmutableMap.of("foo", 1).entrySet()),
|
||||
ImmutableMap.<String, Integer>builder().putAll(ImmutableMap.of("foo", 1)).build(),
|
||||
ImmutableMap.<String, Integer>builder().putAll(ImmutableMap.of("foo", 1)).buildOrThrow(),
|
||||
Map.copyOf(ImmutableMap.of("foo", 1)),
|
||||
ImmutableMap.<String, Integer>builder()
|
||||
.putAll(ImmutableMap.of("foo", 1).entrySet())
|
||||
.build(),
|
||||
.buildOrThrow(),
|
||||
ImmutableMap.of("foo", 1).entrySet().stream()
|
||||
.collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)),
|
||||
Streams.stream(Iterables.cycle(Map.entry("foo", 1)))
|
||||
@@ -100,32 +105,51 @@ final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase {
|
||||
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.<String, String>builder().build(),
|
||||
ImmutableMap.<String, String>builder().buildOrThrow(),
|
||||
ImmutableMap.ofEntries(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
Map.<String, String>of());
|
||||
}
|
||||
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf1() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.<String, String>builder().put("k1", "v1").build(),
|
||||
ImmutableMap.<String, String>builder().put("k1", "v1").buildOrThrow(),
|
||||
ImmutableMap.ofEntries(Map.entry("k1", "v1")),
|
||||
Collections.singletonMap("k1", "v1"),
|
||||
Map.of("k1", "v1"));
|
||||
}
|
||||
|
||||
Map<String, String> testImmutableMapOf2() {
|
||||
return Map.of("k1", "v1", "k2", "v2");
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf2() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.ofEntries(Map.entry("k1", "v1"), Map.entry("k2", "v2")),
|
||||
Map.of("k1", "v1", "k2", "v2"));
|
||||
}
|
||||
|
||||
Map<String, String> testImmutableMapOf3() {
|
||||
return Map.of("k1", "v1", "k2", "v2", "k3", "v3");
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf3() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.ofEntries(Map.entry("k1", "v1"), Map.entry("k2", "v2"), Map.entry("k3", "v3")),
|
||||
Map.of("k1", "v1", "k2", "v2", "k3", "v3"));
|
||||
}
|
||||
|
||||
Map<String, String> testImmutableMapOf4() {
|
||||
return Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4");
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf4() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.ofEntries(
|
||||
Map.entry("k1", "v1"),
|
||||
Map.entry("k2", "v2"),
|
||||
Map.entry("k3", "v3"),
|
||||
Map.entry("k4", "v4")),
|
||||
Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4"));
|
||||
}
|
||||
|
||||
Map<String, String> testImmutableMapOf5() {
|
||||
return Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5");
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf5() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.ofEntries(
|
||||
Map.entry("k1", "v1"),
|
||||
Map.entry("k2", "v2"),
|
||||
Map.entry("k3", "v3"),
|
||||
Map.entry("k4", "v4"),
|
||||
Map.entry("k5", "v5")),
|
||||
Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"));
|
||||
}
|
||||
|
||||
ImmutableMap<String, Integer> testImmutableMapCopyOfMapsFilterKeys() {
|
||||
@@ -139,4 +163,11 @@ final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase {
|
||||
.filter(entry -> entry.getValue() > 0)
|
||||
.collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
ImmutableSet<Map<String, Integer>> testImmutableMapOfEntries() {
|
||||
return ImmutableSet.of(
|
||||
Map.ofEntries(),
|
||||
Map.ofEntries(Map.entry("foo", 1)),
|
||||
Map.ofEntries(Map.entry("bar", 2), Map.entry("baz", 3)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return ImmutableMap.builder();
|
||||
}
|
||||
|
||||
ImmutableMap<Object, Object> testImmutableMapBuilderBuildOrThrow() {
|
||||
return ImmutableMap.builder().buildOrThrow();
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableMap<String, Integer>> testEntryToImmutableMap() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue()),
|
||||
@@ -46,8 +50,9 @@ final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase {
|
||||
Maps.toMap(ImmutableSet.of(10), Integer::valueOf));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableMap<String, Integer>> testEntryIterableToImmutableMap() {
|
||||
ImmutableSet<Map<String, Integer>> testEntryIterableToImmutableMap() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.copyOf(ImmutableMap.of("foo", 1)),
|
||||
ImmutableMap.copyOf(ImmutableMap.of("foo", 1)),
|
||||
ImmutableMap.copyOf(ImmutableMap.of("foo", 1)),
|
||||
ImmutableMap.copyOf(ImmutableMap.of("foo", 1).entrySet()),
|
||||
@@ -83,28 +88,39 @@ final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase {
|
||||
}
|
||||
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf() {
|
||||
return ImmutableSet.of(ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of());
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of());
|
||||
}
|
||||
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf1() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.of("k1", "v1"), ImmutableMap.of("k1", "v1"), ImmutableMap.of("k1", "v1"));
|
||||
ImmutableMap.of("k1", "v1"),
|
||||
ImmutableMap.of("k1", "v1"),
|
||||
ImmutableMap.of("k1", "v1"),
|
||||
ImmutableMap.of("k1", "v1"));
|
||||
}
|
||||
|
||||
Map<String, String> testImmutableMapOf2() {
|
||||
return ImmutableMap.of("k1", "v1", "k2", "v2");
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf2() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.of("k1", "v1", "k2", "v2"), ImmutableMap.of("k1", "v1", "k2", "v2"));
|
||||
}
|
||||
|
||||
Map<String, String> testImmutableMapOf3() {
|
||||
return ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3");
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf3() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"),
|
||||
ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"));
|
||||
}
|
||||
|
||||
Map<String, String> testImmutableMapOf4() {
|
||||
return ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4");
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf4() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4"),
|
||||
ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4"));
|
||||
}
|
||||
|
||||
Map<String, String> testImmutableMapOf5() {
|
||||
return ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5");
|
||||
ImmutableSet<Map<String, String>> testImmutableMapOf5() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"),
|
||||
ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"));
|
||||
}
|
||||
|
||||
ImmutableMap<String, Integer> testImmutableMapCopyOfMapsFilterKeys() {
|
||||
@@ -114,4 +130,11 @@ final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase {
|
||||
ImmutableMap<String, Integer> testImmutableMapCopyOfMapsFilterValues() {
|
||||
return ImmutableMap.copyOf(Maps.filterValues(ImmutableMap.of("foo", 1), v -> v > 0));
|
||||
}
|
||||
|
||||
ImmutableSet<Map<String, Integer>> testImmutableMapOfEntries() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMap.ofEntries(),
|
||||
ImmutableMap.ofEntries(Map.entry("foo", 1)),
|
||||
ImmutableMap.ofEntries(Map.entry("bar", 2), Map.entry("baz", 3)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,16 +32,16 @@ final class ImmutableSortedMapRulesTest implements RefasterRuleCollectionTestCas
|
||||
}
|
||||
|
||||
ImmutableSortedMap<String, Integer> testEmptyImmutableSortedMap() {
|
||||
return ImmutableSortedMap.<String, Integer>naturalOrder().build();
|
||||
return ImmutableSortedMap.<String, Integer>naturalOrder().buildOrThrow();
|
||||
}
|
||||
|
||||
ImmutableSortedMap<String, Integer> testPairToImmutableSortedMap() {
|
||||
return ImmutableSortedMap.<String, Integer>naturalOrder().put("foo", 1).build();
|
||||
return ImmutableSortedMap.<String, Integer>naturalOrder().put("foo", 1).buildOrThrow();
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableSortedMap<String, Integer>> testEntryToImmutableSortedMap() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSortedMap.<String, Integer>naturalOrder().put(Map.entry("foo", 1)).build(),
|
||||
ImmutableSortedMap.<String, Integer>naturalOrder().put(Map.entry("foo", 1)).buildOrThrow(),
|
||||
Stream.of(Map.entry("foo", 1))
|
||||
.collect(toImmutableSortedMap(naturalOrder(), Map.Entry::getKey, Map.Entry::getValue)));
|
||||
}
|
||||
@@ -52,10 +52,10 @@ final class ImmutableSortedMapRulesTest implements RefasterRuleCollectionTestCas
|
||||
ImmutableSortedMap.copyOf(ImmutableSortedMap.of("foo", 1).entrySet()),
|
||||
ImmutableSortedMap.<String, Integer>naturalOrder()
|
||||
.putAll(ImmutableSortedMap.of("foo", 1))
|
||||
.build(),
|
||||
.buildOrThrow(),
|
||||
ImmutableSortedMap.<String, Integer>naturalOrder()
|
||||
.putAll(ImmutableSortedMap.of("foo", 1).entrySet())
|
||||
.build(),
|
||||
.buildOrThrow(),
|
||||
ImmutableSortedMap.of("foo", 1).entrySet().stream()
|
||||
.collect(toImmutableSortedMap(naturalOrder(), Map.Entry::getKey, Map.Entry::getValue)),
|
||||
Streams.stream(Iterables.cycle(Map.entry("foo", 1)))
|
||||
|
||||
@@ -14875,7 +14875,7 @@
|
||||
final String defaultValue = getDefaultValue(propertyName, field, instance);
|
||||
--- a/src/main/java/com/puppycrawl/tools/checkstyle/site/SiteUtil.java
|
||||
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/site/SiteUtil.java
|
||||
@@ -19,6 +19,14 @@
|
||||
@@ -19,6 +19,15 @@
|
||||
|
||||
package com.puppycrawl.tools.checkstyle.site;
|
||||
|
||||
@@ -14886,11 +14886,12 @@
|
||||
+
|
||||
+import com.google.common.base.Strings;
|
||||
+import com.google.common.collect.ImmutableList;
|
||||
+import com.google.common.collect.ImmutableMap;
|
||||
+import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.puppycrawl.tools.checkstyle.Checker;
|
||||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
||||
@@ -55,7 +63,6 @@ import java.net.URI;
|
||||
@@ -55,7 +64,6 @@ import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -14898,7 +14899,7 @@
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -72,7 +79,6 @@ import java.util.Optional;
|
||||
@@ -72,7 +80,6 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -14906,7 +14907,31 @@
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -156,7 +162,7 @@ public final class SiteUtil {
|
||||
@@ -131,12 +138,17 @@ public final class SiteUtil {
|
||||
|
||||
/** Class name and their corresponding parent module name. */
|
||||
private static final Map<Class<?>, String> CLASS_TO_PARENT_MODULE =
|
||||
- Map.ofEntries(
|
||||
- Map.entry(AbstractCheck.class, TreeWalker.class.getSimpleName()),
|
||||
- Map.entry(TreeWalkerFilter.class, TreeWalker.class.getSimpleName()),
|
||||
- Map.entry(AbstractFileSetCheck.class, Checker.class.getSimpleName()),
|
||||
- Map.entry(Filter.class, Checker.class.getSimpleName()),
|
||||
- Map.entry(BeforeExecutionFileFilter.class, Checker.class.getSimpleName()));
|
||||
+ ImmutableMap.of(
|
||||
+ AbstractCheck.class,
|
||||
+ TreeWalker.class.getSimpleName(),
|
||||
+ TreeWalkerFilter.class,
|
||||
+ TreeWalker.class.getSimpleName(),
|
||||
+ AbstractFileSetCheck.class,
|
||||
+ Checker.class.getSimpleName(),
|
||||
+ Filter.class,
|
||||
+ Checker.class.getSimpleName(),
|
||||
+ BeforeExecutionFileFilter.class,
|
||||
+ Checker.class.getSimpleName());
|
||||
|
||||
/** Set of properties that every check has. */
|
||||
private static final Set<String> CHECK_PROPERTIES = getProperties(AbstractCheck.class);
|
||||
@@ -156,7 +168,7 @@ public final class SiteUtil {
|
||||
|
||||
/** Set of properties that are undocumented. Those are internal properties. */
|
||||
private static final Set<String> UNDOCUMENTED_PROPERTIES =
|
||||
@@ -14915,7 +14940,7 @@
|
||||
"SuppressWithNearbyCommentFilter.fileContents", "SuppressionCommentFilter.fileContents");
|
||||
|
||||
/** Properties that can not be gathered from class instance. */
|
||||
@@ -294,27 +300,25 @@ public final class SiteUtil {
|
||||
@@ -294,27 +306,25 @@ public final class SiteUtil {
|
||||
|
||||
/** Path to main source code folder. */
|
||||
private static final String MAIN_FOLDER_PATH =
|
||||
@@ -14932,16 +14957,16 @@
|
||||
+ new File(Path.of(MAIN_FOLDER_PATH, CHECKS, NAMING, "AbstractNameCheck.java").toString()),
|
||||
new File(
|
||||
- Paths.get(MAIN_FOLDER_PATH, CHECKS, NAMING, "AbstractNameCheck.java").toString()),
|
||||
- new File(
|
||||
- Paths.get(MAIN_FOLDER_PATH, CHECKS, "javadoc", "AbstractJavadocCheck.java")
|
||||
- .toString()),
|
||||
- new File(Paths.get(MAIN_FOLDER_PATH, "api", "AbstractFileSetCheck.java").toString()),
|
||||
+ Path.of(MAIN_FOLDER_PATH, CHECKS, "javadoc", "AbstractJavadocCheck.java").toString()),
|
||||
+ new File(Path.of(MAIN_FOLDER_PATH, "api", "AbstractFileSetCheck.java").toString()),
|
||||
new File(
|
||||
- Paths.get(MAIN_FOLDER_PATH, CHECKS, "header", "AbstractHeaderCheck.java").toString()),
|
||||
- Paths.get(MAIN_FOLDER_PATH, CHECKS, "javadoc", "AbstractJavadocCheck.java")
|
||||
- .toString()),
|
||||
- new File(Paths.get(MAIN_FOLDER_PATH, "api", "AbstractFileSetCheck.java").toString()),
|
||||
+ Path.of(MAIN_FOLDER_PATH, CHECKS, "header", "AbstractHeaderCheck.java").toString()),
|
||||
new File(
|
||||
- Paths.get(MAIN_FOLDER_PATH, CHECKS, "header", "AbstractHeaderCheck.java").toString()),
|
||||
- new File(
|
||||
- Paths.get(MAIN_FOLDER_PATH, CHECKS, "metrics", "AbstractClassCouplingCheck.java")
|
||||
+ Path.of(MAIN_FOLDER_PATH, CHECKS, "metrics", "AbstractClassCouplingCheck.java")
|
||||
.toString()),
|
||||
@@ -14951,7 +14976,7 @@
|
||||
.toString()));
|
||||
|
||||
/** Private utility constructor. */
|
||||
@@ -475,7 +479,7 @@ public final class SiteUtil {
|
||||
@@ -475,7 +485,7 @@ public final class SiteUtil {
|
||||
* @throws MacroExecutionException if an I/O error occurs.
|
||||
*/
|
||||
public static Set<Path> getXdocsTemplatesFilePaths() throws MacroExecutionException {
|
||||
@@ -14960,7 +14985,7 @@
|
||||
try (Stream<Path> stream =
|
||||
Files.find(
|
||||
directory,
|
||||
@@ -483,7 +487,7 @@ public final class SiteUtil {
|
||||
@@ -483,7 +493,7 @@ public final class SiteUtil {
|
||||
(path, attr) -> {
|
||||
return attr.isRegularFile() && path.toString().endsWith(".xml.template");
|
||||
})) {
|
||||
@@ -14969,7 +14994,7 @@
|
||||
} catch (IOException ioException) {
|
||||
throw new MacroExecutionException("Failed to find xdocs templates", ioException);
|
||||
}
|
||||
@@ -510,7 +514,7 @@ public final class SiteUtil {
|
||||
@@ -510,7 +520,7 @@ public final class SiteUtil {
|
||||
}
|
||||
|
||||
// If parent class is not found, check interfaces
|
||||
@@ -14978,7 +15003,7 @@
|
||||
final Class<?>[] interfaces = moduleClass.getInterfaces();
|
||||
for (Class<?> interfaceClass : interfaces) {
|
||||
parentModuleName = CLASS_TO_PARENT_MODULE.get(interfaceClass);
|
||||
@@ -520,7 +524,7 @@ public final class SiteUtil {
|
||||
@@ -520,7 +530,7 @@ public final class SiteUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14987,7 +15012,7 @@
|
||||
final String message =
|
||||
String.format(
|
||||
Locale.ROOT, "Failed to find parent module for %s", moduleClass.getSimpleName());
|
||||
@@ -544,7 +548,7 @@ public final class SiteUtil {
|
||||
@@ -544,7 +554,7 @@ public final class SiteUtil {
|
||||
prop -> {
|
||||
return !isGlobalProperty(clss, prop) && !isUndocumentedProperty(clss, prop);
|
||||
})
|
||||
@@ -14996,7 +15021,7 @@
|
||||
properties.addAll(getNonExplicitProperties(instance, clss));
|
||||
return new TreeSet<>(properties);
|
||||
}
|
||||
@@ -663,7 +667,7 @@ public final class SiteUtil {
|
||||
@@ -663,7 +673,7 @@ public final class SiteUtil {
|
||||
treeWalkerConfig.addChild(scraperCheckConfig);
|
||||
try {
|
||||
checker.configure(defaultConfiguration);
|
||||
@@ -15005,7 +15030,7 @@
|
||||
checker.process(filesToProcess);
|
||||
checker.destroy();
|
||||
} catch (CheckstyleException checkstyleException) {
|
||||
@@ -986,9 +990,7 @@ public final class SiteUtil {
|
||||
@@ -986,9 +996,7 @@ public final class SiteUtil {
|
||||
if (value != null && Array.getLength(value) > 0) {
|
||||
result =
|
||||
removeSquareBrackets(
|
||||
@@ -15016,7 +15041,7 @@
|
||||
}
|
||||
|
||||
if (result.isEmpty()) {
|
||||
@@ -1020,8 +1022,7 @@ public final class SiteUtil {
|
||||
@@ -1020,8 +1028,7 @@ public final class SiteUtil {
|
||||
result = "";
|
||||
} else {
|
||||
try (Stream<?> valuesStream = getValuesStream(value)) {
|
||||
@@ -15026,7 +15051,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1062,10 +1063,7 @@ public final class SiteUtil {
|
||||
@@ -1062,10 +1069,7 @@ public final class SiteUtil {
|
||||
private static String getIntArrayPropertyValue(Object value) {
|
||||
try (IntStream stream = getIntStream(value)) {
|
||||
String result =
|
||||
@@ -15038,7 +15063,7 @@
|
||||
if (result.isEmpty()) {
|
||||
result = CURLY_BRACKETS;
|
||||
}
|
||||
@@ -1170,11 +1168,11 @@ public final class SiteUtil {
|
||||
@@ -1170,11 +1174,11 @@ public final class SiteUtil {
|
||||
*/
|
||||
public static List<Integer> getDifference(int[] tokens, int... subtractions) {
|
||||
final Set<Integer> subtractionsSet =
|
||||
@@ -15052,7 +15077,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1221,7 +1219,7 @@ public final class SiteUtil {
|
||||
@@ -1221,7 +1225,7 @@ public final class SiteUtil {
|
||||
throw new MacroExecutionException("Failed to get parent path for " + templatePath);
|
||||
}
|
||||
return templatePathParent
|
||||
@@ -15418,12 +15443,13 @@
|
||||
}
|
||||
--- a/src/main/java/com/puppycrawl/tools/checkstyle/utils/UnmodifiableCollectionUtil.java
|
||||
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/utils/UnmodifiableCollectionUtil.java
|
||||
@@ -19,13 +19,15 @@
|
||||
@@ -19,13 +19,16 @@
|
||||
|
||||
package com.puppycrawl.tools.checkstyle.utils;
|
||||
|
||||
+import static java.util.stream.Collectors.toUnmodifiableList;
|
||||
+
|
||||
+import com.google.common.collect.ImmutableMap;
|
||||
+import com.google.common.collect.ImmutableSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -15435,7 +15461,7 @@
|
||||
|
||||
/**
|
||||
* <div>Note: it simply wraps the existing JDK methods to provide a workaround for Pitest survival
|
||||
@@ -57,7 +59,7 @@ public final class UnmodifiableCollectionUtil {
|
||||
@@ -57,7 +60,7 @@ public final class UnmodifiableCollectionUtil {
|
||||
* @return An unmodifiable List containing elements of the specified type.
|
||||
*/
|
||||
public static <S, T> List<T> unmodifiableList(Collection<S> items, Class<T> elementType) {
|
||||
@@ -15444,7 +15470,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,6 +94,6 @@ public final class UnmodifiableCollectionUtil {
|
||||
@@ -81,7 +84,7 @@ public final class UnmodifiableCollectionUtil {
|
||||
* @return an immutable copy of the input map
|
||||
*/
|
||||
public static <K, V> Map<K, V> copyOfMap(Map<? extends K, ? extends V> map) {
|
||||
- return Map.copyOf(map);
|
||||
+ return ImmutableMap.copyOf(map);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,6 +95,6 @@ public final class UnmodifiableCollectionUtil {
|
||||
* @return immutable set
|
||||
*/
|
||||
public static <T> Set<T> singleton(T obj) {
|
||||
@@ -56937,6 +56972,15 @@
|
||||
private static final Map<String, Class<?>> FULLY_QUALIFIED_CLASS_NAMES =
|
||||
ImmutableMap.<String, Class<?>>builder()
|
||||
.put("int", int.class)
|
||||
@@ -97,7 +96,7 @@ public class XdocsJavaDocsTest extends AbstractModuleTestSupport {
|
||||
.put("URI", URI.class)
|
||||
.put("WrapOption", WrapOption.class)
|
||||
.put("PARAM_LITERAL", int[].class)
|
||||
- .build();
|
||||
+ .buildOrThrow();
|
||||
|
||||
private static final List<List<Node>> CHECK_PROPERTIES = new ArrayList<>();
|
||||
private static final Map<String, String> CHECK_PROPERTY_DOC = new HashMap<>();
|
||||
@@ -115,14 +114,14 @@ public class XdocsJavaDocsTest extends AbstractModuleTestSupport {
|
||||
}
|
||||
|
||||
|
||||
@@ -4459,6 +4459,15 @@
|
||||
"values from otel have precedence over builder",
|
||||
new TestCase()
|
||||
.expectedProperties(
|
||||
@@ -113,7 +113,7 @@ class OtelAutoConfigTest {
|
||||
.put("otel.exporter.otlp.timeout", Optional.of("13s"))
|
||||
.put("otel.exporter.otlp.metrics.timeout", Optional.empty())
|
||||
.put("otel.service.name", Optional.of("otel-service"))
|
||||
- .build())
|
||||
+ .buildOrThrow())
|
||||
.expectedResourceAttributes(
|
||||
ImmutableMap.of(
|
||||
"key",
|
||||
@@ -128,7 +128,7 @@ class OtelAutoConfigTest {
|
||||
"otel-version"))
|
||||
.exporterBuilder(OtelAutoConfigTest::setBuilderValues)
|
||||
@@ -4468,15 +4477,44 @@
|
||||
"values from prom properties have precedence over builder and otel",
|
||||
new TestCase()
|
||||
.expectedProperties(
|
||||
@@ -177,7 +177,7 @@ class OtelAutoConfigTest {
|
||||
@@ -143,7 +143,7 @@ class OtelAutoConfigTest {
|
||||
.put("otel.exporter.otlp.metrics.timeout", Optional.of("23s"))
|
||||
.put("otel.exporter.otlp.timeout", Optional.of("13s"))
|
||||
.put("otel.service.name", Optional.of("prom-service"))
|
||||
- .build())
|
||||
+ .buildOrThrow())
|
||||
.expectedResourceAttributes(
|
||||
ImmutableMap.of(
|
||||
"key",
|
||||
@@ -176,8 +176,8 @@ class OtelAutoConfigTest {
|
||||
.put(
|
||||
"io.prometheus.exporter.opentelemetry.resourceAttributes",
|
||||
"key=prom-value")
|
||||
.build())),
|
||||
- .build())),
|
||||
- Arguments.of(
|
||||
+ .buildOrThrow())),
|
||||
+ arguments(
|
||||
"values from prom properties builder have precedence over builder and otel",
|
||||
new TestCase()
|
||||
.expectedProperties(
|
||||
@@ -192,7 +192,7 @@ class OtelAutoConfigTest {
|
||||
.put("otel.exporter.otlp.metrics.timeout", Optional.of("23s"))
|
||||
.put("otel.exporter.otlp.timeout", Optional.of("13s"))
|
||||
.put("otel.service.name", Optional.of("prom-service"))
|
||||
- .build())
|
||||
+ .buildOrThrow())
|
||||
.expectedResourceAttributes(
|
||||
ImmutableMap.of(
|
||||
"key",
|
||||
@@ -233,7 +233,7 @@ class OtelAutoConfigTest {
|
||||
.put(
|
||||
"otel.resource.attributes",
|
||||
"key=otel-value,service.namespace=otel-namespace,service.instance.id=otel-instance,service.version=otel-version")
|
||||
- .build();
|
||||
+ .buildOrThrow();
|
||||
}
|
||||
|
||||
private static void setBuilderValues(OpenTelemetryExporter.Builder builder) {
|
||||
@@ -250,8 +250,8 @@ class OtelAutoConfigTest {
|
||||
.resourceAttribute("key", "builder-value");
|
||||
}
|
||||
@@ -4565,7 +4603,12 @@
|
||||
}
|
||||
--- a/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/otelmodel/PrometheusMetricDataTest.java
|
||||
+++ b/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/otelmodel/PrometheusMetricDataTest.java
|
||||
@@ -7,7 +7,7 @@ import io.prometheus.metrics.model.snapshots.Unit;
|
||||
@@ -3,14 +3,15 @@ package io.prometheus.metrics.exporter.opentelemetry.otelmodel;
|
||||
import static java.util.Map.entry;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
+import com.google.common.collect.ImmutableMap;
|
||||
import io.prometheus.metrics.model.snapshots.Unit;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -4573,7 +4616,11 @@
|
||||
+final class PrometheusMetricDataTest {
|
||||
|
||||
Map<Object, Object> translations =
|
||||
Map.ofEntries(
|
||||
- Map.ofEntries(
|
||||
+ ImmutableMap.ofEntries(
|
||||
entry("days", "d"),
|
||||
entry("hours", "h"),
|
||||
entry("minutes", "min"),
|
||||
--- a/prometheus-metrics-exporter-pushgateway/src/main/java/io/prometheus/metrics/exporter/pushgateway/DefaultJobLabelDetector.java
|
||||
+++ b/prometheus-metrics-exporter-pushgateway/src/main/java/io/prometheus/metrics/exporter/pushgateway/DefaultJobLabelDetector.java
|
||||
@@ -3,7 +3,6 @@ package io.prometheus.metrics.exporter.pushgateway;
|
||||
|
||||
Reference in New Issue
Block a user