mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Introduce MicrometerRules Refaster rule collection (#1365)
This commit is contained in:
@@ -87,6 +87,11 @@
|
||||
<artifactId>guava</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package tech.picnic.errorprone.refasterrules;
|
||||
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.errorprone.refaster.Refaster;
|
||||
import com.google.errorprone.refaster.annotation.AfterTemplate;
|
||||
import com.google.errorprone.refaster.annotation.BeforeTemplate;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
|
||||
|
||||
/** Refaster rules related to expressions dealing with Micrometer. */
|
||||
// XXX: Consider replacing the `TagsOf[N]` rules with a bug checker, so that various other
|
||||
// expressions (e.g. those creating other collection types, those passing in tags some other way, or
|
||||
// those passing in more tags) can be replaced as wel.
|
||||
@OnlineDocumentation
|
||||
final class MicrometerRules {
|
||||
private MicrometerRules() {}
|
||||
|
||||
/** Prefer using {@link Tags} over other immutable collections. */
|
||||
static final class TagsOf1 {
|
||||
@BeforeTemplate
|
||||
ImmutableCollection<Tag> before(Tag tag) {
|
||||
return Refaster.anyOf(ImmutableSet.of(tag), ImmutableList.of(tag));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Iterable<Tag> after(Tag tag) {
|
||||
return Tags.of(tag);
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer using {@link Tags} over other immutable collections. */
|
||||
static final class TagsOf2 {
|
||||
@BeforeTemplate
|
||||
ImmutableCollection<Tag> before(Tag tag1, Tag tag2) {
|
||||
return Refaster.anyOf(ImmutableSet.of(tag1, tag2), ImmutableList.of(tag1, tag2));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Iterable<Tag> after(Tag tag1, Tag tag2) {
|
||||
return Tags.of(tag1, tag2);
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer using {@link Tags} over other immutable collections. */
|
||||
static final class TagsOf3 {
|
||||
@BeforeTemplate
|
||||
ImmutableCollection<Tag> before(Tag tag1, Tag tag2, Tag tag3) {
|
||||
return Refaster.anyOf(ImmutableSet.of(tag1, tag2, tag3), ImmutableList.of(tag1, tag2, tag3));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Iterable<Tag> after(Tag tag1, Tag tag2, Tag tag3) {
|
||||
return Tags.of(tag1, tag2, tag3);
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer using {@link Tags} over other immutable collections. */
|
||||
static final class TagsOf4 {
|
||||
@BeforeTemplate
|
||||
ImmutableCollection<Tag> before(Tag tag1, Tag tag2, Tag tag3, Tag tag4) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSet.of(tag1, tag2, tag3, tag4), ImmutableList.of(tag1, tag2, tag3, tag4));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Iterable<Tag> after(Tag tag1, Tag tag2, Tag tag3, Tag tag4) {
|
||||
return Tags.of(tag1, tag2, tag3, tag4);
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer using {@link Tags} over other immutable collections. */
|
||||
static final class TagsOf5 {
|
||||
@BeforeTemplate
|
||||
ImmutableCollection<Tag> before(Tag tag1, Tag tag2, Tag tag3, Tag tag4, Tag tag5) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSet.of(tag1, tag2, tag3, tag4, tag5),
|
||||
ImmutableList.of(tag1, tag2, tag3, tag4, tag5));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Iterable<Tag> after(Tag tag1, Tag tag2, Tag tag3, Tag tag4, Tag tag5) {
|
||||
return Tags.of(tag1, tag2, tag3, tag4, tag5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ final class RefasterRulesTest {
|
||||
LongStreamRules.class,
|
||||
MapEntryRules.class,
|
||||
MapRules.class,
|
||||
MicrometerRules.class,
|
||||
MockitoRules.class,
|
||||
MultimapRules.class,
|
||||
NullRules.class,
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package tech.picnic.errorprone.refasterrules;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
|
||||
|
||||
final class MicrometerRulesTest implements RefasterRuleCollectionTestCase {
|
||||
@Override
|
||||
public ImmutableSet<Object> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(ImmutableList.class);
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf1() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSet.of(Tag.of("foo", "v1")), ImmutableList.of(Tag.of("bar", "v2")));
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf2() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSet.of(Tag.of("foo", "v1"), Tag.of("bar", "v2")),
|
||||
ImmutableList.of(Tag.of("baz", "v3"), Tag.of("qux", "v4")));
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf3() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSet.of(Tag.of("foo", "v1"), Tag.of("bar", "v2"), Tag.of("baz", "v3")),
|
||||
ImmutableList.of(Tag.of("qux", "v4"), Tag.of("quux", "v5"), Tag.of("corge", "v6")));
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf4() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSet.of(
|
||||
Tag.of("foo", "v1"), Tag.of("bar", "v2"), Tag.of("baz", "v3"), Tag.of("qux", "v4")),
|
||||
ImmutableList.of(
|
||||
Tag.of("quux", "v5"),
|
||||
Tag.of("corge", "v6"),
|
||||
Tag.of("grault", "v7"),
|
||||
Tag.of("garply", "v8")));
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf5() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSet.of(
|
||||
Tag.of("foo", "v1"),
|
||||
Tag.of("bar", "v2"),
|
||||
Tag.of("baz", "v3"),
|
||||
Tag.of("qux", "v4"),
|
||||
Tag.of("quux", "v5")),
|
||||
ImmutableList.of(
|
||||
Tag.of("corge", "v6"),
|
||||
Tag.of("grault", "v7"),
|
||||
Tag.of("garply", "v8"),
|
||||
Tag.of("waldo", "v9"),
|
||||
Tag.of("fred", "v10")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package tech.picnic.errorprone.refasterrules;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
|
||||
|
||||
final class MicrometerRulesTest implements RefasterRuleCollectionTestCase {
|
||||
@Override
|
||||
public ImmutableSet<Object> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(ImmutableList.class);
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf1() {
|
||||
return ImmutableSet.of(Tags.of(Tag.of("foo", "v1")), Tags.of(Tag.of("bar", "v2")));
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf2() {
|
||||
return ImmutableSet.of(
|
||||
Tags.of(Tag.of("foo", "v1"), Tag.of("bar", "v2")),
|
||||
Tags.of(Tag.of("baz", "v3"), Tag.of("qux", "v4")));
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf3() {
|
||||
return ImmutableSet.of(
|
||||
Tags.of(Tag.of("foo", "v1"), Tag.of("bar", "v2"), Tag.of("baz", "v3")),
|
||||
Tags.of(Tag.of("qux", "v4"), Tag.of("quux", "v5"), Tag.of("corge", "v6")));
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf4() {
|
||||
return ImmutableSet.of(
|
||||
Tags.of(Tag.of("foo", "v1"), Tag.of("bar", "v2"), Tag.of("baz", "v3"), Tag.of("qux", "v4")),
|
||||
Tags.of(
|
||||
Tag.of("quux", "v5"),
|
||||
Tag.of("corge", "v6"),
|
||||
Tag.of("grault", "v7"),
|
||||
Tag.of("garply", "v8")));
|
||||
}
|
||||
|
||||
ImmutableSet<Iterable<Tag>> testTagsOf5() {
|
||||
return ImmutableSet.of(
|
||||
Tags.of(
|
||||
Tag.of("foo", "v1"),
|
||||
Tag.of("bar", "v2"),
|
||||
Tag.of("baz", "v3"),
|
||||
Tag.of("qux", "v4"),
|
||||
Tag.of("quux", "v5")),
|
||||
Tags.of(
|
||||
Tag.of("corge", "v6"),
|
||||
Tag.of("grault", "v7"),
|
||||
Tag.of("garply", "v8"),
|
||||
Tag.of("waldo", "v9"),
|
||||
Tag.of("fred", "v10")));
|
||||
}
|
||||
}
|
||||
5
pom.xml
5
pom.xml
@@ -365,6 +365,11 @@
|
||||
<artifactId>nullaway</artifactId>
|
||||
<version>${version.nullaway}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
<version>1.13.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-bom</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user