Skip to content

Commit

Permalink
add refaster rule to migrate away from orElse(supplier.get()) (#679)
Browse files Browse the repository at this point in the history
Add refaster rule to migrate away from optional.orElse(supplier.get())
  • Loading branch information
ferozco authored and bulldozer-bot[bot] committed Jul 8, 2019
1 parent 70a20c6 commit fdf6e85
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* (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.Optional;
import java.util.function.Supplier;

public class OptionalOrElseSupplier<T> {
@BeforeTemplate
final T eagerOrElse(Optional<T> optional, Supplier<T> supplier) {
return optional.orElse(supplier.get());
}

@AfterTemplate
final T lazyOrElse(Optional<T> optional, Supplier<T> supplier) {
return optional.orElseGet(supplier);
}
}
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-679.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Add refaster rule to migrate away from optional.orElse(supplier.get())
links:
- https://github.com/palantir/gradle-baseline/pull/679

0 comments on commit fdf6e85

Please sign in to comment.