Skip to content

Conversation

Comment on lines 29 to 36
void testSwitch2(Object o) { // 1, function declaration
switch (o) { // 2 switch
case Integer i -> {}
case Point(int x, int y) when (x == 0 && y == 0) -> {} // 3, when - 4, &&
case Point(int x, int y) when x == 0 -> {} // 5, when
default -> {}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about it, but shouldn't it be more reasonable if we ignore everything inside the switch when switchBlockAsSingleDecisionPoint is true? because basically, we should treat switch as a single decision point so considering when and && as decision points and adding 1 to them is odd to me when this option is true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add traditional switches in here with nested if statements to allow us to compare how this check handles them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, it got counted.

if (switchBlockAsSingleDecisionPoint) {
if (ast.getType() != TokenTypes.LITERAL_CASE) {
incrementCurrentValue(BigInteger.ONE);
}

looks like we only ignore case when this option is true but anything else inside the switch will be counted

@mahfouz72
Copy link
Member Author

github, generate site

@mahfouz72
Copy link
Member Author

github, generate report

Copy link
Contributor

@nrmancuso nrmancuso self-assigned this Jul 25, 2024
@mahfouz72 mahfouz72 force-pushed the cyclomatic-when branch 2 times, most recently from 87d431a to 410ca20 Compare July 25, 2024 12:18
@nrmancuso nrmancuso assigned rnveach and unassigned nrmancuso Jul 26, 2024
@nrmancuso nrmancuso requested a review from rnveach July 26, 2024 16:03
@mahfouz72
Copy link
Member Author

github, generate site

@rnveach rnveach merged commit e071377 into checkstyle:master Aug 1, 2024
111 checks passed
@mahfouz72 mahfouz72 deleted the cyclomatic-when branch May 9, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Add Check Support for Java 21 Pattern Matching for Switch Syntax: CyclomaticComplexity
3 participants