@abaplint/core 2.120.112 → 2.120.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/build/abaplint.d.ts +9 -5
  2. package/build/src/abap/2_statements/expressions/method_name.js +1 -1
  3. package/build/src/abap/5_syntax/_builtin_call.js +1 -1
  4. package/build/src/abap/5_syntax/_reserved_names.js +12 -0
  5. package/build/src/abap/5_syntax/basic_types.js +94 -8
  6. package/build/src/abap/5_syntax/expressions/_check_header_line.js +62 -0
  7. package/build/src/abap/5_syntax/expressions/inline_data.js +2 -0
  8. package/build/src/abap/5_syntax/expressions/method_call_chain.js +1 -1
  9. package/build/src/abap/5_syntax/expressions/method_call_param.js +4 -0
  10. package/build/src/abap/5_syntax/expressions/method_parameters.js +4 -0
  11. package/build/src/abap/5_syntax/expressions/type_table.js +21 -1
  12. package/build/src/abap/5_syntax/statements/class_data.js +2 -0
  13. package/build/src/abap/5_syntax/statements/data.js +2 -0
  14. package/build/src/abap/5_syntax/statements/delete_internal.js +11 -0
  15. package/build/src/abap/5_syntax/statements/insert_database.js +12 -0
  16. package/build/src/abap/5_syntax/statements/insert_internal.js +14 -2
  17. package/build/src/abap/5_syntax/statements/modify_internal.js +7 -0
  18. package/build/src/abap/5_syntax/statements/write.js +1 -1
  19. package/build/src/abap/5_syntax/syntax.js +9 -0
  20. package/build/src/abap/types/basic/floating_point_type.js +2 -2
  21. package/build/src/abap/types/basic/hex_type.js +2 -2
  22. package/build/src/abap/types/basic/numeric_type.js +2 -2
  23. package/build/src/abap/types/basic/table_type.js +2 -1
  24. package/build/src/abap/types/method_parameters.js +29 -14
  25. package/build/src/ddic.js +9 -9
  26. package/build/src/objects/table_type.js +8 -7
  27. package/build/src/registry.js +1 -1
  28. package/build/src/rules/check_subrc.js +87 -3
  29. package/build/src/rules/commented_code.js +21 -1
  30. package/build/src/rules/forbidden_statement.js +122 -0
  31. package/build/src/rules/implement_methods.js +20 -6
  32. package/build/src/rules/index.js +1 -0
  33. package/build/src/rules/obsolete_statement.js +31 -1
  34. package/package.json +1 -1
@@ -47,6 +47,7 @@ const _reference_1 = require("../5_syntax/_reference");
47
47
  const identifier_1 = require("../1_lexer/tokens/identifier");
48
48
  const _scope_type_1 = require("../5_syntax/_scope_type");
49
49
  const _syntax_input_1 = require("../5_syntax/_syntax_input");
50
+ const _reserved_names_1 = require("../5_syntax/_reserved_names");
50
51
  // the keywords that can follow a parameter in each section, a plain parameter name is read as them
51
52
  const KEYWORDS_AFTER = {
52
53
  "IMPORTING": ["PREFERRED", "EXPORTING", "CHANGING", "RETURNING", "RAISING", "EXCEPTIONS"],
@@ -76,7 +77,6 @@ class MethodParameters {
76
77
  try {
77
78
  this.parse(node, input, parentName, abstractMethod);
78
79
  this.checkNameLengths(input);
79
- this.checkDuplicateNames();
80
80
  }
81
81
  finally {
82
82
  input.scope.pop(node.getEnd());
@@ -213,25 +213,28 @@ class MethodParameters {
213
213
  }
214
214
  const returning = node.findFirstExpression(Expressions.MethodDefReturning);
215
215
  if (returning) {
216
- this.returning = method_def_returning_1.MethodDefReturning.runSyntax(returning, input, ["returning" /* IdentifierMeta.MethodReturning */]);
216
+ const id = method_def_returning_1.MethodDefReturning.runSyntax(returning, input, ["returning" /* IdentifierMeta.MethodReturning */]);
217
+ if (this.isDuplicateName(id, input) === false) {
218
+ this.returning = id;
219
+ }
217
220
  }
218
221
  this.workaroundRAP(node, input, parentName);
219
222
  }
220
- checkDuplicateNames() {
221
- const names = new Set();
222
- for (const parameter of this.getAll()) {
223
- const name = parameter.getName().toUpperCase();
224
- if (names.has(name)) {
225
- throw new Error(`Method parameter "${name}" already defined`);
226
- }
227
- names.add(name);
223
+ /** reports a parameter with the name of an earlier one, the method definition is kept without it */
224
+ isDuplicateName(id, input) {
225
+ const name = id.getName().toUpperCase();
226
+ if (this.getAll().some(p => p.getName().toUpperCase() === name)) {
227
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, id.getToken(), `Method parameter "${name}" already defined`));
228
+ return true;
228
229
  }
230
+ return false;
229
231
  }
230
232
  checkNameLengths(input) {
231
233
  for (const parameter of this.getAll()) {
232
234
  if (parameter.getName().length > 30) {
233
235
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, parameter.getToken(), "Method parameter name longer than 30 characters"));
234
236
  }
237
+ (0, _reserved_names_1.checkReservedName)(parameter.getToken(), input);
235
238
  }
236
239
  }
237
240
  workaroundRAP(node, input, parentName) {
@@ -300,7 +303,8 @@ class MethodParameters {
300
303
  add(target, source, input, meta, abstractMethod) {
301
304
  var _a;
302
305
  this.checkKeywordNames(source, input);
303
- for (const opt of source.findAllExpressions(Expressions.MethodParamOptional)) {
306
+ const optionals = source.findAllExpressions(Expressions.MethodParamOptional);
307
+ for (const opt of optionals) {
304
308
  const p = opt.findDirectExpression(Expressions.MethodParam);
305
309
  if (p === undefined) {
306
310
  continue;
@@ -316,11 +320,19 @@ class MethodParameters {
316
320
  extraMeta.push("abstract" /* IdentifierMeta.Abstract */);
317
321
  }
318
322
  const id = method_param_1.MethodParam.runSyntax(p, input, [...meta, ...extraMeta]);
323
+ if (this.isDuplicateName(id, input)) {
324
+ continue;
325
+ }
319
326
  input.scope.addIdentifier(id);
320
327
  target.push(id);
321
- if (opt.findDirectTokenByText("OPTIONAL")) {
328
+ const optionalToken = opt.findDirectTokenByText("OPTIONAL");
329
+ if (optionalToken) {
322
330
  const name = target[target.length - 1].getName().toUpperCase();
323
331
  this.optional.push(name);
332
+ if (opt.findFirstExpression(Expressions.Default)) {
333
+ const message = "Parameter \"" + id.getName() + "\" cannot have both DEFAULT and OPTIONAL";
334
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, optionalToken, message));
335
+ }
324
336
  }
325
337
  else if (opt.findFirstExpression(Expressions.Default)) {
326
338
  const name = target[target.length - 1].getName().toUpperCase();
@@ -331,13 +343,16 @@ class MethodParameters {
331
343
  }
332
344
  }
333
345
  }
334
- if (target.length > 0) {
346
+ if (optionals.length > 0) {
335
347
  return;
336
348
  }
337
349
  const params = source.findAllExpressions(Expressions.MethodParam);
338
350
  for (const param of params) {
339
351
  const extraMeta = this.isPassByValue(param) ? ["pass_by_value" /* IdentifierMeta.PassByValue */] : [];
340
- target.push(method_param_1.MethodParam.runSyntax(param, input, [...meta, ...extraMeta]));
352
+ const id = method_param_1.MethodParam.runSyntax(param, input, [...meta, ...extraMeta]);
353
+ if (this.isDuplicateName(id, input) === false) {
354
+ target.push(id);
355
+ }
341
356
  }
342
357
  }
343
358
  // A system reads a plain parameter name as a keyword wherever that keyword can stand, measured on 758:
package/build/src/ddic.js CHANGED
@@ -400,7 +400,7 @@ class DDIC {
400
400
  if (input.length === undefined) {
401
401
  return new Types.UnknownType(input.text + " unknown length", input.infoText);
402
402
  }
403
- return new Types.NumericType(parseInt(input.length, 10), input.qualifiedName);
403
+ return new Types.NumericType(parseInt(input.length, 10), extra);
404
404
  case "CHAR": // 1 <= len <= 30000 (1333 for table fields)
405
405
  case "LCHR": // 256 <= len <= 32000
406
406
  if (input.length === undefined) {
@@ -412,10 +412,10 @@ class DDIC {
412
412
  if (input.length === undefined) {
413
413
  return new Types.UnknownType(input.text + " unknown length", input.infoText);
414
414
  }
415
- return new Types.HexType(parseInt(input.length, 10), input.qualifiedName);
415
+ return new Types.HexType(parseInt(input.length, 10), extra);
416
416
  case "TIMN": // Native HANA
417
417
  case "TIMS":
418
- return new Types.TimeType({ qualifiedName: input.qualifiedName }); //HHMMSS
418
+ return new Types.TimeType(extra); //HHMMSS
419
419
  case "DECFLOAT16": // len = 16
420
420
  case "DECFLOAT34": // len = 34
421
421
  case "D16R": // len = 16
@@ -426,25 +426,25 @@ class DDIC {
426
426
  if (input.length === undefined) {
427
427
  return new Types.UnknownType(input.text + " unknown length", input.infoText);
428
428
  }
429
- return new Types.FloatingPointType(parseInt(input.length, 10), input.qualifiedName);
429
+ return new Types.FloatingPointType(parseInt(input.length, 10), extra);
430
430
  case "DATN": // Native HANA
431
431
  case "DATS":
432
- return new Types.DateType({ qualifiedName: input.qualifiedName }); //YYYYMMDD
432
+ return new Types.DateType(extra); //YYYYMMDD
433
433
  case "INT1":
434
434
  case "INT2":
435
435
  case "INT4":
436
- return Types.IntegerType.get({ qualifiedName: input.qualifiedName });
436
+ return Types.IntegerType.get(extra);
437
437
  case "INT8":
438
- return new Types.Integer8Type({ qualifiedName: input.qualifiedName });
438
+ return new Types.Integer8Type(extra);
439
439
  case "SSTR": // 1 <= len <= 1333
440
440
  case "SSTRING": // 1 <= len <= 1333
441
441
  case "STRG": // 256 <= len
442
442
  case "STRING": // 256 <= len
443
- return Types.StringType.get({ qualifiedName: input.qualifiedName });
443
+ return Types.StringType.get(extra);
444
444
  case "RSTR": // 256 <= len
445
445
  case "RAWSTRING": // 256 <= len
446
446
  case "GEOM_EWKB":
447
- return Types.XStringType.get({ qualifiedName: input.qualifiedName });
447
+ return Types.XStringType.get(extra);
448
448
  case "D16S":
449
449
  case "D34S":
450
450
  case "DF16_SCL":
@@ -141,34 +141,35 @@ class TableType extends _abstract_object_1.AbstractObject {
141
141
  }
142
142
  else if (this.parsedXML.rowkind === "S") {
143
143
  const lookup = ddic.lookupTableOrView(this.parsedXML.rowtype);
144
- type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription());
144
+ type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription(), this.getName());
145
145
  if (lookup.object) {
146
146
  references.push({ object: lookup.object });
147
147
  }
148
148
  }
149
149
  else if (this.parsedXML.rowkind === "E") {
150
150
  const lookup = ddic.lookupDataElement(this.parsedXML.rowtype);
151
- type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription());
151
+ type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription(), this.getName());
152
152
  if (lookup.object) {
153
153
  references.push({ object: lookup.object });
154
154
  }
155
155
  }
156
156
  else if (this.parsedXML.rowkind === "L") {
157
157
  const lookup = ddic.lookupTableType(this.parsedXML.rowtype);
158
- type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription());
158
+ type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription(), this.getName());
159
159
  if (lookup.object) {
160
160
  references.push({ object: lookup.object });
161
161
  }
162
162
  }
163
163
  else if (this.parsedXML.rowkind === "R" && this.parsedXML.rowtype === "OBJECT") {
164
- type = new Types.TableType(new basic_1.GenericObjectReferenceType(), tableOptions, this.getName(), this.getDescription());
164
+ type = new Types.TableType(new basic_1.GenericObjectReferenceType(), tableOptions, this.getName(), this.getDescription(), this.getName());
165
165
  }
166
166
  else if (this.parsedXML.rowkind === "R" && this.parsedXML.rowtype === "DATA") {
167
- type = new Types.TableType(new basic_1.DataReference(new Types.DataType()), tableOptions, this.getName(), this.getDescription());
167
+ const row = new basic_1.DataReference(new Types.DataType());
168
+ type = new Types.TableType(row, tableOptions, this.getName(), this.getDescription(), this.getName());
168
169
  }
169
170
  else if (this.parsedXML.rowkind === "R" && this.parsedXML.rowtype !== undefined) {
170
171
  const lookup = ddic.lookupObject(this.parsedXML.rowtype);
171
- type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription());
172
+ type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription(), this.getName());
172
173
  if (lookup.object) {
173
174
  references.push({ object: lookup.object });
174
175
  }
@@ -184,7 +185,7 @@ class TableType extends _abstract_object_1.AbstractObject {
184
185
  decimals: this.parsedXML.decimals,
185
186
  infoText: this.getName(),
186
187
  });
187
- type = new Types.TableType(row, tableOptions, this.getName(), this.getDescription());
188
+ type = new Types.TableType(row, tableOptions, this.getName(), this.getDescription(), this.getName());
188
189
  }
189
190
  }
190
191
  else {
@@ -78,7 +78,7 @@ class Registry {
78
78
  }
79
79
  static abaplintVersion() {
80
80
  // magic, see build script "version.js"
81
- return "2.120.112";
81
+ return "2.120.114";
82
82
  }
83
83
  getDDICReferences() {
84
84
  return this.ddicReferences;
@@ -56,6 +56,10 @@ class CheckSubrcConf extends _basic_rule_config_1.BasicRuleConfig {
56
56
  this.readTable = true;
57
57
  this.assign = true;
58
58
  this.find = true;
59
+ /** CALL FUNCTION with EXCEPTIONS, unless every exception is mapped to 0 */
60
+ this.callFunction = true;
61
+ /** Method call with EXCEPTIONS, unless every exception is mapped to 0 */
62
+ this.callMethod = true;
59
63
  }
60
64
  }
61
65
  exports.CheckSubrcConf = CheckSubrcConf;
@@ -77,7 +81,17 @@ If sy-dbcnt is checked after database statements, it is considered okay.
77
81
 
78
82
  If IS ASSIGNED is checked after assigning, it is considered okay.
79
83
 
80
- FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
84
+ FIND statement with MATCH COUNT is considered okay if subrc is not checked
85
+
86
+ CALL FUNCTION and method calls are checked if they have an EXCEPTIONS addition that maps an exception to a value other than 0,
87
+ including CALL FUNCTION DESTINATION and STARTING NEW TASK. Not checked: calls without EXCEPTIONS, calls where every exception
88
+ is mapped to 0, EXCEPTION-TABLE, CALL FUNCTION IN UPDATE TASK and IN BACKGROUND.
89
+ For CALL FUNCTION the pragma ##FM_SUBRC_OK is also accepted.
90
+
91
+ A call of a method with SUBRC in its name, like check_subrc( ), is considered a check.
92
+
93
+ After ELSE, ELSEIF, WHEN, CATCH and CLEANUP the check continues after the end of the block, as these branches are not run
94
+ after the statement`,
81
95
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
82
96
  pseudoComment: "EC CI_SUBRC",
83
97
  pragma: "##SUBRC_OK",
@@ -102,7 +116,6 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
102
116
  const config = this.getConfig();
103
117
  for (let i = 0; i < statements.length; i++) {
104
118
  const statement = statements[i];
105
- // todo: CALL FUNCTION
106
119
  if (statement.getPragmas().some(t => t.getStr() === this.getMetadata().pragma)) {
107
120
  continue;
108
121
  }
@@ -188,6 +201,22 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
188
201
  const fix = this.buildFix(file, statement);
189
202
  issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity, undefined, [fix]));
190
203
  }
204
+ else if (config.callFunction === true
205
+ && statement.get() instanceof Statements.CallFunction
206
+ && statement.getPragmas().some(t => t.getStr().toUpperCase() === "##FM_SUBRC_OK") === false
207
+ && this.isUpdateOrBackgroundTask(statement) === false
208
+ && this.mapsExceptionToNonZero(statement) === true
209
+ && this.isChecked(i, statements) === false) {
210
+ const fix = this.buildFix(file, statement);
211
+ issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity, undefined, [fix]));
212
+ }
213
+ else if (config.callMethod === true
214
+ && statement.get() instanceof Statements.Call
215
+ && this.mapsExceptionToNonZero(statement) === true
216
+ && this.isChecked(i, statements) === false) {
217
+ const fix = this.buildFix(file, statement);
218
+ issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity, undefined, [fix]));
219
+ }
191
220
  }
192
221
  return issues;
193
222
  }
@@ -202,6 +231,22 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
202
231
  }
203
232
  return false;
204
233
  }
234
+ /** true if the EXCEPTIONS addition maps an exception to a value other than 0, then the call sets sy-subrc */
235
+ mapsExceptionToNonZero(statement) {
236
+ for (const list of statement.findAllExpressions(Expressions.ParameterListExceptions)) {
237
+ for (const exception of list.findDirectExpressions(Expressions.ParameterException)) {
238
+ const value = exception.findDirectExpression(Expressions.Integer);
239
+ if (value === undefined || parseInt(value.concatTokens().replace(/\s/g, ""), 10) !== 0) {
240
+ return true;
241
+ }
242
+ }
243
+ }
244
+ return false;
245
+ }
246
+ isUpdateOrBackgroundTask(statement) {
247
+ const concat = statement.concatTokens().toUpperCase();
248
+ return concat.includes(" IN UPDATE TASK") || concat.includes(" IN BACKGROUND ");
249
+ }
205
250
  isExemptedFind(s) {
206
251
  // see https://github.com/abaplint/abaplint/issues/2130
207
252
  return s.concatTokens().toUpperCase().includes(" MATCH COUNT ") === true;
@@ -223,6 +268,28 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
223
268
  }
224
269
  return false;
225
270
  }
271
+ /** index of the end statement that closes the block the statement at index is in */
272
+ findEnd(index, statements, open, close) {
273
+ let depth = 0;
274
+ for (let i = index + 1; i < statements.length; i++) {
275
+ const statement = statements[i].get();
276
+ if (open.some(o => statement instanceof o)) {
277
+ depth++;
278
+ }
279
+ else if (statement instanceof close) {
280
+ if (depth === 0) {
281
+ return i;
282
+ }
283
+ depth--;
284
+ }
285
+ }
286
+ return statements.length;
287
+ }
288
+ /** a method call like check_subrc( ), the method reads sy-subrc */
289
+ callsSubrcMethod(statement) {
290
+ return statement.get() instanceof Statements.Call
291
+ && statement.findAllExpressions(Expressions.MethodName).some(m => m.concatTokens().toUpperCase().includes("SUBRC"));
292
+ }
226
293
  isChecked(index, statements) {
227
294
  var _a, _b;
228
295
  let assigned = undefined;
@@ -242,9 +309,25 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
242
309
  }
243
310
  }
244
311
  else if (statement.get() instanceof Statements.EndIf
312
+ || statement.get() instanceof Statements.EndCase
313
+ || statement.get() instanceof Statements.EndTry
245
314
  || statement.get() instanceof Statements.EndTestSeam) {
246
315
  continue;
247
316
  }
317
+ else if (statement.get() instanceof Statements.Else
318
+ || statement.get() instanceof Statements.ElseIf) {
319
+ // the other branches are not run after this one, continue after ENDIF
320
+ i = this.findEnd(i, statements, [Statements.If], Statements.EndIf);
321
+ }
322
+ else if (statement.get() instanceof Statements.When
323
+ || statement.get() instanceof Statements.WhenOthers
324
+ || statement.get() instanceof Statements.WhenType) {
325
+ i = this.findEnd(i, statements, [Statements.Case, Statements.CaseType], Statements.EndCase);
326
+ }
327
+ else if (statement.get() instanceof Statements.Catch
328
+ || statement.get() instanceof Statements.Cleanup) {
329
+ i = this.findEnd(i, statements, [Statements.Try], Statements.EndTry);
330
+ }
248
331
  else {
249
332
  if (assigned && concat.includes(assigned)) {
250
333
  return true;
@@ -253,7 +336,8 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
253
336
  return true;
254
337
  }
255
338
  return concat.includes(" SY-SUBRC")
256
- || concat.includes("CL_ABAP_UNIT_ASSERT=>ASSERT_SUBRC");
339
+ || concat.includes("CL_ABAP_UNIT_ASSERT=>ASSERT_SUBRC")
340
+ || this.callsSubrcMethod(statement);
257
341
  }
258
342
  }
259
343
  return false;
@@ -81,7 +81,8 @@ https://docs.abapopenchecks.org/checks/14/`,
81
81
  return [];
82
82
  }
