Skip to content

Commit

Permalink
Refaster rule to convert Stream.of() -> Stream.empty() (#1061)
Browse files Browse the repository at this point in the history
Add Refaster rule to convert Stream.of() -> Stream.empty()
  • Loading branch information
ferozco authored and bulldozer-bot[bot] committed Nov 20, 2019
1 parent 686d71f commit 90ed907
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.baseline.refaster;

import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import java.util.stream.Stream;

public final class StreamEmpty<T> {

@BeforeTemplate
Stream<T> streamNoParams() {
return Stream.of();
}

@AfterTemplate
Stream<T> streamEmpty() {
return Stream.empty();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.baseline.refaster;

import org.junit.Test;

public class StreamEmptyTest {

@Test
public void test() {
RefasterTestHelper
.forRefactoring(StreamEmpty.class)
.withInputLines(
"Test",
"import java.util.*;",
"import java.util.stream.Stream;",
"public class Test {",
" Stream<Integer> i = Stream.of();",
"}")
.hasOutputLines(
"import java.util.*;",
"import java.util.stream.Stream;",
"public class Test {",
" Stream<Integer> i = Stream.empty();",
"}");
}
}
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1061.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Add Refaster rule to convert Stream.of() -> Stream.empty()
links:
- https://github.com/palantir/gradle-baseline/pull/1061

0 comments on commit 90ed907

Please sign in to comment.