Skip to content

Commit 2fd96cc

Browse files
committed
fix IndentRule for multiple commands on same line (SAP#248)
1 parent 73e5d1f commit 2fd96cc

File tree

2 files changed

+23
-0
lines changed
  • com.sap.adt.abapcleaner/src/com/sap/adt/abapcleaner/rules/prettyprinter
  • test/com.sap.adt.abapcleaner.test/src/com/sap/adt/abapcleaner/rules/prettyprinter

2 files changed

+23
-0
lines changed

com.sap.adt.abapcleaner/src/com/sap/adt/abapcleaner/rules/prettyprinter/IndentRule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ else if (alignCommand.firstCodeTokenIsAnyKeyword("CATCH", "CLEANUP"))
162162

163163
public final void executeOn(Code code, Command command, int newIndent) {
164164
Token firstToken = command.getFirstToken();
165+
// skip commands that follow on the same line as the previous command
166+
if (firstToken.lineBreaks == 0 && !command.isFirstCommandInCode()) {
167+
return;
168+
}
165169
if (firstToken.spacesLeft != newIndent) {
166170
command.addIndent(newIndent - firstToken.spacesLeft, 0);
167171
code.addRuleUse(this, command);

test/com.sap.adt.abapcleaner.test/src/com/sap/adt/abapcleaner/rules/prettyprinter/IndentTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,4 +995,23 @@ void testModuleAfterEventBlock() {
995995

996996
testRule();
997997
}
998+
999+
@Test
1000+
void testTwoCommandsOnSameLine() {
1001+
// ensure that the assignment (and with it, then WHEN ... THEN ... ELSE ... lines) are NOT moved,
1002+
// because they follow on the same line as the WHEN command
1003+
1004+
buildSrc(" CASE sy-tabix.");
1005+
buildSrc(" WHEN 1. lv_flag = COND #(");
1006+
buildSrc(" WHEN lv_cond = 1");
1007+
buildSrc(" THEN abap_true");
1008+
buildSrc(" ELSE abap_false ).");
1009+
buildSrc(" ENDCASE.");
1010+
1011+
putAnyMethodAroundSrcAndExp();
1012+
1013+
copyExpFromSrc();
1014+
1015+
testRule();
1016+
}
9981017
}

0 commit comments

Comments
 (0)