83
83
  let containsStatement = false;
84
- for (const statementNode of statementNodes) {
84
+ for (let i = 0; i < statementNodes.length; i++) {
85
+ const statementNode = statementNodes[i];
85
86
  const statement = statementNode.get();
86
87
  if (this.getConfig().allowIncludeInFugr === true
87
88
  && obj instanceof objects_1.FunctionGroup
@@ -91,6 +92,9 @@ https://docs.abapopenchecks.org/checks/14/`,
91
92
  if (!(statement instanceof _statement_1.Unknown
92
93
  || statement instanceof _statement_1.Empty
93
94
  || statement instanceof _statement_1.Comment)) {
95
+ if (this.isSplitFromText(statementNodes, i)) {
96
+ continue;
97
+ }
94
98
  containsStatement = true;
95
99
  break;
96
100
  }
@@ -102,6 +106,22 @@ https://docs.abapopenchecks.org/checks/14/`,
102
106
  const issue = issue_1.Issue.atRange(file, posStart, posEnd, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
103
107
  return [issue];
104
108
  }
109
+ /**
110
+ * The statement parser splits an Unknown statement at a line break if the rest parses as a statement.
111
+ * In comment text, such a split is code only if no further text follows the statement on its line.
112
+ */
113
+ isSplitFromText(statementNodes, index) {
114
+ const previous = statementNodes[index - 1];
115
+ if (previous === undefined
116
+ || !(previous.get() instanceof _statement_1.Unknown)
117
+ || [".", ","].includes(previous.getLastToken().getStr())) {
118
+ return false;
119
+ }
120
+ const next = statementNodes[index + 1];
121
+ return next !== undefined
122
+ && next.get() instanceof _statement_1.Unknown
123
+ && next.getFirstToken().getRow() === statementNodes[index].getLastToken().getRow();
124
+ }
105
125
  isCommentLine(text) {
106
126
  return (text.substr(0, 1) === "*")
107
127
  || (text.trim().substr(0, 1) === "\"" && text.trim().substr(1, 1) !== "!");
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ForbiddenStatement = exports.ForbiddenStatementConf = void 0;
37
+ const Statements = __importStar(require("../abap/2_statements/statements"));
38
+ const _abap_rule_1 = require("./_abap_rule");
39
+ const _basic_rule_config_1 = require("./_basic_rule_config");
40
+ const issue_1 = require("../issue");
41
+ const _irule_1 = require("./_irule");
42
+ class ForbiddenStatementConf extends _basic_rule_config_1.BasicRuleConfig {
43
+ constructor() {
44
+ super(...arguments);
45
+ /** List of forbidden statements, given as abaplint statement names,
46
+ * case insensitive, spaces, underscores and dashes are ignored,
47
+ * so "READ TABLE", "ReadTable" and "read_table" are the same
48
+ * @uniqueItems true
49
+ */
50
+ this.statements = [];
51
+ }
52
+ }
53
+ exports.ForbiddenStatementConf = ForbiddenStatementConf;
54
+ class ForbiddenStatement extends _abap_rule_1.ABAPRule {
55
+ constructor() {
56
+ super(...arguments);
57
+ this.conf = new ForbiddenStatementConf();
58
+ /** statement class -> configured spelling, used in the message */
59
+ this.forbidden = new Map();
60
+ }
61
+ getMetadata() {
62
+ return {
63
+ key: "forbidden_statement",
64
+ title: "Forbidden Statement",
65
+ shortDescription: `Forbid use of specified statements.`,
66
+ extendedInformation: `Nothing is reported unless statements are configured.
67
+
68
+ A configured entry matches the abaplint statement with the same name, compared case insensitive,
69
+ ignoring spaces, underscores and dashes, so "READ TABLE", "ReadTable" and "read_table" all match ReadTable.
70
+
71
+ The names are the class names in https://github.com/abaplint/abaplint/tree/main/packages/core/src/abap/2_statements/statements,
72
+ some keywords are split into several statements, eg. "INSERT" does not match anything,
73
+ use "InsertInternal" or "InsertDatabase", likewise for DELETE, MODIFY and READ. Entries that do not match a statement are ignored.
74
+
75
+ Each part of a chained statement is checked as a separate statement.`,
76
+ tags: [_irule_1.RuleTag.SingleFile],
77
+ badExample: `* with "statements": ["READ TABLE"]
78
+ READ TABLE items INDEX 1 INTO item.`,
79
+ goodExample: `* with "statements": ["READ TABLE"]
80
+ item = items[ 1 ].`,
81
+ };
82
+ }
83
+ getConfig() {
84
+ return this.conf;
85
+ }
86
+ setConfig(conf) {
87
+ this.conf = conf;
88
+ if (this.conf.statements === undefined) {
89
+ this.conf.statements = [];
90
+ }
91
+ const byName = new Map();
92
+ for (const [name, value] of Object.entries(Statements)) {
93
+ byName.set(ForbiddenStatement.normalize(name), value);
94
+ }
95
+ this.forbidden = new Map();
96
+ for (const entry of this.conf.statements) {
97
+ const found = byName.get(ForbiddenStatement.normalize(entry));
98
+ if (found !== undefined && this.forbidden.has(found) === false) {
99
+ this.forbidden.set(found, entry.trim());
100
+ }
101
+ }
102
+ }
103
+ runParsed(file) {
104
+ if (this.forbidden.size === 0) {
105
+ return [];
106
+ }
107
+ const ret = [];
108
+ for (const s of file.getStatements()) {
109
+ const name = this.forbidden.get(s.get().constructor);
110
+ if (name !== undefined) {
111
+ const message = "Statement \"" + name + "\" is forbidden";
112
+ ret.push(issue_1.Issue.atStatement(file, s, message, this.getMetadata().key, this.conf.severity));
113
+ }
114
+ }
115
+ return ret;
116
+ }
117
+ static normalize(name) {
118
+ return name.toLowerCase().replace(/[\s_-]/g, "");
119
+ }
120
+ }
121
+ exports.ForbiddenStatement = ForbiddenStatement;
122
+ //# sourceMappingURL=forbidden_statement.js.map
@@ -303,12 +303,11 @@ class ImplementMethods extends _abap_rule_1.ABAPRule {
303
303
  const name = m.objectName + "~" + m.method.name;
304
304
  let found = impl.methods.find(m => m.getName().toUpperCase() === name.toUpperCase());
305
305
  if (found === undefined) {
306
- // try looking for ALIASes
307
- for (const alias of def.aliases) {
308
- if (alias.component.toUpperCase() === name.toUpperCase()) {
309
- found = impl.methods.find(m => m.getName().toUpperCase() === alias.name.toUpperCase());
310
- break;
311
- }
306
+ // try looking for ALIASes, also the ones inherited from super classes,
307
+ // "METHODS alias_name REDEFINITION" implements the method through an alias of the super class
308
+ const alias = this.findAlias(def, name);
309
+ if (alias !== undefined) {
310
+ found = impl.methods.find(m => m.getName().toUpperCase() === alias.toUpperCase());
312
311
  }
313
312
  }
314
313
  if (found === undefined && def.superClassName !== undefined) {
@@ -331,6 +330,21 @@ class ImplementMethods extends _abap_rule_1.ABAPRule {
331
330
  }
332
331
  return found !== undefined;
333
332
  }
333
+ /** name of the alias for the component, in the class or in one of its super classes */
334
+ findAlias(def, component) {
335
+ var _a;
336
+ const visited = new Set();
337
+ let current = def;
338
+ while (current !== undefined && !visited.has(current.name.toUpperCase())) {
339
+ visited.add(current.name.toUpperCase());
340
+ const alias = current.aliases.find(a => a.component.toUpperCase() === component.toUpperCase());
341
+ if (alias !== undefined) {
342
+ return alias.name;
343
+ }
344
+ current = current.superClassName ? (_a = this.findClass(current.superClassName)) === null || _a === void 0 ? void 0 : _a.def : undefined;
345
+ }
346
+ return undefined;
347
+ }
334
348
  viaAliasInInterface(m, intf, impl) {
335
349
  for (const a of intf.aliases) {
336
350
  if (a.component.toUpperCase() === m.objectName.toUpperCase() + "~" + m.method.name.toUpperCase()) {
@@ -98,6 +98,7 @@ __exportStar(require("./fm_global_parameters_obsolete"), exports);
98
98
  __exportStar(require("./forbidden_identifier"), exports);
99
99
  __exportStar(require("./forbidden_kernel_write"), exports);
100
100
  __exportStar(require("./forbidden_pseudo_and_pragma"), exports);
101
+ __exportStar(require("./forbidden_statement"), exports);
101
102
  __exportStar(require("./forbidden_void_type"), exports);
102
103
  __exportStar(require("./form_tables_obsolete"), exports);
103
104
  __exportStar(require("./fully_type_constants"), exports);
@@ -112,6 +112,8 @@ class ObsoleteStatementConf extends _basic_rule_config_1.BasicRuleConfig {
112
112
  this.replaceInto = true;
113
113
  this.loopExtract = true;
114
114
  this.sortExtract = true;
115
+ /** Checks for TRANSLATE statement */
116
+ this.translate = true;
115
117
  }
116
118
  }
117
119
  exports.ObsoleteStatementConf = ObsoleteStatementConf;
@@ -168,7 +170,9 @@ POSIX REGEX: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABE
168
170
 
169
171
  OCCURENCES: check for OCCURENCES vs OCCURRENCES
170
172
 
171
- CLIENT SPECIFIED, from 754: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapselect_client_obsolete.html`,
173
+ CLIENT SPECIFIED, from 754: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapselect_client_obsolete.html
174
+
175
+ TRANSLATE: https://help.sap.com/docs/abap-cloud/abap-keywords-standard-abap/translate`,
172
176
  badExample: `REFRESH itab.
173
177
 
174
178
  COMPUTE foo = 2 + 2.
@@ -373,6 +377,11 @@ ENDIF.`,
373
377
  const issue = issue_1.Issue.atStatement(file, staNode, "SORT extract", this.getMetadata().key, this.conf.severity);
374
378
  issues.push(issue);
375
379
  }
380
+ if (this.conf.translate && sta instanceof Statements.Translate) {
381
+ const fix = this.getTranslateFix(file, staNode);
382
+ const issue = issue_1.Issue.atStatement(file, staNode, "TRANSLATE is obsolete", this.getMetadata().key, this.conf.severity, fix);
383
+ issues.push(issue);
384
+ }
376
385
  if ((0, version_1.releaseAtLeast)(configRelease, version_1.Release.v754) && this.conf.clientSpecified
377
386
  && (sta instanceof Statements.Select
378
387
  || sta instanceof Statements.SelectLoop
@@ -495,6 +504,27 @@ ENDIF.`,
495
504
  }
496
505
  return undefined;
497
506
  }
507
+ getTranslateFix(file, statementNode) {
508
+ const tokens = statementNode.getTokens();
509
+ // tokens: TRANSLATE <target> TO UPPER|LOWER CASE .
510
+ // or: TRANSLATE <target> USING <source> .
511
+ if (tokens.length < 4) {
512
+ return undefined;
513
+ }
514
+ const thirdToken = tokens[2].getStr().toUpperCase();
515
+ if (thirdToken !== "TO") {
516
+ return undefined;
517
+ }
518
+ const targetStr = tokens[1].getStr();
519
+ const directionToken = tokens[3].getStr().toUpperCase();
520
+ if (directionToken === "UPPER") {
521
+ return edit_helper_1.EditHelper.replaceRange(file, statementNode.getStart(), statementNode.getEnd(), targetStr + " = to_upper( " + targetStr + " ).");
522
+ }
523
+ else if (directionToken === "LOWER") {
524
+ return edit_helper_1.EditHelper.replaceRange(file, statementNode.getStart(), statementNode.getEnd(), targetStr + " = to_lower( " + targetStr + " ).");
525
+ }
526
+ return undefined;
527
+ }
498
528
  }
499
529
  exports.ObsoleteStatement = ObsoleteStatement;
500
530
  //# sourceMappingURL=obsolete_statement.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.112",
3
+ "version": "2.120.114",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",