jhaabhijeet864 opened a new pull request, #4082: URL: https://github.com/apache/incubator-kie-tools/pull/4082
Closes https://github.com/apache/incubator-kie-tools/issues/4054 ### Description In DRL rule consequences (\ hen\ blocks), unbraced \if\, \else if\, and \else\ statements were formatted at the same indentation level as their headers. This change applies standard Java indentation rules to unbraced \if-else\ constructs: - Single-statement consequences are indented one level in (\aseDepth + 1\) from the header. - \else\ and \else if\ branches align to the \aseDepth\ of their matching \if\ clause. - Sibling statements following an unbraced \if-else\ chain return to the enclosing base indentation depth. - The scope is strictly limited to \if\, \else if\, and \else\ constructs. ### Changes - \packages/drools-lsp/drools-formatter/src/main/java/org/drools/formatter/RhsFormatter.java\: - Added \IfContext\ state tracker to track header base depths and pending consequence status. - Added pre-emit alignment in \emitRhsStatementInBlock\ to restore depth for \else\ branches and sibling statements. - Added post-emit stack updates to indent unbraced consequence bodies and pop completed chains. - Added helper methods: \isUnbracedIfElseHeader\, \isIfOrElseIfHeader\, \startsLikeElse\, \lignDepthForElse\, and \popCompletedIfContexts\. - \packages/drools-lsp/drools-formatter/src/test/java/org/drools/formatter/FormatterConsequenceIfElseTest.java\: - Added unit test suite covering unbraced \if\, \if/else\, multi-branch \if/else if/else\, braced/unbraced mixtures, nested \if\ chains, and block-enclosed statements. - Verified idempotency on all test cases (\DRLFormatter.format(formatted).isEqualTo(formatted)\). ### How to test Run the formatter tests with Maven: \\\ash mvn test -Drevision=0.0.0 -Dtest=FormatterConsequenceIfElseTest,FormatterConsequenceSwitchTest,FormatterConsequenceBracketsTest,DRLFormatterTest -pl packages/drools-lsp/drools-formatter \\\ ### Checklist - [x] Linked to an issue: https://github.com/apache/incubator-kie-tools/issues/4054 - [x] Follows pull request title guidelines - [x] Apache License 2.0 header in new source files - [x] Unit tests added and passing -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
