From 12060422e4945ba2637e8e9e4a8cc4d8a1aa94d7 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Thu, 21 Nov 2019 07:19:34 -0500 Subject: [PATCH] Revert "Refaster rule to remove unnecessary supplier creation (#1059)" The refaster rule breaks the common pattern: `Suppliers.memoize(supplier::get)`. This reverts commit 686d71f1be37ea1737f62052e9390b2c630c2a84. --- .../refaster/SupplierRedefinition.java | 42 --------------- .../refaster/SupplierRedefinitionTest.java | 51 ------------------- 2 files changed, 93 deletions(-) delete mode 100644 baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/SupplierRedefinition.java delete mode 100644 baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/SupplierRedefinitionTest.java diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/SupplierRedefinition.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/SupplierRedefinition.java deleted file mode 100644 index c0079e76a..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/SupplierRedefinition.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * (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.function.Supplier; - -/** No reason to redefine a supplier when the target type is also a supplier. */ -final class SupplierRedefinition { - - @BeforeTemplate - @SuppressWarnings({"Convert2MethodRef", "FunctionalExpressionCanBeFolded"}) - Supplier before1(Supplier input) { - return () -> input.get(); - } - - @BeforeTemplate - @SuppressWarnings("FunctionalExpressionCanBeFolded") - Supplier before2(Supplier input) { - return input::get; - } - - @AfterTemplate - Supplier after(Supplier input) { - return input; - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/SupplierRedefinitionTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/SupplierRedefinitionTest.java deleted file mode 100644 index 421dcd8d4..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/SupplierRedefinitionTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * (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 SupplierRedefinitionTest { - - @Test - public void test() { - RefasterTestHelper - .forRefactoring(SupplierRedefinition.class) - .withInputLines( - "Test", - "import java.util.*;", - "import java.util.function.*;", - "class Test {", - " String func1(Optional in, Supplier defaultValue) {", - " return in.orElseGet(() -> defaultValue.get());", - " }", - " String func2(Optional in, Supplier defaultValue) {", - " return in.orElseGet(defaultValue::get);", - " }", - "}") - .hasOutputLines( - "import java.util.*;", - "import java.util.function.*;", - "class Test {", - " String func1(Optional in, Supplier defaultValue) {", - " return in.orElseGet(defaultValue);", - " }", - " String func2(Optional in, Supplier defaultValue) {", - " return in.orElseGet(defaultValue);", - " }", - "}"); - } -}