From e8ce80ba0a01bf56ca002e47bc82cb0241972e12 Mon Sep 17 00:00:00 2001 From: Vitor Mussatto Date: Mon, 21 Feb 2022 15:00:19 +0100 Subject: [PATCH] Adding listOf templates for up to 5 items --- .../CollectionTemplates.java | 1 - .../ImmutableListTemplates.java | 48 +++++++++++++++++++ .../ImmutableListTemplatesTestInput.java | 20 +++++++- .../ImmutableListTemplatesTestOutput.java | 20 +++++++- 4 files changed, 84 insertions(+), 5 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/CollectionTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/CollectionTemplates.java index 91f89421de2..aea3761bb7f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/CollectionTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/CollectionTemplates.java @@ -402,5 +402,4 @@ Optional after(Queue queue) { // XXX: collection.stream().noneMatch(e -> e.equals(other)) // ^ This is !collection.contains(other). Do we already rewrite variations on this? - } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java index 6b34051f09b..9c5f382f453 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java @@ -211,4 +211,52 @@ ImmutableCollection after(T item) { return ImmutableList.of(item); } } + + static final class ImmutableListOf2 { + @BeforeTemplate + List before(T item, T item2) { + return List.of(item, item2); + } + + @AfterTemplate + ImmutableCollection after(T item, T item2) { + return ImmutableList.of(item, item2); + } + } + + static final class ImmutableListOf3 { + @BeforeTemplate + List before(T i1, T i2, T i3) { + return List.of(i1, i2, i3); + } + + @AfterTemplate + ImmutableCollection after(T i1, T i2, T i3) { + return ImmutableList.of(i1, i2, i3); + } + } + + static final class ImmutableListOf4 { + @BeforeTemplate + List before(T i1, T i2, T i3, T i4) { + return List.of(i1, i2, i3, i4); + } + + @AfterTemplate + ImmutableCollection after(T i1, T i2, T i3, T i4) { + return ImmutableList.of(i1, i2, i3, i4); + } + } + + static final class ImmutableListOf5 { + @BeforeTemplate + List before(T i1, T i2, T i3, T i4, T i5) { + return List.of(i1, i2, i3, i4, i5); + } + + @AfterTemplate + ImmutableCollection after(T i1, T i2, T i3, T i4, T i5) { + return ImmutableList.of(i1, i2, i3, i4, i5); + } + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListTemplatesTestInput.java index 6b84e41d3cd..f4b56376dba 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListTemplatesTestInput.java @@ -90,7 +90,23 @@ List testImmutableListOfTyped() { return Collections.emptyList(); } - ImmutableSet> testImmutableList1() { - return ImmutableSet.of(List.of("1")); + Collection testImmutableListOf1() { + return List.of("1"); + } + + Collection testImmutableListOf2() { + return List.of("1", "2"); + } + + Collection testImmutableListOf3() { + return List.of("1", "2", "3"); + } + + Collection testImmutableListOf4() { + return List.of("1", "2", "3", "4"); + } + + Collection testImmutableListOf5() { + return List.of("1", "2", "3", "4", "5"); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListTemplatesTestOutput.java index fede952e203..18d9b559012 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListTemplatesTestOutput.java @@ -85,7 +85,23 @@ List testImmutableListOfTyped() { return ImmutableList.of(); } - ImmutableSet> testImmutableList1() { - return ImmutableSet.of(ImmutableList.of("1")); + Collection testImmutableListOf1() { + return ImmutableList.of("1"); + } + + Collection testImmutableListOf2() { + return ImmutableList.of("1", "2"); + } + + Collection testImmutableListOf3() { + return ImmutableList.of("1", "2", "3"); + } + + Collection testImmutableListOf4() { + return ImmutableList.of("1", "2", "3", "4"); + } + + Collection testImmutableListOf5() { + return ImmutableList.of("1", "2", "3", "4", "5"); } }