forked from checkstyle/checkstyle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#4639: added support for lambdas in UnnecessaryParent…
…heses
- Loading branch information
1 parent
e15a50d
commit 1b7bd7d
Showing
13 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...s/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesLambdas.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.puppycrawl.tools.checkstyle.checks.coding.unnecessaryparentheses; | ||
|
||
import java.io.Serializable; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
public class InputUnnecessaryParenthesesLambdas { | ||
int foo(int y) { | ||
MathOperation case1 = (x) -> x + x; | ||
MathOperation case2 = (x) -> { return x + x; }; | ||
MathOperation case3 = (int x) -> x + x; | ||
MathOperation case4 = x -> x + x; | ||
MathOperation2 case5 = (a, b) -> a + b; | ||
MathOperation2 case6 = (int a, int b) -> a + b; | ||
MathOperation2 case7 = (int a, int b) -> { return a + b; }; | ||
Objects.requireNonNull(null, () -> "message"); | ||
call((x) -> x + x); | ||
new HashSet<Integer>().stream().filter((filter) -> filter > 0); | ||
return y; | ||
} | ||
|
||
static <T> CheckedFunction1<T, T> identitity() { | ||
return t -> t; | ||
} | ||
|
||
public interface CheckedFunction2<T1, T2, R> extends Lambda<R> { | ||
R apply(T1 t1, T2 t2) throws Throwable; | ||
|
||
default CheckedFunction1<T2, R> apply(T1 t1) { | ||
return (T2 t2) -> apply(t1, t2); | ||
} | ||
@Override | ||
default Function1<T1, CheckedFunction1<T2, R>> curried() { | ||
return t1 -> t2 -> apply(t1, t2); | ||
} | ||
default Function1<T1, CheckedFunction1<T2, R>> curried2() { | ||
return (t1) -> (t2) -> apply(t1, t2); | ||
} | ||
default Function1<T1, CheckedFunction1<T2, R>> curried3() { | ||
return (t1) -> t2 -> apply(t1, t2); | ||
} | ||
default Function1<T1, CheckedFunction1<T2, R>> curried4() { | ||
return t1 -> (t2) -> apply(t1, t2); | ||
} | ||
} | ||
|
||
private void call(MathOperation o) { | ||
o.operation(1); | ||
} | ||
|
||
interface MathOperation { | ||
int operation(int a); | ||
} | ||
|
||
interface MathOperation2 { | ||
int operation(int a, int b); | ||
} | ||
|
||
interface Lambda<R> extends Serializable { | ||
Lambda<?> curried(); | ||
} | ||
|
||
public interface Function1<T1, R> extends Lambda<R>, Function<T1, R> { | ||
@Override | ||
default Function1<T1, R> curried() { | ||
return this; | ||
} | ||
} | ||
|
||
public interface CheckedFunction1<T1, R> extends Lambda<R> { | ||
R apply(T1 t1) throws Throwable; | ||
|
||
@Override | ||
default CheckedFunction1<T1, R> curried() { | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters