From 3e41a6b5228cce439cd6ac7f4e5f253a1b3b5386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg-Michael=20Grassau?= Date: Fri, 9 Feb 2024 12:48:05 +0100 Subject: [PATCH] fix AlignSelectListsRule for SELECT SINGLE FOR UPDATE * (#241) --- .../rules/alignment/AlignSelectListsRule.java | 5 +++-- .../rules/alignment/AlignSelectListsTest.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/com.sap.adt.abapcleaner/src/com/sap/adt/abapcleaner/rules/alignment/AlignSelectListsRule.java b/com.sap.adt.abapcleaner/src/com/sap/adt/abapcleaner/rules/alignment/AlignSelectListsRule.java index bdf26307..a2123e09 100644 --- a/com.sap.adt.abapcleaner/src/com/sap/adt/abapcleaner/rules/alignment/AlignSelectListsRule.java +++ b/com.sap.adt.abapcleaner/src/com/sap/adt/abapcleaner/rules/alignment/AlignSelectListsRule.java @@ -196,12 +196,13 @@ private boolean executeOn(Code code, SelectQuery query, SelectClause clauseType, boolean skip = false; Token start = null; if (clauseType == SelectClause.SELECT && !query.hasSelectListInSelectClause()) { - // SELECT [SINGLE [FOR UPDATE]] + // SELECT [SINGLE [FOR UPDATE]], if directly followed 'FROM' skip = true; } else if (clauseType == SelectClause.SELECT || clauseType == SelectClause.FIELDS) { start = clause.firstToken.getNextCodeSibling(); - while (start.isAnyKeyword("SINGLE", "DISTINCT")) + // skip [DISTINCT] | [SINGLE [FOR UPDATE]] + while (start.isAnyKeyword("DISTINCT", "SINGLE", "FOR", "UPDATE")) start = start.getNextCodeSibling(); // skip 'SELECT|FIELDS [DISTINCT] (column_syntax)' and 'SELECT|FIELDS [DISTINCT] *' skip = opensDynamicSyntax(start, clause) || start.textEquals("*") && start == clause.lastToken; diff --git a/test/com.sap.adt.abapcleaner.test/src/com/sap/adt/abapcleaner/rules/alignment/AlignSelectListsTest.java b/test/com.sap.adt.abapcleaner.test/src/com/sap/adt/abapcleaner/rules/alignment/AlignSelectListsTest.java index 9aa72ed4..20485d5c 100644 --- a/test/com.sap.adt.abapcleaner.test/src/com/sap/adt/abapcleaner/rules/alignment/AlignSelectListsTest.java +++ b/test/com.sap.adt.abapcleaner.test/src/com/sap/adt/abapcleaner/rules/alignment/AlignSelectListsTest.java @@ -813,4 +813,18 @@ void testAnonymousFieldWithCase() { testRule(); } + + @Test + void testSelectSingleForUpdate() { + // ensure that SELECT SINGLE FOR UPDATE works in non-strict syntax, too (i.e. if a field list follows) + buildSrc(" SELECT SINGLE FOR UPDATE * FROM any_dtab"); + buildSrc(" INTO ls_any"); + buildSrc(" WHERE any_key = 1."); + + copyExpFromSrc(); + + putAnyMethodAroundSrcAndExp(); + + testRule(); + } }