Skip to content

Conversation

marek-parfianowicz
Copy link
Member

See issue #126.

@marek-parfianowicz marek-parfianowicz self-assigned this Nov 5, 2023
@marek-parfianowicz marek-parfianowicz added this to the 4.5.2 milestone Nov 5, 2023
…or switch expressions and switch statements when yield and break are allowed or not
… return values, be void, or throw exceptions
…ase matcher, including special cases like 'case null, default'; also a test verifying that mixing different forms of case in a single statement is not allowed
…ar, first fix was to not treat entire case as a lambda function, but as a simple value, followed by ->, followed by an expression; a second fix was to match a semicolon after an expression; JavaSyntax14CompilationTest correct regexps in switchStatementWithCaseWithColonCanUseBreak (there are extra if-boolean inserted, regex does not match multi-line); ignore switchStatementWithCaseWithColonCannotUseYield as grammar is not so strict
…h the colon-based and the lambda-based switch can be used inside expressions; both the colon-based and the lambda-based can be a standalone statement (in the latter case the lambda-based needs to call void lambdas); using semantic predicates for disambiguation of both formats; returning ContextSetAndComplexity from both types of switches
…e RecorderInstrEmitter generates two helper caseInc() methods
…returning and void expressions are wrapped inside helper caseInc(); throw expressions are converted to blocks with R.inc() before throw
…t single values (JLS specifies it shall be a constant expression, e.g. without method calls, but we're not restricting this); JavaSyntaxCompilationTestBase - change R_CASE_EXPRESSION_RIGHT to simplify asserts; Java14SwitchExpressionWithMultiValueCase - correct test case as it failed on not covering all cases in switch blocks; JavaSyntax14CompilationTest - correct assertions in test cases (mainly placement of space characters)
…anguage specification), they're used in case labels in both forms of the switch expression/statement
…e ternary expressions and since JDK14 also switch expressions in practically every place, a single expression might not have a cyclomatic complexity equal to 0, as somewhere in the expression tree there might be ?: or switch; this non-zero value must be propagated through all possible levels of expressions, even in crazy places like inside array size initializer (see lambdaSwitchExpressionInsideArrayInitializer example), variable declaration, for loop init/condition/iterator, while and do-while conditions, even a throw statement or an expression lambda can have a switch inside
…ase and over a dozen of test classes; add a test of complexityOfTernaryOperator in ExpressionComplexityCounterTest; remove counting ternaryComplexity=1 in conditionalExpression as it's already accounted for in the ExpressionInfo.fromTokens counter
… argument lists (as they might have switch expressions, for instance)
@marek-parfianowicz marek-parfianowicz merged commit ffe1ca4 into master Jan 31, 2024
@marek-parfianowicz marek-parfianowicz deleted the OC-126-java14-switch-expressions branch January 31, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant