Skip to content

Commit

Permalink
Introduce ImmutableList.of().stream() Refaster rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Venorcis authored and Stephan202 committed Oct 7, 2023
1 parent da5eea8 commit 2723e7a
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,84 @@ ImmutableList<T> after(T e1, T e2, T e3, T e4, T e5) {
return ImmutableList.of(e1, e2, e3, e4, e5);
}
}

/**
* Prefer {@link Stream#of(Object[])} over constructing a list and then directly calling {@link
* ImmutableList#stream()} on it.
*/
static final class StreamImmutableListOf1<T> {
@BeforeTemplate
Stream<T> before(T e1) {
return ImmutableList.of(e1).stream();
}

@AfterTemplate
Stream<T> after(T e1) {
return Stream.of(e1);
}
}

/**
* Prefer {@link Stream#of(Object[])} over constructing a list and then directly calling {@link
* ImmutableList#stream()} on it.
*/
static final class StreamImmutableListOf2<T> {
@BeforeTemplate
Stream<T> before(T e1, T e2) {
return ImmutableList.of(e1, e2).stream();
}

@AfterTemplate
Stream<T> after(T e1, T e2) {
return Stream.of(e1, e2);
}
}

/**
* Prefer {@link Stream#of(Object[])} over constructing a list and then directly calling {@link
* ImmutableList#stream()} on it.
*/
static final class StreamImmutableListOf3<T> {
@BeforeTemplate
Stream<T> before(T e1, T e2, T e3) {
return ImmutableList.of(e1, e2, e3).stream();
}

@AfterTemplate
Stream<T> after(T e1, T e2, T e3) {
return Stream.of(e1, e2, e3);
}
}

/**
* Prefer {@link Stream#of(Object[])} over constructing a list and then directly calling {@link
* ImmutableList#stream()} on it.
*/
static final class StreamImmutableListOf4<T> {
@BeforeTemplate
Stream<T> before(T e1, T e2, T e3, T e4) {
return ImmutableList.of(e1, e2, e3, e4).stream();
}

@AfterTemplate
Stream<T> after(T e1, T e2, T e3, T e4) {
return Stream.of(e1, e2, e3, e4);
}
}

/**
* Prefer {@link Stream#of(Object[])} over constructing a list and then directly calling {@link
* ImmutableList#stream()} on it.
*/
static final class StreamImmutableListOf5<T> {
@BeforeTemplate
Stream<T> before(T e1, T e2, T e3, T e4, T e5) {
return ImmutableList.of(e1, e2, e3, e4, e5).stream();
}

@AfterTemplate
Stream<T> after(T e1, T e2, T e3, T e4, T e5) {
return Stream.of(e1, e2, e3, e4, e5);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,24 @@ List<Integer> testImmutableListOf4() {
List<Integer> testImmutableListOf5() {
return List.of(1, 2, 3, 4, 5);
}

Stream<Integer> testStreamImmutableListOf1() {
return ImmutableList.of(1).stream();
}

Stream<Integer> testStreamImmutableListOf2() {
return ImmutableList.of(1, 2).stream();
}

Stream<Integer> testStreamImmutableListOf3() {
return ImmutableList.of(1, 2, 3).stream();
}

Stream<Integer> testStreamImmutableListOf4() {
return ImmutableList.of(1, 2, 3, 4).stream();
}

Stream<Integer> testStreamImmutableListOf5() {
return ImmutableList.of(1, 2, 3, 4, 5).stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,24 @@ List<Integer> testImmutableListOf4() {
List<Integer> testImmutableListOf5() {
return ImmutableList.of(1, 2, 3, 4, 5);
}

Stream<Integer> testStreamImmutableListOf1() {
return Stream.of(1);
}

Stream<Integer> testStreamImmutableListOf2() {
return Stream.of(1, 2);
}

Stream<Integer> testStreamImmutableListOf3() {
return Stream.of(1, 2, 3);
}

Stream<Integer> testStreamImmutableListOf4() {
return Stream.of(1, 2, 3, 4);
}

Stream<Integer> testStreamImmutableListOf5() {
return Stream.of(1, 2, 3, 4, 5);
}
}

0 comments on commit 2723e7a

Please sign in to comment.