-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[Feature Request] Make use of Java 17 pattern matching switch statements where possible #17874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@harshavamsi i want to take on this issue. |
…witch statements
…witch statements
@harshavamsi i have opened PR but dont merge it right now because i am going to make this kind of changes in other files. |
…witch statements
…witch statements
…witch statements
…witch statements
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements Signed-off-by: Jay Sabva <[email protected]>
…witch statements Signed-off-by: Jay Sabva <[email protected]>
@JaySabva -- Since this is just code cleanup, the existing unit + integration tests should be sufficient. We expect no changes in behavior, just friendlier code. |
👍 |
@msfroh I might sound silly but I have one question regarding this #17909 (review) How to clean up code like this? I don't see any good way to do it. Please if you can guide me. |
Oh... I don't think that's possible in the general case. For the
@owaiskazi19 -- did you have something else in mind? I'm new to Java's pattern-matching in |
We could also use record pattern matching here public static FileTree getJavaTestAndMainSourceResources(Project project, Action<? super PatternFilterable> filter) {
var testFileTree = getJavaTestSourceSet(project).map(SourceSet::getResources).map(FileTree::getAsFileTree);
var mainFileTree = getJavaMainSourceSet(project).map(SourceSet::getResources).map(FileTree::getAsFileTree);
return switch (new Pair<>(testFileTree, mainFileTree)) {
case Pair<Optional<FileTree>, Optional<FileTree>>(var test, var main)
when test.isPresent() && main.isPresent() ->
test.get().plus(main.get()).matching(filter);
case Pair<Optional<FileTree>, Optional<FileTree>>(var test, var main)
when main.isPresent() ->
main.get().matching(filter);
case Pair<Optional<FileTree>, Optional<FileTree>>(var test, var main)
when test.isPresent() ->
test.get().matching(filter);
default -> null;
};
} |
Is your feature request related to a problem? Please describe
Coming from #17769 (comment), there are many classes (and tests!) where we would replace multiple chained if-statements to make use of switch pattern matching to make them more readable
Describe the solution you'd like
An example class is
NestedHelper.java
where we match the query type in an if-else statement. This can be replaced to use switch statementsRelated component
Other
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: