@abaplint/cli 2.120.79 → 2.120.81

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 (2) hide show
  1. package/build/cli.js +3205 -227
  2. package/package.json +2 -2
package/build/cli.js CHANGED
@@ -25288,28 +25288,28 @@ BuiltIn.methods = {
25288
25288
  "ABS": {
25289
25289
  counter: BuiltIn.counter++,
25290
25290
  mandatory: {
25291
- "val": new basic_1.FloatType(),
25291
+ "val": new basic_1.NumericGenericType(),
25292
25292
  },
25293
25293
  return: basic_1.IntegerType.get(),
25294
25294
  },
25295
25295
  "ACOS": {
25296
25296
  counter: BuiltIn.counter++,
25297
25297
  mandatory: {
25298
- "val": new basic_1.FloatType(),
25298
+ "val": new basic_1.NumericGenericType(),
25299
25299
  },
25300
25300
  return: new basic_1.FloatType(),
25301
25301
  },
25302
25302
  "ASIN": {
25303
25303
  counter: BuiltIn.counter++,
25304
25304
  mandatory: {
25305
- "val": new basic_1.FloatType(),
25305
+ "val": new basic_1.NumericGenericType(),
25306
25306
  },
25307
25307
  return: new basic_1.FloatType(),
25308
25308
  },
25309
25309
  "ATAN": {
25310
25310
  counter: BuiltIn.counter++,
25311
25311
  mandatory: {
25312
- "val": new basic_1.FloatType(),
25312
+ "val": new basic_1.NumericGenericType(),
25313
25313
  },
25314
25314
  return: new basic_1.FloatType(),
25315
25315
  },
@@ -25343,7 +25343,7 @@ BuiltIn.methods = {
25343
25343
  "CEIL": {
25344
25344
  counter: BuiltIn.counter++,
25345
25345
  mandatory: {
25346
- "val": new basic_1.FloatType(),
25346
+ "val": new basic_1.NumericGenericType(),
25347
25347
  },
25348
25348
  return: basic_1.IntegerType.get(),
25349
25349
  },
@@ -25480,14 +25480,14 @@ BuiltIn.methods = {
25480
25480
  "COS": {
25481
25481
  counter: BuiltIn.counter++,
25482
25482
  mandatory: {
25483
- "val": new basic_1.FloatType(),
25483
+ "val": new basic_1.NumericGenericType(),
25484
25484
  },
25485
25485
  return: new basic_1.FloatType(),
25486
25486
  },
25487
25487
  "COSH": {
25488
25488
  counter: BuiltIn.counter++,
25489
25489
  mandatory: {
25490
- "val": new basic_1.FloatType(),
25490
+ "val": new basic_1.NumericGenericType(),
25491
25491
  },
25492
25492
  return: new basic_1.FloatType(),
25493
25493
  },
@@ -25567,7 +25567,7 @@ BuiltIn.methods = {
25567
25567
  "EXP": {
25568
25568
  counter: BuiltIn.counter++,
25569
25569
  mandatory: {
25570
- "val": new basic_1.FloatType(),
25570
+ "val": new basic_1.NumericGenericType(),
25571
25571
  },
25572
25572
  return: new basic_1.FloatType(),
25573
25573
  },
@@ -25636,14 +25636,14 @@ BuiltIn.methods = {
25636
25636
  "FLOOR": {
25637
25637
  counter: BuiltIn.counter++,
25638
25638
  mandatory: {
25639
- "val": new basic_1.FloatType(),
25639
+ "val": new basic_1.NumericGenericType(),
25640
25640
  },
25641
25641
  return: basic_1.IntegerType.get(),
25642
25642
  },
25643
25643
  "FRAC": {
25644
25644
  counter: BuiltIn.counter++,
25645
25645
  mandatory: {
25646
- "val": new basic_1.FloatType(),
25646
+ "val": new basic_1.NumericGenericType(),
25647
25647
  },
25648
25648
  return: basic_1.IntegerType.get(),
25649
25649
  },
@@ -25675,8 +25675,8 @@ BuiltIn.methods = {
25675
25675
  "IPOW": {
25676
25676
  counter: BuiltIn.counter++,
25677
25677
  mandatory: {
25678
- "base": new basic_1.FloatType(),
25679
- "exp": new basic_1.FloatType(),
25678
+ "base": new basic_1.NumericGenericType(),
25679
+ "exp": new basic_1.NumericGenericType(),
25680
25680
  },
25681
25681
  return: basic_1.IntegerType.get(),
25682
25682
  release: version_1.Release.v740sp02,
@@ -25708,14 +25708,14 @@ BuiltIn.methods = {
25708
25708
  "LOG": {
25709
25709
  counter: BuiltIn.counter++,
25710
25710
  mandatory: {
25711
- "val": new basic_1.FloatType(),
25711
+ "val": new basic_1.NumericGenericType(),
25712
25712
  },
25713
25713
  return: new basic_1.FloatType(),
25714
25714
  },
25715
25715
  "LOG10": {
25716
25716
  counter: BuiltIn.counter++,
25717
25717
  mandatory: {
25718
- "val": new basic_1.FloatType(),
25718
+ "val": new basic_1.NumericGenericType(),
25719
25719
  },
25720
25720
  return: new basic_1.FloatType(),
25721
25721
  },
@@ -25821,7 +25821,7 @@ BuiltIn.methods = {
25821
25821
  "RESCALE": {
25822
25822
  counter: BuiltIn.counter++,
25823
25823
  mandatory: {
25824
- "val": new basic_1.FloatType(),
25824
+ "val": new basic_1.NumericGenericType(),
25825
25825
  },
25826
25826
  optional: {
25827
25827
  "dec": basic_1.IntegerType.get(),
@@ -25842,7 +25842,7 @@ BuiltIn.methods = {
25842
25842
  "ROUND": {
25843
25843
  counter: BuiltIn.counter++,
25844
25844
  mandatory: {
25845
- "val": new basic_1.FloatType(),
25845
+ "val": new basic_1.NumericGenericType(),
25846
25846
  },
25847
25847
  optional: {
25848
25848
  "dec": basic_1.IntegerType.get(),
@@ -25894,28 +25894,28 @@ BuiltIn.methods = {
25894
25894
  "SIGN": {
25895
25895
  counter: BuiltIn.counter++,
25896
25896
  mandatory: {
25897
- "val": new basic_1.FloatType(),
25897
+ "val": new basic_1.NumericGenericType(),
25898
25898
  },
25899
25899
  return: basic_1.IntegerType.get(),
25900
25900
  },
25901
25901
  "SIN": {
25902
25902
  counter: BuiltIn.counter++,
25903
25903
  mandatory: {
25904
- "val": new basic_1.FloatType(),
25904
+ "val": new basic_1.NumericGenericType(),
25905
25905
  },
25906
25906
  return: new basic_1.FloatType(),
25907
25907
  },
25908
25908
  "SINH": {
25909
25909
  counter: BuiltIn.counter++,
25910
25910
  mandatory: {
25911
- "val": new basic_1.FloatType(),
25911
+ "val": new basic_1.NumericGenericType(),
25912
25912
  },
25913
25913
  return: new basic_1.FloatType(),
25914
25914
  },
25915
25915
  "SQRT": {
25916
25916
  counter: BuiltIn.counter++,
25917
25917
  mandatory: {
25918
- "val": new basic_1.FloatType(),
25918
+ "val": new basic_1.NumericGenericType(),
25919
25919
  },
25920
25920
  return: new basic_1.FloatType(),
25921
25921
  },
@@ -26005,14 +26005,14 @@ BuiltIn.methods = {
26005
26005
  "TAN": {
26006
26006
  counter: BuiltIn.counter++,
26007
26007
  mandatory: {
26008
- "val": new basic_1.FloatType(),
26008
+ "val": new basic_1.NumericGenericType(),
26009
26009
  },
26010
26010
  return: new basic_1.FloatType(),
26011
26011
  },
26012
26012
  "TANH": {
26013
26013
  counter: BuiltIn.counter++,
26014
26014
  mandatory: {
26015
- "val": new basic_1.FloatType(),
26015
+ "val": new basic_1.NumericGenericType(),
26016
26016
  },
26017
26017
  return: new basic_1.FloatType(),
26018
26018
  },
@@ -26056,7 +26056,7 @@ BuiltIn.methods = {
26056
26056
  "TRUNC": {
26057
26057
  counter: BuiltIn.counter++,
26058
26058
  mandatory: {
26059
- "val": new basic_1.FloatType(),
26059
+ "val": new basic_1.NumericGenericType(),
26060
26060
  },
26061
26061
  return: basic_1.IntegerType.get(),
26062
26062
  },
@@ -28270,7 +28270,9 @@ class TypeUtils {
28270
28270
  return false;
28271
28271
  }
28272
28272
  else if (source instanceof basic_1.Integer8Type) {
28273
- if (target instanceof basic_1.IntegerType || target instanceof basic_1.StringType) {
28273
+ if (target instanceof basic_1.IntegerType
28274
+ || target instanceof basic_1.StringType
28275
+ || target instanceof basic_1.FloatType) {
28274
28276
  return false;
28275
28277
  }
28276
28278
  }
@@ -33519,7 +33521,7 @@ class MethodCallChain {
33519
33521
  context = component_name_1.ComponentName.runSyntax(context, current, input);
33520
33522
  }
33521
33523
  else if (current instanceof nodes_1.ExpressionNode && current.get() instanceof Expressions.AttributeName) {
33522
- context = attribute_name_1.AttributeName.runSyntax(context, current, input);
33524
+ context = attribute_name_1.AttributeName.runSyntax(context, current, input, _reference_1.ReferenceType.DataReadReference);
33523
33525
  }
33524
33526
  previous = current;
33525
33527
  }
@@ -50561,22 +50563,35 @@ class AbstractNode {
50561
50563
  }
50562
50564
  addChild(n) {
50563
50565
  if (this.children === EMPTY) {
50564
- this.children = [];
50566
+ this.children = n;
50567
+ }
50568
+ else if (Array.isArray(this.children)) {
50569
+ this.children.push(n);
50570
+ }
50571
+ else {
50572
+ this.children = [this.children, n];
50565
50573
  }
50566
- this.children.push(n);
50567
50574
  }
50568
50575
  setChildren(children) {
50569
- // copy, input arrays are built via push() and carry over-allocated backing stores
50570
- this.children = children.slice();
50576
+ if (children.length === 1) {
50577
+ this.children = children[0];
50578
+ }
50579
+ else {
50580
+ // copy, input arrays are built via push() and carry over-allocated backing stores
50581
+ this.children = children.length === 0 ? EMPTY : children.slice();
50582
+ }
50571
50583
  }
50572
50584
  getChildren() {
50573
- return this.children;
50585
+ const children = this.children;
50586
+ return Array.isArray(children) ? children : [children];
50574
50587
  }
50575
50588
  getFirstChild() {
50576
- return this.children[0];
50589
+ const children = this.children;
50590
+ return Array.isArray(children) ? children[0] : children;
50577
50591
  }
50578
50592
  getLastChild() {
50579
- return this.children[this.children.length - 1];
50593
+ const children = this.children;
50594
+ return Array.isArray(children) ? children[children.length - 1] : children;
50580
50595
  }
50581
50596
  }
50582
50597
  exports.AbstractNode = AbstractNode;
@@ -71507,7 +71522,7 @@ class Registry {
71507
71522
  }
71508
71523
  static abaplintVersion() {
71509
71524
  // magic, see build script "version.js"
71510
- return "2.120.79";
71525
+ return "2.120.81";
71511
71526
  }
71512
71527
  getDDICReferences() {
71513
71528
  return this.ddicReferences;
@@ -72021,6 +72036,1220 @@ exports.NamingRuleConfig = NamingRuleConfig;
72021
72036
 
72022
72037
  /***/ },
72023
72038
 
72039
+ /***/ "../core/build/src/rules/_procedure_analysis.js"
72040
+ /*!******************************************************!*\
72041
+ !*** ../core/build/src/rules/_procedure_analysis.js ***!
72042
+ \******************************************************/
72043
+ (__unused_webpack_module, exports, __webpack_require__) {
72044
+
72045
+ "use strict";
72046
+
72047
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
72048
+ if (k2 === undefined) k2 = k;
72049
+ var desc = Object.getOwnPropertyDescriptor(m, k);
72050
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
72051
+ desc = { enumerable: true, get: function() { return m[k]; } };
72052
+ }
72053
+ Object.defineProperty(o, k2, desc);
72054
+ }) : (function(o, m, k, k2) {
72055
+ if (k2 === undefined) k2 = k;
72056
+ o[k2] = m[k];
72057
+ }));
72058
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
72059
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
72060
+ }) : function(o, v) {
72061
+ o["default"] = v;
72062
+ });
72063
+ var __importStar = (this && this.__importStar) || (function () {
72064
+ var ownKeys = function(o) {
72065
+ ownKeys = Object.getOwnPropertyNames || function (o) {
72066
+ var ar = [];
72067
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
72068
+ return ar;
72069
+ };
72070
+ return ownKeys(o);
72071
+ };
72072
+ return function (mod) {
72073
+ if (mod && mod.__esModule) return mod;
72074
+ var result = {};
72075
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
72076
+ __setModuleDefault(result, mod);
72077
+ return result;
72078
+ };
72079
+ })();
72080
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
72081
+ exports.SourceKind = exports.PredicateKind = exports.Procedure = exports.ObjectAnalysis = exports.Variable = exports.OccurrenceKind = void 0;
72082
+ exports.findStructures = findStructures;
72083
+ exports.expressionPath = expressionPath;
72084
+ exports.plainMove = plainMove;
72085
+ exports.singleField = singleField;
72086
+ exports.singleTarget = singleTarget;
72087
+ exports.plainClear = plainClear;
72088
+ exports.plainData = plainData;
72089
+ exports.isImmutable = isImmutable;
72090
+ exports.isReferenceType = isReferenceType;
72091
+ exports.identicalTypes = identicalTypes;
72092
+ exports.simplePredicate = simplePredicate;
72093
+ exports.characterConstant = characterConstant;
72094
+ exports.sameCharacters = sameCharacters;
72095
+ exports.isCondition = isCondition;
72096
+ exports.dataSource = dataSource;
72097
+ exports.targetType = targetType;
72098
+ exports.unchangedBetween = unchangedBetween;
72099
+ exports.mergeEdits = mergeEdits;
72100
+ exports.deleteRegion = deleteRegion;
72101
+ exports.deleteStatement = deleteStatement;
72102
+ exports.rawText = rawText;
72103
+ exports.nodeText = nodeText;
72104
+ exports.ifBranches = ifBranches;
72105
+ exports.selfContained = selfContained;
72106
+ exports.foldIf = foldIf;
72107
+ exports.foldIssues = foldIssues;
72108
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
72109
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
72110
+ const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
72111
+ const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "../core/build/src/abap/2_statements/statements/_statement.js");
72112
+ const tokens_1 = __webpack_require__(/*! ../abap/1_lexer/tokens */ "../core/build/src/abap/1_lexer/tokens/index.js");
72113
+ const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
72114
+ const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/build/src/abap/5_syntax/syntax.js");
72115
+ const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
72116
+ const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
72117
+ const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
72118
+ const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "../core/build/src/objects/_abap_object.js");
72119
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
72120
+ const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
72121
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
72122
+ // Shared analysis for the rules that remove redundant code around local variables:
72123
+ // clear_after_declaration, unnecessary_copy, constant_condition, copy_chain, copy_of_initial_variable,
72124
+ // bound_check_after_create, boolean_flag_via_if, alias_never_reassigned, single_use_expression_temp
72125
+ // and try_cast_empty_catch.
72126
+ //
72127
+ // Everything is derived from the syntax tree and the resolved references of the syntax check,
72128
+ // statements are never matched as text.
72129
+ var OccurrenceKind;
72130
+ (function (OccurrenceKind) {
72131
+ /** the value is read, or only used to reach a referenced object (ref->attr, ref->*) */
72132
+ OccurrenceKind["Read"] = "read";
72133
+ /** the variable itself is changed */
72134
+ OccurrenceKind["Write"] = "write";
72135
+ /** address taken, field symbol binding, USING/TABLES, dynamic, type reference, or a statement
72136
+ * that is not known to only read its operands */
72137
+ OccurrenceKind["Escape"] = "escape";
72138
+ })(OccurrenceKind || (exports.OccurrenceKind = OccurrenceKind = {}));
72139
+ class Variable {
72140
+ constructor(identifier, declaration, inline, occurrences, complete) {
72141
+ this.identifier = identifier;
72142
+ this.declaration = declaration;
72143
+ this.inline = inline;
72144
+ this.occurrences = occurrences;
72145
+ this.complete = complete;
72146
+ }
72147
+ /** declared by DATA, or inline, in the procedure; not a parameter, attribute or STATICS */
72148
+ isLocal() {
72149
+ return this.declaration !== undefined;
72150
+ }
72151
+ reads() {
72152
+ return this.occurrences.filter(o => o.kind === OccurrenceKind.Read);
72153
+ }
72154
+ writes() {
72155
+ return this.occurrences.filter(o => o.kind === OccurrenceKind.Write);
72156
+ }
72157
+ escapes() {
72158
+ return this.occurrences.some(o => o.kind === OccurrenceKind.Escape);
72159
+ }
72160
+ }
72161
+ exports.Variable = Variable;
72162
+ /** References of one object, after a successful syntax check */
72163
+ class ObjectAnalysis {
72164
+ /** returns undefined if the object is not supported, or has syntax errors */
72165
+ static run(reg, obj) {
72166
+ var _a;
72167
+ if (!(obj instanceof _abap_object_1.ABAPObject)) {
72168
+ return undefined;
72169
+ }
72170
+ const syntax = new syntax_1.SyntaxLogic(reg, obj).run();
72171
+ // the rules run one after the other on the same object, the syntax result changes when the object changes
72172
+ if (((_a = ObjectAnalysis.last) === null || _a === void 0 ? void 0 : _a.obj) === obj && ObjectAnalysis.last.syntax === syntax) {
72173
+ return ObjectAnalysis.last.analysis;
72174
+ }
72175
+ const analysis = ObjectAnalysis.build(obj, syntax);
72176
+ ObjectAnalysis.last = { obj, syntax, analysis };
72177
+ return analysis;
72178
+ }
72179
+ static build(obj, syntax) {
72180
+ // Neither macro expansion nor unknown statements have reliable references.
72181
+ for (const file of obj.getABAPFiles()) {
72182
+ for (const statement of file.getStatements()) {
72183
+ const type = statement.get();
72184
+ if (type instanceof _statement_1.Unknown || type instanceof Statements.Define
72185
+ || type instanceof _statement_1.MacroCall || type instanceof _statement_1.MacroContent || type instanceof _statement_1.MacroRecursion) {
72186
+ return undefined;
72187
+ }
72188
+ }
72189
+ }
72190
+ if (syntax.issues.length > 0) {
72191
+ return undefined;
72192
+ }
72193
+ return new ObjectAnalysis(obj, syntax.spaghetti);
72194
+ }
72195
+ constructor(obj, spaghetti) {
72196
+ this.procedures = [];
72197
+ this.byResolved = new Map();
72198
+ this.byPosition = new Map();
72199
+ this.obj = obj;
72200
+ this.spaghetti = spaghetti;
72201
+ const stack = [spaghetti.getTop()];
72202
+ while (stack.length > 0) {
72203
+ const node = stack.pop();
72204
+ for (const reference of node.getData().references) {
72205
+ const position = ObjectAnalysis.key(reference.position);
72206
+ const atPosition = this.byPosition.get(position) || [];
72207
+ atPosition.push(reference);
72208
+ this.byPosition.set(position, atPosition);
72209
+ if (reference.resolved !== undefined) {
72210
+ const resolved = ObjectAnalysis.key(reference.resolved);
72211
+ const list = this.byResolved.get(resolved) || [];
72212
+ list.push(reference);
72213
+ this.byResolved.set(resolved, list);
72214
+ }
72215
+ }
72216
+ stack.push(...node.getChildren());
72217
+ }
72218
+ for (const file of obj.getABAPFiles()) {
72219
+ const structure = file.getStructure();
72220
+ if (structure === undefined) {
72221
+ continue;
72222
+ }
72223
+ for (const procedure of findStructures(structure, [Structures.Method, Structures.Form, Structures.FunctionModule])) {
72224
+ this.procedures.push(new Procedure(this, file, procedure));
72225
+ }
72226
+ }
72227
+ }
72228
+ static key(identifier) {
72229
+ const start = identifier.getStart();
72230
+ return identifier.getFilename() + "," + start.getRow() + "," + start.getCol();
72231
+ }
72232
+ static tokenKey(filename, token) {
72233
+ return filename + "," + token.getRow() + "," + token.getCol();
72234
+ }
72235
+ referencesTo(identifier) {
72236
+ return this.byResolved.get(ObjectAnalysis.key(identifier)) || [];
72237
+ }
72238
+ referencesAt(filename, token) {
72239
+ return this.byPosition.get(ObjectAnalysis.tokenKey(filename, token)) || [];
72240
+ }
72241
+ /** all resolved identifiers, with the positions of their references */
72242
+ allReferences() {
72243
+ return this.byResolved.entries();
72244
+ }
72245
+ }
72246
+ exports.ObjectAnalysis = ObjectAnalysis;
72247
+ const LOOPS = [Structures.Loop, Structures.Do, Structures.While, Structures.Select,
72248
+ Structures.Provide, Structures.LoopAtScreen, Structures.LoopExtract, Structures.With];
72249
+ /** Statements whose data read references are known to only read the value */
72250
+ const READING = [Statements.Move, Statements.Call, Statements.If, Statements.ElseIf,
72251
+ Statements.Case, Statements.When, Statements.While, Statements.Check, Statements.Assert, Statements.Append,
72252
+ Statements.InsertInternal, Statements.ModifyInternal, Statements.DeleteInternal, Statements.ReadTable,
72253
+ Statements.Loop, Statements.CreateObject, Statements.Raise, Statements.Message, Statements.Concatenate,
72254
+ Statements.Split, Statements.Condense, Statements.Translate, Statements.Replace, Statements.Find,
72255
+ Statements.Select, Statements.SelectLoop, Statements.Do, Statements.Write, Statements.Collect,
72256
+ Statements.Describe, Statements.Shift, Statements.Return, Statements.Clear, Statements.Sort,
72257
+ Statements.InsertDatabase, Statements.ModifyDatabase, Statements.UpdateDatabase, Statements.DeleteDatabase];
72258
+ /** Statements which cannot run other ABAP code, unless they contain a method call or NEW */
72259
+ const CALL_FREE = [Statements.Move, Statements.Data, Statements.Clear, Statements.Free,
72260
+ Statements.Append, Statements.InsertInternal, Statements.ModifyInternal, Statements.DeleteInternal,
72261
+ Statements.ReadTable, Statements.Sort, Statements.Concatenate, Statements.Condense, Statements.Split,
72262
+ Statements.Translate, Statements.Replace, Statements.Find, Statements.Shift, Statements.Collect,
72263
+ Statements.Describe, Statements.FieldSymbol, Statements.Constant, Statements.Type, Statements.Unassign,
72264
+ Statements.If, Statements.ElseIf, Statements.Else, Statements.EndIf, Statements.Case, Statements.When,
72265
+ Statements.WhenOthers, Statements.EndCase, Statements.Do, Statements.EndDo, Statements.While, Statements.EndWhile,
72266
+ Statements.Loop, Statements.EndLoop, Statements.Check, Statements.Exit, Statements.Continue, Statements.Return,
72267
+ Statements.Try, Statements.Catch, Statements.Cleanup, Statements.EndTry];
72268
+ /** A METHOD, FORM or FUNCTION implementation */
72269
+ class Procedure {
72270
+ constructor(analysis, file, structure) {
72271
+ var _a, _b, _c;
72272
+ /** all statements, including METHOD and ENDMETHOD */
72273
+ this.statements = [];
72274
+ this.info = new Map();
72275
+ this.parents = new Map();
72276
+ /** identifier tokens by lower case name, positions as row * 100000 + column, the procedure is in one file */
72277
+ this.names = new Map();
72278
+ this.declarations = new Map();
72279
+ this.declarationTokens = [];
72280
+ this.tokens = new Map();
72281
+ this.variables = new Map();
72282
+ this.own = undefined;
72283
+ this.comments = undefined;
72284
+ this.analysis = analysis;
72285
+ this.file = file;
72286
+ this.structure = structure;
72287
+ this.walk(structure, [], undefined, false);
72288
+ this.supported = this.isSupported();
72289
+ if (this.supported === false) {
72290
+ return;
72291
+ }
72292
+ for (const statement of this.statements) {
72293
+ const tokens = this.tokensOf(statement);
72294
+ for (let i = 0; i < tokens.length; i++) {
72295
+ const token = tokens[i];
72296
+ const previous = tokens[i - 1];
72297
+ if (!(token instanceof tokens_1.Identifier)
72298
+ || (previous !== undefined && (previous.getStr() === "->" || previous.getStr() === "=>"
72299
+ || previous.getStr() === "~" || previous instanceof tokens_1.Dash))) {
72300
+ continue;
72301
+ }
72302
+ const name = token.getStr().toLowerCase();
72303
+ const list = this.names.get(name);
72304
+ if (list === undefined) {
72305
+ this.names.set(name, [position(token)]);
72306
+ }
72307
+ else {
72308
+ list.push(position(token));
72309
+ }
72310
+ }
72311
+ const type = statement.get();
72312
+ if (type instanceof Statements.Data && this.isSimple(statement)) {
72313
+ const name = (_b = (_a = statement.findDirectExpression(Expressions.DataDefinition)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.DefinitionName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
72314
+ if (name !== undefined) {
72315
+ this.declarations.set(this.tokenKey(name), statement);
72316
+ this.declarationTokens.push(name);
72317
+ }
72318
+ }
72319
+ if (!(type instanceof Statements.Form) && tokens.some((t, i) => { var _a; return t.getStr().toUpperCase() === "DATA"
72320
+ && ((_a = tokens[i + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) === "("; })) {
72321
+ for (const inline of statement.findAllExpressionsRecursive(Expressions.InlineData)) {
72322
+ const name = (_c = inline.findDirectExpression(Expressions.TargetField)) === null || _c === void 0 ? void 0 : _c.getFirstToken();
72323
+ if (name !== undefined) {
72324
+ this.declarations.set(this.tokenKey(name), statement);
72325
+ this.declarationTokens.push(name);
72326
+ }
72327
+ }
72328
+ }
72329
+ }
72330
+ }
72331
+ getStart() {
72332
+ return this.structure.getFirstToken().getStart();
72333
+ }
72334
+ getEnd() {
72335
+ return this.structure.getLastToken().getEnd();
72336
+ }
72337
+ contains(identifier) {
72338
+ return identifier.getFilename() === this.file.getFilename()
72339
+ && !identifier.getStart().isBefore(this.getStart())
72340
+ && !identifier.getStart().isAfter(this.getEnd());
72341
+ }
72342
+ tokenKey(token) {
72343
+ return ObjectAnalysis.tokenKey(this.file.getFilename(), token);
72344
+ }
72345
+ index(statement) {
72346
+ var _a;
72347
+ var _b;
72348
+ return (_b = (_a = this.info.get(statement)) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : -1;
72349
+ }
72350
+ block(statement) {
72351
+ var _a;
72352
+ return (_a = this.info.get(statement)) === null || _a === void 0 ? void 0 : _a.block;
72353
+ }
72354
+ loop(statement) {
72355
+ var _a;
72356
+ return (_a = this.info.get(statement)) === null || _a === void 0 ? void 0 : _a.loop;
72357
+ }
72358
+ /** a direct statement of its block, not the start, middle or end of a nested structure */
72359
+ isSimple(statement) {
72360
+ var _a;
72361
+ return ((_a = this.info.get(statement)) === null || _a === void 0 ? void 0 : _a.simple) === true;
72362
+ }
72363
+ /** first executes before second, on every path that reaches second within one iteration:
72364
+ * the block of first contains second, and first is before second */
72365
+ dominates(first, second) {
72366
+ const a = this.info.get(first);
72367
+ const b = this.info.get(second);
72368
+ return a !== undefined && b !== undefined && a.block !== undefined
72369
+ && a.index < b.index && b.blockPath.includes(a.block);
72370
+ }
72371
+ sameLoop(first, second) {
72372
+ return this.loop(first) === this.loop(second);
72373
+ }
72374
+ /** statements strictly between two statements of the same block,
72375
+ * undefined if any of them is not a direct statement of that block */
72376
+ straightBetween(first, second) {
72377
+ const a = this.info.get(first);
72378
+ const b = this.info.get(second);
72379
+ if (a === undefined || b === undefined || a.block === undefined || a.block !== b.block || a.index >= b.index) {
72380
+ return undefined;
72381
+ }
72382
+ const between = this.statements.slice(a.index + 1, b.index);
72383
+ for (const statement of between) {
72384
+ if (this.block(statement) !== a.block || this.isSimple(statement) === false) {
72385
+ return undefined;
72386
+ }
72387
+ }
72388
+ return between;
72389
+ }
72390
+ /** a comment line or end of line comment between the two positions */
72391
+ hasComment(start, end) {
72392
+ if (this.comments === undefined) {
72393
+ this.comments = this.file.getStatements()
72394
+ .filter(s => s.get() instanceof _statement_1.Comment
72395
+ && !s.getStart().isBefore(this.getStart()) && s.getStart().isBefore(this.getEnd()))
72396
+ .map(s => s.getStart());
72397
+ }
72398
+ return this.comments.some(c => !c.isBefore(start) && c.isBefore(end));
72399
+ }
72400
+ /** the IF structure of an IF or ELSEIF statement */
72401
+ ifStructure(statement) {
72402
+ let parent = this.parents.get(statement);
72403
+ if (statement.get() instanceof Statements.ElseIf && parent !== undefined) {
72404
+ parent = this.parents.get(parent);
72405
+ }
72406
+ return (parent === null || parent === void 0 ? void 0 : parent.get()) instanceof Structures.If ? parent : undefined;
72407
+ }
72408
+ /** the variable for an identifier referenced in this procedure,
72409
+ * undefined for identifiers without data references, e.g. types or methods */
72410
+ variable(identifier) {
72411
+ if (!(identifier instanceof _typed_identifier_1.TypedIdentifier)) {
72412
+ return undefined;
72413
+ }
72414
+ const key = ObjectAnalysis.key(identifier);
72415
+ if (this.variables.has(key)) {
72416
+ return this.variables.get(key);
72417
+ }
72418
+ const declaration = this.contains(identifier) ? this.declarations.get(key) : undefined;
72419
+ const inline = declaration !== undefined && !(declaration.get() instanceof Statements.Data);
72420
+ const occurrences = [];
72421
+ const known = new Set([position(identifier.getToken())]);
72422
+ for (const reference of this.analysis.referencesTo(identifier)) {
72423
+ if (!this.contains(reference.position)) {
72424
+ continue;
72425
+ }
72426
+ const token = reference.position.getToken();
72427
+ known.add(position(token));
72428
+ if (inline && reference.position.getStart().equals(identifier.getStart())
72429
+ && reference.referenceType === _reference_1.ReferenceType.DataWriteReference) {
72430
+ continue;
72431
+ }
72432
+ const statement = this.statementOf(token);
72433
+ if (statement === undefined) {
72434
+ this.variables.set(key, undefined);
72435
+ return undefined;
72436
+ }
72437
+ occurrences.push({ token, statement, index: this.index(statement), kind: this.classify(reference, statement) });
72438
+ }
72439
+ // several references at the same position, e.g. read and write in LOOP AT itab ASSIGNING
72440
+ occurrences.sort((a, b) => a.token.getStart().isBefore(b.token.getStart()) ? -1
72441
+ : a.token.getStart().equals(b.token.getStart()) ? 0 : 1);
72442
+ const merged = [];
72443
+ for (const occurrence of occurrences) {
72444
+ const last = merged[merged.length - 1];
72445
+ if (last !== undefined && last.token.getStart().equals(occurrence.token.getStart())) {
72446
+ if (last.kind !== occurrence.kind) {
72447
+ merged[merged.length - 1] = Object.assign(Object.assign({}, last), { kind: rank(last.kind) > rank(occurrence.kind) ? last.kind : occurrence.kind });
72448
+ }
72449
+ continue;
72450
+ }
72451
+ merged.push(occurrence);
72452
+ }
72453
+ let complete = true;
72454
+ for (const named of this.names.get(identifier.getName().toLowerCase()) || []) {
72455
+ if (!known.has(named)) {
72456
+ complete = false;
72457
+ }
72458
+ }
72459
+ const variable = new Variable(identifier, declaration, inline, merged, complete);
72460
+ this.variables.set(key, variable);
72461
+ return variable;
72462
+ }
72463
+ /** local variable, declared in the procedure by DATA or inline, and with all its references understood */
72464
+ local(identifier) {
72465
+ const variable = this.variable(identifier);
72466
+ if (variable === undefined || variable.isLocal() === false || variable.complete === false
72467
+ || variable.identifier.getMeta().includes("static" /* IdentifierMeta.Static */)) {
72468
+ return undefined;
72469
+ }
72470
+ return variable;
72471
+ }
72472
+ /** all local variables declared in the procedure */
72473
+ locals() {
72474
+ var _a;
72475
+ const ret = [];
72476
+ for (const token of this.declarationTokens) {
72477
+ const variable = this.local((_a = this.identifierAt(token)) !== null && _a !== void 0 ? _a : this.declaredIdentifier(token));
72478
+ if (variable !== undefined) {
72479
+ ret.push(variable);
72480
+ }
72481
+ }
72482
+ return ret;
72483
+ }
72484
+ /** tokens of the statement, getTokens() builds a new list on every call */
72485
+ tokensOf(statement) {
72486
+ let tokens = this.tokens.get(statement);
72487
+ if (tokens === undefined) {
72488
+ tokens = statement.getTokens();
72489
+ this.tokens.set(statement, tokens);
72490
+ }
72491
+ return tokens;
72492
+ }
72493
+ /** the resolved identifier of the data reference at the token, if any */
72494
+ identifierAt(token) {
72495
+ for (const reference of this.analysis.referencesAt(this.file.getFilename(), token)) {
72496
+ if (reference.referenceType === _reference_1.ReferenceType.DataReadReference
72497
+ || reference.referenceType === _reference_1.ReferenceType.DataWriteReference) {
72498
+ return reference.resolved;
72499
+ }
72500
+ }
72501
+ return undefined;
72502
+ }
72503
+ /** the identifier declared at the token, also when it is never referenced */
72504
+ declaredIdentifier(token) {
72505
+ var _a;
72506
+ const found = (_a = this.analysis.spaghetti.lookupPosition(token.getStart(), this.file.getFilename())) === null || _a === void 0 ? void 0 : _a.findVariable(token.getStr());
72507
+ return found !== undefined && found.getFilename() === this.file.getFilename()
72508
+ && found.getStart().equals(token.getStart()) ? found : undefined;
72509
+ }
72510
+ /** identifiers declared in the procedure, with all their references */
72511
+ ownReferences() {
72512
+ if (this.own === undefined) {
72513
+ this.own = [];
72514
+ for (const [, references] of this.analysis.allReferences()) {
72515
+ const resolved = references[0].resolved;
72516
+ if (resolved !== undefined && this.contains(resolved)) {
72517
+ this.own.push([resolved, references]);
72518
+ }
72519
+ }
72520
+ }
72521
+ return this.own;
72522
+ }
72523
+ statementOf(token) {
72524
+ // statement ends are increasing, also for chained statements which share their first tokens
72525
+ let low = 0;
72526
+ let high = this.statements.length;
72527
+ const start = token.getStart();
72528
+ while (low < high) {
72529
+ const middle = Math.floor((low + high) / 2);
72530
+ if (this.statements[middle].getEnd().isBefore(start)) {
72531
+ low = middle + 1;
72532
+ }
72533
+ else {
72534
+ high = middle;
72535
+ }
72536
+ }
72537
+ for (let i = low; i < this.statements.length && !start.isBefore(this.statements[i].getStart()); i++) {
72538
+ if (this.statements[i].includesToken(token)) {
72539
+ return this.statements[i];
72540
+ }
72541
+ }
72542
+ return undefined;
72543
+ }
72544
+ /** the statement cannot run other ABAP code: no method, function or form call, no constructor, no event */
72545
+ isCallFree(statement) {
72546
+ var _a;
72547
+ const type = statement.get();
72548
+ if (!CALL_FREE.some(t => type instanceof t)) {
72549
+ return false;
72550
+ }
72551
+ for (const call of statement.findAllExpressionsRecursive(Expressions.MethodCall)) {
72552
+ const name = (_a = call.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
72553
+ if (name === undefined) {
72554
+ return false;
72555
+ }
72556
+ const references = this.analysis.referencesAt(this.file.getFilename(), name);
72557
+ if (references.length === 0 || references.some(r => r.referenceType !== _reference_1.ReferenceType.BuiltinMethodReference)) {
72558
+ return false;
72559
+ }
72560
+ }
72561
+ return statement.findFirstExpression(Expressions.NewObject) === undefined;
72562
+ }
72563
+ /** every data write in the statement goes to a local variable, a pass-by-value parameter or the
72564
+ * RETURNING parameter, ie. memory that no other data object, field symbol or reference can share */
72565
+ writesOnlyPrivate(statement) {
72566
+ var _a;
72567
+ const tokens = this.tokensOf(statement);
72568
+ for (let i = 0; i < tokens.length; i++) {
72569
+ for (const reference of this.analysis.referencesAt(this.file.getFilename(), tokens[i])) {
72570
+ if (reference.referenceType !== _reference_1.ReferenceType.DataWriteReference) {
72571
+ continue;
72572
+ }
72573
+ if (((_a = tokens[i + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) === "->") {
72574
+ return false;
72575
+ }
72576
+ const variable = this.variable(reference.resolved);
72577
+ if (variable === undefined || variable.escapes()) {
72578
+ return false;
72579
+ }
72580
+ const meta = variable.identifier.getMeta();
72581
+ if (!variable.isLocal() && !meta.includes("returning" /* IdentifierMeta.MethodReturning */)
72582
+ && !meta.includes("pass_by_value" /* IdentifierMeta.PassByValue */)) {
72583
+ return false;
72584
+ }
72585
+ }
72586
+ }
72587
+ // writes without any reference, e.g. to field symbols assigned dynamically, are not expected after the
72588
+ // syntax check, but field symbol targets are excluded explicitly
72589
+ return statement.findFirstExpression(Expressions.TargetFieldSymbol) === undefined
72590
+ && statement.findFirstExpression(Expressions.Dereference) === undefined;
72591
+ }
72592
+ classify(reference, statement) {
72593
+ var _a;
72594
+ if (reference.referenceType !== _reference_1.ReferenceType.DataReadReference
72595
+ && reference.referenceType !== _reference_1.ReferenceType.DataWriteReference) {
72596
+ return OccurrenceKind.Escape;
72597
+ }
72598
+ const token = reference.position.getToken();
72599
+ const tokens = this.tokensOf(statement);
72600
+ const index = tokens.findIndex(t => t.getStart().equals(token.getStart()));
72601
+ if (index < 0) {
72602
+ return OccurrenceKind.Escape;
72603
+ }
72604
+ const path = expressionPath(statement, token);
72605
+ if (path.some(e => e.get() instanceof Expressions.Dynamic)) {
72606
+ return OccurrenceKind.Escape;
72607
+ }
72608
+ if (((_a = tokens[index + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) === "->") {
72609
+ // the reference itself is not changed, nor exposed, only the object or data it points to
72610
+ return OccurrenceKind.Read;
72611
+ }
72612
+ if (reference.referenceType === _reference_1.ReferenceType.DataWriteReference) {
72613
+ return OccurrenceKind.Write;
72614
+ }
72615
+ const type = statement.get();
72616
+ if (!READING.some(t => type instanceof t)
72617
+ || statement.findFirstExpression(Expressions.FSTarget) !== undefined
72618
+ || statement.findTokenSequencePosition("REFERENCE", "INTO") !== undefined
72619
+ || path.some(e => e.get() instanceof Expressions.Source && isRefConstructor(e))) {
72620
+ return OccurrenceKind.Escape;
72621
+ }
72622
+ return OccurrenceKind.Read;
72623
+ }
72624
+ isSupported() {
72625
+ for (const statement of this.statements) {
72626
+ const type = statement.get();
72627
+ if (type instanceof Statements.Include || type instanceof _statement_1.NativeSQL
72628
+ || type instanceof Statements.TestSeam || type instanceof Statements.TestInjection
72629
+ || type instanceof Statements.Enhancement || type instanceof Statements.EnhancementSection
72630
+ || type instanceof Statements.ExecSQL
72631
+ || statement.findFirstExpression(Expressions.Dynamic) !== undefined) {
72632
+ return false;
72633
+ }
72634
+ }
72635
+ return true;
72636
+ }
72637
+ walk(node, blockPath, loop, simple) {
72638
+ const type = node.get();
72639
+ if (type instanceof Structures.Body) {
72640
+ blockPath = [...blockPath, node];
72641
+ }
72642
+ else if (LOOPS.some(l => type instanceof l) || (type instanceof Structures.Try && retries(node))) {
72643
+ loop = node;
72644
+ }
72645
+ for (const child of node.getChildren()) {
72646
+ this.parents.set(child, node);
72647
+ if (child instanceof nodes_1.StructureNode) {
72648
+ this.walk(child, blockPath, loop, child.get() instanceof Structures.Normal);
72649
+ }
72650
+ else if (child instanceof nodes_1.StatementNode) {
72651
+ this.info.set(child, {
72652
+ index: this.statements.length,
72653
+ block: blockPath[blockPath.length - 1],
72654
+ blockPath,
72655
+ loop,
72656
+ simple: simple && type instanceof Structures.Normal,
72657
+ });
72658
+ this.statements.push(child);
72659
+ }
72660
+ }
72661
+ }
72662
+ }
72663
+ exports.Procedure = Procedure;
72664
+ function position(token) {
72665
+ return token.getRow() * 100000 + token.getCol();
72666
+ }
72667
+ function rank(kind) {
72668
+ return kind === OccurrenceKind.Escape ? 2 : kind === OccurrenceKind.Write ? 1 : 0;
72669
+ }
72670
+ /** RETRY and RESUME jump back into the TRY block, as does a CATCH BEFORE UNWIND handler */
72671
+ function retries(node) {
72672
+ return node.findAllStatements(Statements.Retry).length > 0
72673
+ || node.findAllStatements(Statements.Resume).length > 0
72674
+ || node.findAllStatements(Statements.Catch).some(c => c.findDirectTokenByText("UNWIND") !== undefined);
72675
+ }
72676
+ function isRefConstructor(source) {
72677
+ const first = source.getChildren()[0];
72678
+ return first instanceof nodes_1.TokenNode && first.getFirstToken().getStr().toUpperCase() === "REF"
72679
+ && source.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined;
72680
+ }
72681
+ function findStructures(node, types) {
72682
+ if (types.some(t => node.get() instanceof t)) {
72683
+ return [node];
72684
+ }
72685
+ const ret = [];
72686
+ for (const child of node.getChildren()) {
72687
+ if (child instanceof nodes_1.StructureNode) {
72688
+ ret.push(...findStructures(child, types));
72689
+ }
72690
+ }
72691
+ return ret;
72692
+ }
72693
+ /** expression nodes from the statement down to the token */
72694
+ function expressionPath(statement, token) {
72695
+ const ret = [];
72696
+ let children = statement.getChildren();
72697
+ for (;;) {
72698
+ let next = undefined;
72699
+ for (const child of children) {
72700
+ if (child instanceof nodes_1.ExpressionNode
72701
+ && !token.getStart().isBefore(child.getFirstToken().getStart())
72702
+ && !child.getLastToken().getStart().isBefore(token.getStart())) {
72703
+ next = child;
72704
+ break;
72705
+ }
72706
+ }
72707
+ if (next === undefined) {
72708
+ return ret;
72709
+ }
72710
+ ret.push(next);
72711
+ children = next.getChildren();
72712
+ }
72713
+ }
72714
+ /** target = source. or target ?= source. without chaining, pragmas or MOVE */
72715
+ function plainMove(statement) {
72716
+ if (!(statement.get() instanceof Statements.Move) || statement.getColon() !== undefined
72717
+ || statement.getPragmas().length > 0) {
72718
+ return undefined;
72719
+ }
72720
+ const target = statement.findDirectExpression(Expressions.Target);
72721
+ const source = statement.findDirectExpression(Expressions.Source);
72722
+ const tokens = statement.getTokens();
72723
+ if (target === undefined || source === undefined
72724
+ || tokens.length !== target.countTokens() + source.countTokens() + 2) {
72725
+ return undefined;
72726
+ }
72727
+ const operator = tokens[target.countTokens()].getStr();
72728
+ if (operator !== "=" && operator !== "?=") {
72729
+ return undefined;
72730
+ }
72731
+ return { target, source, operator };
72732
+ }
72733
+ /** the source is a single field, ie. one token */
72734
+ function singleField(source) {
72735
+ var _a;
72736
+ if (source.getChildren().length !== 1 || source.countTokens() !== 1) {
72737
+ return undefined;
72738
+ }
72739
+ const field = (_a = source.findDirectExpression(Expressions.FieldChain)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.SourceField);
72740
+ return field === null || field === void 0 ? void 0 : field.getFirstToken();
72741
+ }
72742
+ /** the target is a single field, ie. one token, not an inline declaration */
72743
+ function singleTarget(target) {
72744
+ if (target.countTokens() !== 1 || target.findDirectExpression(Expressions.TargetField) === undefined) {
72745
+ return undefined;
72746
+ }
72747
+ return target.getFirstToken();
72748
+ }
72749
+ /** CLEAR name. without chaining or WITH */
72750
+ function plainClear(statement) {
72751
+ if (!(statement.get() instanceof Statements.Clear) || statement.getPragmas().length > 0) {
72752
+ return undefined;
72753
+ }
72754
+ const targets = statement.findDirectExpressions(Expressions.Target);
72755
+ const tokens = statement.getTokens();
72756
+ if (targets.length !== 1 || tokens.length !== 3 || tokens[0].getStr().toUpperCase() !== "CLEAR") {
72757
+ return undefined;
72758
+ }
72759
+ return singleTarget(targets[0]);
72760
+ }
72761
+ /** DATA name TYPE/LIKE ... without VALUE, without chaining */
72762
+ function plainData(statement) {
72763
+ var _a;
72764
+ return statement.get() instanceof Statements.Data
72765
+ && ((_a = statement.findDirectExpression(Expressions.DataDefinition)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Value)) === undefined;
72766
+ }
72767
+ /** constants of the class or program, builtin constants like abap_true, and me: never change */
72768
+ function isImmutable(identifier) {
72769
+ if (!(identifier instanceof _typed_identifier_1.TypedIdentifier)) {
72770
+ return false;
72771
+ }
72772
+ const meta = identifier.getMeta();
72773
+ if (identifier.getName().toLowerCase() === "me" && identifier.getType() instanceof basic_1.ObjectReferenceType) {
72774
+ return true;
72775
+ }
72776
+ return meta.includes("read_only" /* IdentifierMeta.ReadOnly */)
72777
+ && (meta.includes("static" /* IdentifierMeta.Static */) || (meta.includes("built-in" /* IdentifierMeta.BuiltIn */) && identifier.getValue() !== undefined));
72778
+ }
72779
+ function isReferenceType(type) {
72780
+ return type instanceof basic_1.ObjectReferenceType || type instanceof basic_1.DataReference;
72781
+ }
72782
+ /** same runtime type, so assignments between the two never convert */
72783
+ function identicalTypes(first, second) {
72784
+ var _a, _b;
72785
+ if (first instanceof basic_1.UnknownType || second instanceof basic_1.UnknownType
72786
+ || first instanceof basic_1.VoidType || second instanceof basic_1.VoidType
72787
+ || first.isGeneric() || second.isGeneric()
72788
+ || first.constructor !== second.constructor) {
72789
+ return false;
72790
+ }
72791
+ if (first instanceof basic_1.StructureType || first instanceof basic_1.TableType) {
72792
+ const firstName = (_a = first.getQualifiedName()) === null || _a === void 0 ? void 0 : _a.toUpperCase();
72793
+ return firstName !== undefined && firstName === ((_b = second.getQualifiedName()) === null || _b === void 0 ? void 0 : _b.toUpperCase());
72794
+ }
72795
+ if (isReferenceType(first)) {
72796
+ return first.toABAP().toUpperCase() === second.toABAP().toUpperCase();
72797
+ }
72798
+ return first.toABAP() === second.toABAP();
72799
+ }
72800
+ ////////////////////////////////////////
72801
+ // conditions
72802
+ var PredicateKind;
72803
+ (function (PredicateKind) {
72804
+ PredicateKind["Equal"] = "equal";
72805
+ PredicateKind["Initial"] = "initial";
72806
+ PredicateKind["Bound"] = "bound";
72807
+ })(PredicateKind || (exports.PredicateKind = PredicateKind = {}));
72808
+ /** the condition of IF or ELSEIF is one comparison: a = b, a EQ b, a <> b, a NE b,
72809
+ * a IS [NOT] INITIAL, a IS [NOT] BOUND, optionally prefixed with NOT */
72810
+ function simplePredicate(statement) {
72811
+ if (!(statement.get() instanceof Statements.If || statement.get() instanceof Statements.ElseIf)
72812
+ || statement.getColon() !== undefined) {
72813
+ return undefined;
72814
+ }
72815
+ const cond = statement.findDirectExpression(Expressions.Cond);
72816
+ if (cond === undefined || cond.getChildren().length !== 1) {
72817
+ return undefined;
72818
+ }
72819
+ const compare = cond.findDirectExpression(Expressions.Compare);
72820
+ if (compare === undefined) {
72821
+ return undefined;
72822
+ }
72823
+ const children = compare.getChildren();
72824
+ let negated = false;
72825
+ let i = 0;
72826
+ if (children[0] instanceof nodes_1.TokenNode && children[0].getFirstToken().getStr().toUpperCase() === "NOT") {
72827
+ negated = true;
72828
+ i = 1;
72829
+ }
72830
+ const left = children[i];
72831
+ if (!(left instanceof nodes_1.ExpressionNode) || !(left.get() instanceof Expressions.Source)) {
72832
+ return undefined;
72833
+ }
72834
+ const rest = children.slice(i + 1);
72835
+ const words = rest.map(c => c instanceof nodes_1.TokenNode ? c.getFirstToken().getStr().toUpperCase() : "");
72836
+ if (rest.length === 2 && rest[0].get() instanceof Expressions.CompareOperator
72837
+ && rest[1] instanceof nodes_1.ExpressionNode && rest[1].get() instanceof Expressions.Source) {
72838
+ const operator = rest[0].getFirstToken().getStr().toUpperCase();
72839
+ if (rest[0].countTokens() !== 1 || !["=", "EQ", "<>", "NE"].includes(operator)) {
72840
+ return undefined;
72841
+ }
72842
+ return { kind: PredicateKind.Equal, left, right: rest[1], negated: negated !== (operator === "<>" || operator === "NE") };
72843
+ }
72844
+ else if (words.join(" ") === "IS INITIAL" || words.join(" ") === "IS NOT INITIAL") {
72845
+ return { kind: PredicateKind.Initial, left, negated: negated !== (words.length === 3) };
72846
+ }
72847
+ else if (words.join(" ") === "IS BOUND" || words.join(" ") === "IS NOT BOUND") {
72848
+ return { kind: PredicateKind.Bound, left, negated: negated !== (words.length === 3) };
72849
+ }
72850
+ return undefined;
72851
+ }
72852
+ /** value of a character literal 'abc', or of a character constant like abap_true, undefined otherwise */
72853
+ function characterConstant(procedure, source) {
72854
+ var _a;
72855
+ if (source.getChildren().length !== 1) {
72856
+ return undefined;
72857
+ }
72858
+ const literal = (_a = source.findDirectExpression(Expressions.Constant)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.ConstantString);
72859
+ if (literal !== undefined) {
72860
+ return literal.countTokens() === 1 ? textLiteral(literal.getFirstToken().getStr()) : undefined;
72861
+ }
72862
+ const field = singleField(source);
72863
+ const identifier = field === undefined ? undefined : procedure.identifierAt(field);
72864
+ if (identifier instanceof _typed_identifier_1.TypedIdentifier && isImmutable(identifier)
72865
+ && identifier.getType() instanceof basic_1.CharacterType) {
72866
+ const value = identifier.getValue();
72867
+ return typeof value === "string" ? textLiteral(value) : undefined;
72868
+ }
72869
+ return undefined;
72870
+ }
72871
+ function textLiteral(text) {
72872
+ if (text.length < 2 || !text.startsWith("'") || !text.endsWith("'")) {
72873
+ return undefined;
72874
+ }
72875
+ return text.substring(1, text.length - 1).replace(/''/g, "'");
72876
+ }
72877
+ /** character values compare after padding the shorter one with blanks */
72878
+ function sameCharacters(first, second) {
72879
+ return first.replace(/ +$/, "") === second.replace(/ +$/, "");
72880
+ }
72881
+ /** IF, ELSEIF, WHILE, CHECK, CASE or WHEN: a constant compared there is left for constant_condition,
72882
+ * instead of replacing a variable by a constant and comparing two constants */
72883
+ function isCondition(statement) {
72884
+ const type = statement.get();
72885
+ return type instanceof Statements.If || type instanceof Statements.ElseIf || type instanceof Statements.While
72886
+ || type instanceof Statements.Check || type instanceof Statements.Case || type instanceof Statements.When;
72887
+ }
72888
+ ////////////////////////////////////////
72889
+ // data sources
72890
+ var SourceKind;
72891
+ (function (SourceKind) {
72892
+ /** constants and me, never change */
72893
+ SourceKind["Immutable"] = "immutable";
72894
+ /** a local variable, or a component of it, changes only by references to the variable */
72895
+ SourceKind["Local"] = "local";
72896
+ /** attributes, parameters, globals, anything reached via a reference: may change by other code */
72897
+ SourceKind["Volatile"] = "volatile";
72898
+ })(SourceKind || (exports.SourceKind = SourceKind = {}));
72899
+ /** a plain data object: field, constant, attribute or component chain without calls, offsets, table
72900
+ * expressions, field symbols or dereferencing with ->* */
72901
+ function dataSource(procedure, source) {
72902
+ var _a;
72903
+ if (source.getChildren().length !== 1) {
72904
+ return undefined;
72905
+ }
72906
+ const chain = source.findDirectExpression(Expressions.FieldChain);
72907
+ if (chain === undefined) {
72908
+ return undefined;
72909
+ }
72910
+ const children = chain.getChildren();
72911
+ let first;
72912
+ let next;
72913
+ if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.SourceField) {
72914
+ first = procedure.identifierAt(children[0].getFirstToken());
72915
+ next = 1;
72916
+ }
72917
+ else if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.ClassName
72918
+ && ((_a = children[1]) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr()) === "=>" && children[2] instanceof nodes_1.ExpressionNode
72919
+ && children[2].get() instanceof Expressions.AttributeName) {
72920
+ first = procedure.identifierAt(children[2].getFirstToken());
72921
+ next = 3;
72922
+ }
72923
+ else {
72924
+ return undefined;
72925
+ }
72926
+ if (!(first instanceof _typed_identifier_1.TypedIdentifier)
72927
+ || (first.getMeta().includes("built-in" /* IdentifierMeta.BuiltIn */) && !isImmutable(first))) {
72928
+ // system fields like sy-subrc and sy-tabix are changed by many statements without a write reference
72929
+ return undefined;
72930
+ }
72931
+ let type = first.getType();
72932
+ let deref = false;
72933
+ for (let i = next; i < children.length; i += 2) {
72934
+ const separator = children[i];
72935
+ const name = children[i + 1];
72936
+ if (!(separator instanceof nodes_1.TokenNode) || !(name instanceof nodes_1.ExpressionNode) || type === undefined) {
72937
+ return undefined;
72938
+ }
72939
+ if (type instanceof basic_1.TableType && type.isWithHeader()) {
72940
+ return undefined;
72941
+ }
72942
+ else if (separator.getFirstToken().getStr() === "->" && name.get() instanceof Expressions.AttributeName) {
72943
+ const attribute = procedure.identifierAt(name.getFirstToken());
72944
+ type = attribute instanceof _typed_identifier_1.TypedIdentifier ? attribute.getType() : undefined;
72945
+ deref = true;
72946
+ }
72947
+ else if (separator.getFirstToken().getStr() === "-" && name.get() instanceof Expressions.ComponentName
72948
+ && type instanceof basic_1.StructureType) {
72949
+ type = type.getComponentByName(name.getFirstToken().getStr());
72950
+ }
72951
+ else {
72952
+ return undefined;
72953
+ }
72954
+ }
72955
+ if (type === undefined || type.isGeneric() || (type instanceof basic_1.TableType && type.isWithHeader())) {
72956
+ return undefined;
72957
+ }
72958
+ const local = next === 1 ? procedure.local(first) : undefined;
72959
+ let kind = SourceKind.Volatile;
72960
+ if (deref === false && isImmutable(first)) {
72961
+ kind = SourceKind.Immutable;
72962
+ }
72963
+ else if (deref === false && local !== undefined) {
72964
+ kind = SourceKind.Local;
72965
+ }
72966
+ return { text: nodeText(procedure.file, source), kind, base: local, type };
72967
+ }
72968
+ /** type of a plain target: variable, field symbol, attribute or component chain, not an inline declaration,
72969
+ * without offsets, table expressions or ->* */
72970
+ function targetType(procedure, target) {
72971
+ var _a;
72972
+ const children = target.getChildren();
72973
+ let identifier;
72974
+ let next;
72975
+ const first = children[0];
72976
+ if (first instanceof nodes_1.ExpressionNode
72977
+ && (first.get() instanceof Expressions.TargetField || first.get() instanceof Expressions.TargetFieldSymbol)) {
72978
+ identifier = procedure.identifierAt(first.getFirstToken());
72979
+ next = 1;
72980
+ }
72981
+ else if (first instanceof nodes_1.ExpressionNode && first.get() instanceof Expressions.ClassName
72982
+ && ((_a = children[1]) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr()) === "=>" && children[2] instanceof nodes_1.ExpressionNode
72983
+ && children[2].get() instanceof Expressions.AttributeName) {
72984
+ identifier = procedure.identifierAt(children[2].getFirstToken());
72985
+ next = 3;
72986
+ }
72987
+ else {
72988
+ return undefined;
72989
+ }
72990
+ let type = identifier instanceof _typed_identifier_1.TypedIdentifier ? identifier.getType() : undefined;
72991
+ for (let i = next; i < children.length; i += 2) {
72992
+ const separator = children[i];
72993
+ const name = children[i + 1];
72994
+ if (!(separator instanceof nodes_1.TokenNode) || !(name instanceof nodes_1.ExpressionNode) || type === undefined) {
72995
+ return undefined;
72996
+ }
72997
+ if (separator.getFirstToken().getStr() === "->" && name.get() instanceof Expressions.AttributeName) {
72998
+ const attribute = procedure.identifierAt(name.getFirstToken());
72999
+ type = attribute instanceof _typed_identifier_1.TypedIdentifier ? attribute.getType() : undefined;
73000
+ }
73001
+ else if (separator.getFirstToken().getStr() === "-" && name.get() instanceof Expressions.ComponentName
73002
+ && type instanceof basic_1.StructureType) {
73003
+ type = type.getComponentByName(name.getFirstToken().getStr());
73004
+ }
73005
+ else {
73006
+ return undefined;
73007
+ }
73008
+ }
73009
+ if (type === undefined || (type instanceof basic_1.TableType && type.isWithHeader())) {
73010
+ return undefined;
73011
+ }
73012
+ return type;
73013
+ }
73014
+ /**
73015
+ * The data source has the same value at the end of statement "to" as at the end of statement "from".
73016
+ * When "read" is given, it is the token in statement "to" that reads the value; writes of statement "to"
73017
+ * after its sources are evaluated, ie. the target of a MOVE or the call after evaluating its receiver, do not count.
73018
+ */
73019
+ function unchangedBetween(procedure, source, from, to, read) {
73020
+ if (source.kind === SourceKind.Immutable) {
73021
+ return true;
73022
+ }
73023
+ const start = procedure.index(from);
73024
+ const end = procedure.index(to);
73025
+ if (start < 0 || end < start) {
73026
+ return false;
73027
+ }
73028
+ if (source.base !== undefined && (source.base.escapes()
73029
+ || source.base.writes().some(w => w.index > start && w.index <= end))) {
73030
+ return false;
73031
+ }
73032
+ if (source.kind === SourceKind.Local) {
73033
+ return source.base !== undefined;
73034
+ }
73035
+ for (let index = start + 1; index <= end; index++) {
73036
+ const statement = procedure.statements[index];
73037
+ if (index === end && read !== undefined) {
73038
+ if (isReceiver(statement, read)
73039
+ || (statement.get() instanceof Statements.Move && procedure.isCallFree(statement))) {
73040
+ continue;
73041
+ }
73042
+ }
73043
+ if (!procedure.isCallFree(statement) || !procedure.writesOnlyPrivate(statement)) {
73044
+ return false;
73045
+ }
73046
+ }
73047
+ return true;
73048
+ }
73049
+ /** the token is the receiver of the method call chain of the statement: a->m( ). or x = a->m( ).
73050
+ * The receiver is evaluated before the arguments and the call */
73051
+ function isReceiver(statement, token) {
73052
+ var _a, _b;
73053
+ let chain;
73054
+ if (statement.get() instanceof Statements.Call) {
73055
+ chain = statement.findDirectExpression(Expressions.MethodCallChain);
73056
+ }
73057
+ else if (((_a = plainMove(statement)) === null || _a === void 0 ? void 0 : _a.source.getChildren().length) === 1) {
73058
+ chain = plainMove(statement).source.findDirectExpression(Expressions.MethodCallChain);
73059
+ }
73060
+ const receiver = chain === null || chain === void 0 ? void 0 : chain.getChildren()[0];
73061
+ return receiver instanceof nodes_1.ExpressionNode && receiver.get() instanceof Expressions.FieldChain
73062
+ && receiver.countTokens() === 1 && receiver.getFirstToken().getStart().equals(token.getStart())
73063
+ && ((_b = chain === null || chain === void 0 ? void 0 : chain.getChildren()[1]) === null || _b === void 0 ? void 0 : _b.getFirstToken().getStr()) === "->";
73064
+ }
73065
+ ////////////////////////////////////////
73066
+ // edits
73067
+ const rowCache = new WeakMap();
73068
+ /** getRawRows() splits the source on every call; a file is never changed, edits create a new one */
73069
+ function rowsOf(file) {
73070
+ let rows = rowCache.get(file);
73071
+ if (rows === undefined) {
73072
+ rows = file.getRawRows();
73073
+ rowCache.set(file, rows);
73074
+ }
73075
+ return rows;
73076
+ }
73077
+ /** edits of one fix, sorted so that applying them one after the other keeps the positions valid */
73078
+ function mergeEdits(file, edits) {
73079
+ const list = [];
73080
+ for (const edit of edits) {
73081
+ list.push(...edit[file.getFilename()] || []);
73082
+ }
73083
+ list.sort((a, b) => {
73084
+ if (a.range.start.equals(b.range.start)) {
73085
+ return 0;
73086
+ }
73087
+ return a.range.start.isAfter(b.range.start) ? -1 : 1;
73088
+ });
73089
+ return { [file.getFilename()]: list };
73090
+ }
73091
+ /** deletes the statements from first to last, the full lines if nothing else is on them */
73092
+ function deleteRegion(file, first, last) {
73093
+ if (first === last && first.getColon() !== undefined) {
73094
+ return edit_helper_1.EditHelper.deleteStatement(file, first);
73095
+ }
73096
+ const rows = rowsOf(file);
73097
+ const start = first.getStart();
73098
+ const end = last.getEnd();
73099
+ const before = rows[start.getRow() - 1].substring(0, start.getCol() - 1);
73100
+ const after = rows[end.getRow() - 1].substring(end.getCol() - 1);
73101
+ if (before.trim() === "" && after.trim() === "" && end.getRow() < rows.length) {
73102
+ return edit_helper_1.EditHelper.deleteRange(file, new position_1.Position(start.getRow(), 1), new position_1.Position(end.getRow() + 1, 1));
73103
+ }
73104
+ return edit_helper_1.EditHelper.deleteRange(file, start, end);
73105
+ }
73106
+ function deleteStatement(file, statement) {
73107
+ return deleteRegion(file, statement, statement);
73108
+ }
73109
+ /** the source code between two positions, as written */
73110
+ function rawText(file, start, end) {
73111
+ const rows = rowsOf(file);
73112
+ if (start.getRow() === end.getRow()) {
73113
+ return rows[start.getRow() - 1].substring(start.getCol() - 1, end.getCol() - 1);
73114
+ }
73115
+ const ret = [rows[start.getRow() - 1].substring(start.getCol() - 1)];
73116
+ for (let row = start.getRow() + 1; row < end.getRow(); row++) {
73117
+ ret.push(rows[row - 1]);
73118
+ }
73119
+ ret.push(rows[end.getRow() - 1].substring(0, end.getCol() - 1));
73120
+ return ret.join("\n");
73121
+ }
73122
+ function nodeText(file, node) {
73123
+ return rawText(file, node.getFirstToken().getStart(), node.getLastToken().getEnd());
73124
+ }
73125
+ /** the IF, ELSEIF and ELSE branches of an IF structure */
73126
+ function ifBranches(structure) {
73127
+ const branches = [];
73128
+ for (const child of structure.getChildren()) {
73129
+ if (child instanceof nodes_1.StatementNode) {
73130
+ if (child.get() instanceof Statements.If) {
73131
+ branches.push({ statement: child, body: undefined });
73132
+ }
73133
+ }
73134
+ else if (child.get() instanceof Structures.Body) {
73135
+ if (branches.length !== 1) {
73136
+ return undefined;
73137
+ }
73138
+ branches[0].body = child;
73139
+ }
73140
+ else if (child.get() instanceof Structures.ElseIf || child.get() instanceof Structures.Else) {
73141
+ const statement = child.getFirstStatement();
73142
+ if (statement === undefined) {
73143
+ return undefined;
73144
+ }
73145
+ branches.push({ statement, body: child.findDirectStructure(Structures.Body) });
73146
+ }
73147
+ }
73148
+ return branches.length > 0 ? branches : undefined;
73149
+ }
73150
+ /** a region of statements can be deleted if nothing declared in it is used outside of it */
73151
+ function selfContained(procedure, first, last) {
73152
+ const filename = procedure.file.getFilename();
73153
+ const start = first.getStart();
73154
+ const end = last.getEnd();
73155
+ const inside = (identifier) => identifier.getFilename() === filename
73156
+ && !identifier.getStart().isBefore(start) && !identifier.getStart().isAfter(end);
73157
+ for (const [resolved, references] of procedure.ownReferences()) {
73158
+ if (inside(resolved) && references.some(r => !inside(r.position))) {
73159
+ return false;
73160
+ }
73161
+ }
73162
+ return true;
73163
+ }
73164
+ /**
73165
+ * Removes an IF branch whose condition is known.
73166
+ * decided: the IF or ELSEIF statement whose condition always has the given value.
73167
+ * Returns undefined if a removed branch declares something used outside of it.
73168
+ */
73169
+ function foldIf(procedure, structure, decided, value) {
73170
+ var _a;
73171
+ const file = procedure.file;
73172
+ const branches = ifBranches(structure);
73173
+ const endIf = structure.findDirectStatement(Statements.EndIf);
73174
+ const k = (_a = branches === null || branches === void 0 ? void 0 : branches.findIndex(b => b.statement === decided)) !== null && _a !== void 0 ? _a : -1;
73175
+ if (branches === undefined || endIf === undefined || k < 0
73176
+ || branches[k].statement.get() instanceof Statements.Else
73177
+ || structure.getChildren().some(c => c instanceof nodes_1.StatementNode && c.getColon() !== undefined)
73178
+ || branches.some(b => b.statement.getColon() !== undefined)) {
73179
+ return undefined;
73180
+ }
73181
+ const lastOf = (index) => {
73182
+ var _a;
73183
+ const statements = ((_a = branches[index].body) === null || _a === void 0 ? void 0 : _a.findAllStatementNodes()) || [];
73184
+ return statements.length > 0 ? statements[statements.length - 1] : branches[index].statement;
73185
+ };
73186
+ const dead = (from, to) => {
73187
+ // branches from..to are removed, including their statements
73188
+ return selfContained(procedure, branches[from].statement, lastOf(to));
73189
+ };
73190
+ const last = branches.length - 1;
73191
+ const edits = [];
73192
+ if (value === true) {
73193
+ if (k < last && !dead(k + 1, last)) {
73194
+ return undefined;
73195
+ }
73196
+ if (k === 0) {
73197
+ edits.push(deleteStatement(file, branches[0].statement));
73198
+ edits.push(k < last ? deleteRegion(file, branches[k + 1].statement, endIf) : deleteStatement(file, endIf));
73199
+ }
73200
+ else {
73201
+ edits.push(edit_helper_1.EditHelper.replaceRange(file, decided.getStart(), decided.getEnd(), "ELSE."));
73202
+ if (k < last) {
73203
+ edits.push(deleteRegion(file, branches[k + 1].statement, lastOf(last)));
73204
+ }
73205
+ }
73206
+ }
73207
+ else {
73208
+ if (!dead(k, k)) {
73209
+ return undefined;
73210
+ }
73211
+ if (k === 0) {
73212
+ if (last === 0) {
73213
+ edits.push(deleteRegion(file, branches[0].statement, endIf));
73214
+ }
73215
+ else {
73216
+ edits.push(deleteRegion(file, branches[0].statement, lastOf(0)));
73217
+ const next = branches[1].statement;
73218
+ if (next.get() instanceof Statements.ElseIf) {
73219
+ edits.push(edit_helper_1.EditHelper.replaceToken(file, next.getFirstToken(), "IF"));
73220
+ }
73221
+ else {
73222
+ edits.push(deleteStatement(file, next));
73223
+ edits.push(deleteStatement(file, endIf));
73224
+ }
73225
+ }
73226
+ }
73227
+ else {
73228
+ edits.push(deleteRegion(file, branches[k].statement, lastOf(k)));
73229
+ }
73230
+ }
73231
+ return mergeEdits(file, edits);
73232
+ }
73233
+ /**
73234
+ * Issues for folds of IF structures. The edits of a fold inside a removed branch of another fold can not be
73235
+ * applied in the same round, and abaplint --fix only checks if the rows of a new fix cover the first or last row
73236
+ * of an accepted one. So only the outermost fold, and the first fold of an IF, keeps its quick fix; the others
73237
+ * are reported without, and get their fix in the next round.
73238
+ */
73239
+ function foldIssues(file, candidates, key, severity) {
73240
+ const contains = (outer, inner) => !inner.getFirstToken().getStart().isBefore(outer.getFirstToken().getStart())
73241
+ && !outer.getLastToken().getEnd().isBefore(inner.getLastToken().getEnd());
73242
+ return candidates.map((candidate, index) => {
73243
+ const nested = candidates.some((other, otherIndex) => other.structure === candidate.structure
73244
+ ? otherIndex < index
73245
+ : contains(other.structure, candidate.structure));
73246
+ return issue_1.Issue.atStatement(file, candidate.statement, candidate.message, key, severity, nested ? undefined : candidate.fix);
73247
+ });
73248
+ }
73249
+ //# sourceMappingURL=_procedure_analysis.js.map
73250
+
73251
+ /***/ },
73252
+
72024
73253
  /***/ "../core/build/src/rules/abapdoc.js"
72025
73254
  /*!******************************************!*\
72026
73255
  !*** ../core/build/src/rules/abapdoc.js ***!
@@ -72630,129 +73859,253 @@ var __importStar = (this && this.__importStar) || (function () {
72630
73859
  };
72631
73860
  })();
72632
73861
  Object.defineProperty(exports, "__esModule", ({ value: true }));
72633
- exports.AddTestAttributes = exports.AddTestAttributesConf = void 0;
73862
+ exports.AddTestAttributes = exports.AddTestAttributesConf = void 0;
73863
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
73864
+ const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
73865
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
73866
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
73867
+ const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
73868
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
73869
+ class AddTestAttributesConf extends _basic_rule_config_1.BasicRuleConfig {
73870
+ }
73871
+ exports.AddTestAttributesConf = AddTestAttributesConf;
73872
+ class AddTestAttributes extends _abap_rule_1.ABAPRule {
73873
+ constructor() {
73874
+ super(...arguments);
73875
+ this.conf = new AddTestAttributesConf();
73876
+ }
73877
+ getMetadata() {
73878
+ return {
73879
+ key: "add_test_attributes",
73880
+ title: "Add test attributes for tests classes with test methods",
73881
+ shortDescription: `Add test attributes DURATION and RISK LEVEL for tests classes with test methods`,
73882
+ tags: [_irule_1.RuleTag.SingleFile],
73883
+ badExample: `CLASS ltcl_test1 DEFINITION FINAL FOR TESTING.
73884
+ PUBLIC SECTION.
73885
+ PROTECTED SECTION.
73886
+ PRIVATE SECTION.
73887
+ METHODS test FOR TESTING RAISING cx_static_check.
73888
+ ENDCLASS.
73889
+
73890
+ CLASS ltcl_test1 IMPLEMENTATION.
73891
+ METHOD test.
73892
+ ENDMETHOD.
73893
+ ENDCLASS.`,
73894
+ goodExample: `CLASS ltcl_test2 DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
73895
+ PUBLIC SECTION.
73896
+ PROTECTED SECTION.
73897
+ PRIVATE SECTION.
73898
+ METHODS test FOR TESTING RAISING cx_static_check.
73899
+ ENDCLASS.
73900
+
73901
+ CLASS ltcl_test2 IMPLEMENTATION.
73902
+ METHOD test.
73903
+ ENDMETHOD.
73904
+ ENDCLASS.`,
73905
+ };
73906
+ }
73907
+ getConfig() {
73908
+ return this.conf;
73909
+ }
73910
+ setConfig(conf) {
73911
+ this.conf = conf;
73912
+ }
73913
+ runParsed(file) {
73914
+ const issues = [];
73915
+ const stru = file.getStructure();
73916
+ if (stru === undefined) {
73917
+ return [];
73918
+ }
73919
+ for (const classStructure of stru.findAllStructures(Structures.ClassDefinition)) {
73920
+ const cdef = classStructure.findFirstStatement(Statements.ClassDefinition);
73921
+ if (cdef === undefined) {
73922
+ continue;
73923
+ }
73924
+ const cdefConcat = cdef === null || cdef === void 0 ? void 0 : cdef.concatTokens().toUpperCase();
73925
+ if ((cdefConcat === null || cdefConcat === void 0 ? void 0 : cdefConcat.includes(" FOR TESTING")) === false) {
73926
+ continue;
73927
+ }
73928
+ const hasDuration = cdefConcat === null || cdefConcat === void 0 ? void 0 : cdefConcat.includes(" DURATION ");
73929
+ const hasRiskLevel = cdefConcat === null || cdefConcat === void 0 ? void 0 : cdefConcat.includes(" RISK LEVEL ");
73930
+ if (hasDuration === true && hasRiskLevel === true) {
73931
+ continue;
73932
+ }
73933
+ let hasTestMethod = false;
73934
+ for (const mdef of classStructure.findAllStatements(Statements.MethodDef)) {
73935
+ const concat = mdef.concatTokens().toUpperCase();
73936
+ if (concat.includes(" FOR TESTING")) {
73937
+ hasTestMethod = true;
73938
+ }
73939
+ }
73940
+ if (hasTestMethod === false) {
73941
+ continue;
73942
+ }
73943
+ if (hasDuration === false) {
73944
+ issues.push(issue_1.Issue.atStatement(file, cdef, "Add DURATION", this.getMetadata().key, this.getConfig().severity));
73945
+ }
73946
+ if (hasRiskLevel === false) {
73947
+ issues.push(issue_1.Issue.atStatement(file, cdef, "Add RISK LEVEL", this.getMetadata().key, this.getConfig().severity));
73948
+ }
73949
+ }
73950
+ return issues;
73951
+ }
73952
+ }
73953
+ exports.AddTestAttributes = AddTestAttributes;
73954
+ //# sourceMappingURL=add_test_attributes.js.map
73955
+
73956
+ /***/ },
73957
+
73958
+ /***/ "../core/build/src/rules/aff_and_xml.js"
73959
+ /*!**********************************************!*\
73960
+ !*** ../core/build/src/rules/aff_and_xml.js ***!
73961
+ \**********************************************/
73962
+ (__unused_webpack_module, exports, __webpack_require__) {
73963
+
73964
+ "use strict";
73965
+
73966
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
73967
+ exports.AFFAndXML = exports.AFFAndXMLConf = void 0;
73968
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
73969
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
73970
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
73971
+ class AFFAndXMLConf extends _basic_rule_config_1.BasicRuleConfig {
73972
+ }
73973
+ exports.AFFAndXMLConf = AFFAndXMLConf;
73974
+ class AFFAndXML {
73975
+ constructor() {
73976
+ this.conf = new AFFAndXMLConf();
73977
+ }
73978
+ getMetadata() {
73979
+ return {
73980
+ key: "aff_and_xml",
73981
+ title: "AFF and XML",
73982
+ shortDescription: `Checks for objects that have both AFF (.json) and XML (.xml) files`,
73983
+ extendedInformation: `If an object has both an ABAP file format JSON file and an XML file, the XML file should be removed`,
73984
+ tags: [_irule_1.RuleTag.Syntax],
73985
+ };
73986
+ }
73987
+ getConfig() {
73988
+ return this.conf;
73989
+ }
73990
+ setConfig(conf) {
73991
+ this.conf = conf;
73992
+ }
73993
+ initialize(_reg) {
73994
+ return this;
73995
+ }
73996
+ run(obj) {
73997
+ const files = obj.getFiles();
73998
+ let hasJSON = false;
73999
+ let hasXML = false;
74000
+ const type = obj.getType().toLowerCase();
74001
+ for (const file of files) {
74002
+ const filename = file.getFilename().toLowerCase();
74003
+ if (filename.endsWith("." + type + ".json")) {
74004
+ hasJSON = true;
74005
+ }
74006
+ else if (filename.endsWith("." + type + ".xml")) {
74007
+ hasXML = true;
74008
+ }
74009
+ }
74010
+ if (hasJSON && hasXML) {
74011
+ const xmlFile = obj.getXMLFile();
74012
+ if (xmlFile) {
74013
+ const message = "Object has both AFF JSON and XML files, remove the XML";
74014
+ return [issue_1.Issue.atRow(xmlFile, 1, message, this.getMetadata().key, this.conf.severity)];
74015
+ }
74016
+ }
74017
+ return [];
74018
+ }
74019
+ }
74020
+ exports.AFFAndXML = AFFAndXML;
74021
+ //# sourceMappingURL=aff_and_xml.js.map
74022
+
74023
+ /***/ },
74024
+
74025
+ /***/ "../core/build/src/rules/alias_never_reassigned.js"
74026
+ /*!*********************************************************!*\
74027
+ !*** ../core/build/src/rules/alias_never_reassigned.js ***!
74028
+ \*********************************************************/
74029
+ (__unused_webpack_module, exports, __webpack_require__) {
74030
+
74031
+ "use strict";
74032
+
74033
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
74034
+ if (k2 === undefined) k2 = k;
74035
+ var desc = Object.getOwnPropertyDescriptor(m, k);
74036
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
74037
+ desc = { enumerable: true, get: function() { return m[k]; } };
74038
+ }
74039
+ Object.defineProperty(o, k2, desc);
74040
+ }) : (function(o, m, k, k2) {
74041
+ if (k2 === undefined) k2 = k;
74042
+ o[k2] = m[k];
74043
+ }));
74044
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
74045
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
74046
+ }) : function(o, v) {
74047
+ o["default"] = v;
74048
+ });
74049
+ var __importStar = (this && this.__importStar) || (function () {
74050
+ var ownKeys = function(o) {
74051
+ ownKeys = Object.getOwnPropertyNames || function (o) {
74052
+ var ar = [];
74053
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
74054
+ return ar;
74055
+ };
74056
+ return ownKeys(o);
74057
+ };
74058
+ return function (mod) {
74059
+ if (mod && mod.__esModule) return mod;
74060
+ var result = {};
74061
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
74062
+ __setModuleDefault(result, mod);
74063
+ return result;
74064
+ };
74065
+ })();
74066
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
74067
+ exports.AliasNeverReassigned = exports.AliasNeverReassignedConf = void 0;
74068
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
74069
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
72634
74070
  const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
72635
- const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
72636
74071
  const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
72637
- const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
72638
- const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
72639
- const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
72640
- class AddTestAttributesConf extends _basic_rule_config_1.BasicRuleConfig {
72641
- }
72642
- exports.AddTestAttributesConf = AddTestAttributesConf;
72643
- class AddTestAttributes extends _abap_rule_1.ABAPRule {
72644
- constructor() {
72645
- super(...arguments);
72646
- this.conf = new AddTestAttributesConf();
72647
- }
72648
- getMetadata() {
72649
- return {
72650
- key: "add_test_attributes",
72651
- title: "Add test attributes for tests classes with test methods",
72652
- shortDescription: `Add test attributes DURATION and RISK LEVEL for tests classes with test methods`,
72653
- tags: [_irule_1.RuleTag.SingleFile],
72654
- badExample: `CLASS ltcl_test1 DEFINITION FINAL FOR TESTING.
72655
- PUBLIC SECTION.
72656
- PROTECTED SECTION.
72657
- PRIVATE SECTION.
72658
- METHODS test FOR TESTING RAISING cx_static_check.
72659
- ENDCLASS.
72660
-
72661
- CLASS ltcl_test1 IMPLEMENTATION.
72662
- METHOD test.
72663
- ENDMETHOD.
72664
- ENDCLASS.`,
72665
- goodExample: `CLASS ltcl_test2 DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
72666
- PUBLIC SECTION.
72667
- PROTECTED SECTION.
72668
- PRIVATE SECTION.
72669
- METHODS test FOR TESTING RAISING cx_static_check.
72670
- ENDCLASS.
72671
-
72672
- CLASS ltcl_test2 IMPLEMENTATION.
72673
- METHOD test.
72674
- ENDMETHOD.
72675
- ENDCLASS.`,
72676
- };
72677
- }
72678
- getConfig() {
72679
- return this.conf;
72680
- }
72681
- setConfig(conf) {
72682
- this.conf = conf;
72683
- }
72684
- runParsed(file) {
72685
- const issues = [];
72686
- const stru = file.getStructure();
72687
- if (stru === undefined) {
72688
- return [];
72689
- }
72690
- for (const classStructure of stru.findAllStructures(Structures.ClassDefinition)) {
72691
- const cdef = classStructure.findFirstStatement(Statements.ClassDefinition);
72692
- if (cdef === undefined) {
72693
- continue;
72694
- }
72695
- const cdefConcat = cdef === null || cdef === void 0 ? void 0 : cdef.concatTokens().toUpperCase();
72696
- if ((cdefConcat === null || cdefConcat === void 0 ? void 0 : cdefConcat.includes(" FOR TESTING")) === false) {
72697
- continue;
72698
- }
72699
- const hasDuration = cdefConcat === null || cdefConcat === void 0 ? void 0 : cdefConcat.includes(" DURATION ");
72700
- const hasRiskLevel = cdefConcat === null || cdefConcat === void 0 ? void 0 : cdefConcat.includes(" RISK LEVEL ");
72701
- if (hasDuration === true && hasRiskLevel === true) {
72702
- continue;
72703
- }
72704
- let hasTestMethod = false;
72705
- for (const mdef of classStructure.findAllStatements(Statements.MethodDef)) {
72706
- const concat = mdef.concatTokens().toUpperCase();
72707
- if (concat.includes(" FOR TESTING")) {
72708
- hasTestMethod = true;
72709
- }
72710
- }
72711
- if (hasTestMethod === false) {
72712
- continue;
72713
- }
72714
- if (hasDuration === false) {
72715
- issues.push(issue_1.Issue.atStatement(file, cdef, "Add DURATION", this.getMetadata().key, this.getConfig().severity));
72716
- }
72717
- if (hasRiskLevel === false) {
72718
- issues.push(issue_1.Issue.atStatement(file, cdef, "Add RISK LEVEL", this.getMetadata().key, this.getConfig().severity));
72719
- }
72720
- }
72721
- return issues;
72722
- }
72723
- }
72724
- exports.AddTestAttributes = AddTestAttributes;
72725
- //# sourceMappingURL=add_test_attributes.js.map
72726
-
72727
- /***/ },
72728
-
72729
- /***/ "../core/build/src/rules/aff_and_xml.js"
72730
- /*!**********************************************!*\
72731
- !*** ../core/build/src/rules/aff_and_xml.js ***!
72732
- \**********************************************/
72733
- (__unused_webpack_module, exports, __webpack_require__) {
72734
-
72735
- "use strict";
72736
-
72737
- Object.defineProperty(exports, "__esModule", ({ value: true }));
72738
- exports.AFFAndXML = exports.AFFAndXMLConf = void 0;
72739
- const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
72740
74072
  const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
72741
- const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
72742
- class AFFAndXMLConf extends _basic_rule_config_1.BasicRuleConfig {
74073
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
74074
+ class AliasNeverReassignedConf extends _basic_rule_config_1.BasicRuleConfig {
72743
74075
  }
72744
- exports.AFFAndXMLConf = AFFAndXMLConf;
72745
- class AFFAndXML {
74076
+ exports.AliasNeverReassignedConf = AliasNeverReassignedConf;
74077
+ class AliasNeverReassigned {
72746
74078
  constructor() {
72747
- this.conf = new AFFAndXMLConf();
74079
+ this.conf = new AliasNeverReassignedConf();
72748
74080
  }
72749
74081
  getMetadata() {
72750
74082
  return {
72751
- key: "aff_and_xml",
72752
- title: "AFF and XML",
72753
- shortDescription: `Checks for objects that have both AFF (.json) and XML (.xml) files`,
72754
- extendedInformation: `If an object has both an ABAP file format JSON file and an XML file, the XML file should be removed`,
72755
- tags: [_irule_1.RuleTag.Syntax],
74083
+ key: "alias_never_reassigned",
74084
+ title: "Alias never reassigned",
74085
+ shortDescription: `Finds DATA(a) = b. where neither a nor b changes afterwards, so b can be read instead of a`,
74086
+ extendedInformation: `Reports DATA(a) = b. when all of the following hold:
74087
+
74088
+ * a is a local variable of a METHOD, FORM or FUNCTION, and has at least two more references, all of them reads,
74089
+ which do not take its address, bind a field symbol to it, or pass it to USING, CHANGING or EXPORTING
74090
+ * b is a local variable, or a component of one, whose address is never taken and which is not written
74091
+ after the declaration of a; or b is a constant or me
74092
+ * the declaration is executed before every read on every path: each read is in the block of the declaration
74093
+ or a nested block
74094
+
74095
+ a has the type of b, so reading b instead does not change any conversion.
74096
+ A constant b read in IF, ELSEIF, WHILE, CHECK, CASE or WHEN is not reported, see constant_condition.
74097
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
74098
+ INCLUDE, test seams, enhancements or native SQL.
74099
+
74100
+ The quick fix deletes the declaration and replaces every read of a with b. No release requirement.
74101
+
74102
+ See also unnecessary_copy for copies that are read once, also of attributes and parameters.`,
74103
+ tags: [_irule_1.RuleTag.Quickfix],
74104
+ badExample: `DATA(lo_file) = lo_input.
74105
+ lo_file->read( ).
74106
+ rv_name = lo_file->get_name( ).`,
74107
+ goodExample: `lo_input->read( ).
74108
+ rv_name = lo_input->get_name( ).`,
72756
74109
  };
72757
74110
  }
72758
74111
  getConfig() {
@@ -72761,35 +74114,53 @@ class AFFAndXML {
72761
74114
  setConfig(conf) {
72762
74115
  this.conf = conf;
72763
74116
  }
72764
- initialize(_reg) {
74117
+ initialize(reg) {
74118
+ this.reg = reg;
72765
74119
  return this;
72766
74120
  }
72767
74121
  run(obj) {
72768
- const files = obj.getFiles();
72769
- let hasJSON = false;
72770
- let hasXML = false;
72771
- const type = obj.getType().toLowerCase();
72772
- for (const file of files) {
72773
- const filename = file.getFilename().toLowerCase();
72774
- if (filename.endsWith("." + type + ".json")) {
72775
- hasJSON = true;
72776
- }
72777
- else if (filename.endsWith("." + type + ".xml")) {
72778
- hasXML = true;
72779
- }
74122
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
74123
+ if (analysis === undefined) {
74124
+ return [];
72780
74125
  }
72781
- if (hasJSON && hasXML) {
72782
- const xmlFile = obj.getXMLFile();
72783
- if (xmlFile) {
72784
- const message = "Object has both AFF JSON and XML files, remove the XML";
72785
- return [issue_1.Issue.atRow(xmlFile, 1, message, this.getMetadata().key, this.conf.severity)];
74126
+ const issues = [];
74127
+ for (const procedure of analysis.procedures) {
74128
+ if (procedure.supported === false) {
74129
+ continue;
74130
+ }
74131
+ for (const variable of procedure.locals()) {
74132
+ const declaration = variable.declaration;
74133
+ const move = variable.inline ? (0, _procedure_analysis_1.plainMove)(declaration) : undefined;
74134
+ const reads = variable.occurrences;
74135
+ if (move === undefined || move.operator !== "="
74136
+ || move.target.getChildren().length !== 1
74137
+ || move.target.findDirectExpression(Expressions.InlineData) === undefined
74138
+ || reads.length < 2 || reads.some(r => r.kind !== _procedure_analysis_1.OccurrenceKind.Read)
74139
+ || reads.some(r => !procedure.dominates(declaration, r.statement))) {
74140
+ continue;
74141
+ }
74142
+ const source = (0, _procedure_analysis_1.dataSource)(procedure, move.source);
74143
+ if (source === undefined || source.base === variable
74144
+ || (source.kind === _procedure_analysis_1.SourceKind.Immutable && reads.some(r => (0, _procedure_analysis_1.isCondition)(r.statement)))
74145
+ || (source.kind === _procedure_analysis_1.SourceKind.Local
74146
+ && (source.base.escapes() || source.base.writes().some(w => w.index >= procedure.index(declaration))))
74147
+ || source.kind === _procedure_analysis_1.SourceKind.Volatile) {
74148
+ continue;
74149
+ }
74150
+ const edits = [(0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)];
74151
+ for (const read of reads) {
74152
+ edits.push(edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, source.text));
74153
+ }
74154
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
74155
+ const message = variable.identifier.getName() + " is a copy of " + source.text + ", and neither changes";
74156
+ issues.push(issue_1.Issue.atStatement(procedure.file, declaration, message, this.getMetadata().key, this.conf.severity, fix));
72786
74157
  }
72787
74158
  }
72788
- return [];
74159
+ return issues;
72789
74160
  }
72790
74161
  }
72791
- exports.AFFAndXML = AFFAndXML;
72792
- //# sourceMappingURL=aff_and_xml.js.map
74162
+ exports.AliasNeverReassigned = AliasNeverReassigned;
74163
+ //# sourceMappingURL=alias_never_reassigned.js.map
72793
74164
 
72794
74165
  /***/ },
72795
74166
 
@@ -74181,42 +75552,371 @@ var __importStar = (this && this.__importStar) || (function () {
74181
75552
  };
74182
75553
  })();
74183
75554
  Object.defineProperty(exports, "__esModule", ({ value: true }));
74184
- exports.BeginSingleInclude = exports.BeginSingleIncludeConf = void 0;
75555
+ exports.BeginSingleInclude = exports.BeginSingleIncludeConf = void 0;
75556
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
75557
+ const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
75558
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
75559
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
75560
+ const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
75561
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
75562
+ class BeginSingleIncludeConf extends _basic_rule_config_1.BasicRuleConfig {
75563
+ }
75564
+ exports.BeginSingleIncludeConf = BeginSingleIncludeConf;
75565
+ class BeginSingleInclude extends _abap_rule_1.ABAPRule {
75566
+ constructor() {
75567
+ super(...arguments);
75568
+ this.conf = new BeginSingleIncludeConf();
75569
+ }
75570
+ getMetadata() {
75571
+ return {
75572
+ key: "begin_single_include",
75573
+ title: "BEGIN contains single INCLUDE",
75574
+ shortDescription: `Finds TYPE BEGIN with just one INCLUDE TYPE, and DATA with single INCLUDE STRUCTURE`,
75575
+ tags: [_irule_1.RuleTag.SingleFile],
75576
+ badExample: `TYPES: BEGIN OF dummy1.
75577
+ INCLUDE TYPE dselc.
75578
+ TYPES: END OF dummy1.
75579
+
75580
+ DATA BEGIN OF foo.
75581
+ INCLUDE STRUCTURE syst.
75582
+ DATA END OF foo.
75583
+
75584
+ STATICS BEGIN OF bar.
75585
+ INCLUDE STRUCTURE syst.
75586
+ STATICS END OF bar.`,
75587
+ goodExample: `DATA BEGIN OF foo.
75588
+ DATA field TYPE i.
75589
+ INCLUDE STRUCTURE dselc.
75590
+ DATA END OF foo.`,
75591
+ };
75592
+ }
75593
+ getConfig() {
75594
+ return this.conf;
75595
+ }
75596
+ setConfig(conf) {
75597
+ this.conf = conf;
75598
+ }
75599
+ runParsed(file) {
75600
+ const issues = [];
75601
+ const stru = file.getStructure();
75602
+ if (stru === undefined) {
75603
+ return [];
75604
+ }
75605
+ for (const t of stru.findAllStructures(Structures.Types)) {
75606
+ if (t.getChildren().length !== 3) {
75607
+ continue;
75608
+ }
75609
+ if (t.findFirstStatement(Statements.IncludeType)) {
75610
+ const token = t.getFirstToken();
75611
+ const message = "TYPE BEGIN with single INCLUDE";
75612
+ const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
75613
+ issues.push(issue);
75614
+ }
75615
+ }
75616
+ for (const t of stru.findAllStructures(Structures.Data)) {
75617
+ if (t.getChildren().length !== 3) {
75618
+ continue;
75619
+ }
75620
+ const data = t.findFirstStatement(Statements.DataBegin);
75621
+ if (data === null || data === void 0 ? void 0 : data.findDirectTokenByText("OCCURS")) {
75622
+ continue;
75623
+ }
75624
+ if (t.findFirstStatement(Statements.IncludeType)) {
75625
+ const token = t.getFirstToken();
75626
+ const message = "DATA BEGIN with single INCLUDE";
75627
+ const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
75628
+ issues.push(issue);
75629
+ }
75630
+ }
75631
+ for (const t of stru.findAllStructures(Structures.Statics)) {
75632
+ if (t.getChildren().length !== 3) {
75633
+ continue;
75634
+ }
75635
+ if (t.findFirstStatement(Statements.IncludeType)) {
75636
+ const token = t.getFirstToken();
75637
+ const message = "STATICS BEGIN with single INCLUDE";
75638
+ const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
75639
+ issues.push(issue);
75640
+ }
75641
+ }
75642
+ return issues;
75643
+ }
75644
+ }
75645
+ exports.BeginSingleInclude = BeginSingleInclude;
75646
+ //# sourceMappingURL=begin_single_include.js.map
75647
+
75648
+ /***/ },
75649
+
75650
+ /***/ "../core/build/src/rules/boolean_flag_via_if.js"
75651
+ /*!******************************************************!*\
75652
+ !*** ../core/build/src/rules/boolean_flag_via_if.js ***!
75653
+ \******************************************************/
75654
+ (__unused_webpack_module, exports, __webpack_require__) {
75655
+
75656
+ "use strict";
75657
+
75658
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
75659
+ if (k2 === undefined) k2 = k;
75660
+ var desc = Object.getOwnPropertyDescriptor(m, k);
75661
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
75662
+ desc = { enumerable: true, get: function() { return m[k]; } };
75663
+ }
75664
+ Object.defineProperty(o, k2, desc);
75665
+ }) : (function(o, m, k, k2) {
75666
+ if (k2 === undefined) k2 = k;
75667
+ o[k2] = m[k];
75668
+ }));
75669
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
75670
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
75671
+ }) : function(o, v) {
75672
+ o["default"] = v;
75673
+ });
75674
+ var __importStar = (this && this.__importStar) || (function () {
75675
+ var ownKeys = function(o) {
75676
+ ownKeys = Object.getOwnPropertyNames || function (o) {
75677
+ var ar = [];
75678
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
75679
+ return ar;
75680
+ };
75681
+ return ownKeys(o);
75682
+ };
75683
+ return function (mod) {
75684
+ if (mod && mod.__esModule) return mod;
75685
+ var result = {};
75686
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
75687
+ __setModuleDefault(result, mod);
75688
+ return result;
75689
+ };
75690
+ })();
75691
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
75692
+ exports.BooleanFlagViaIf = exports.BooleanFlagViaIfConf = void 0;
75693
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
75694
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
75695
+ const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
75696
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
74185
75697
  const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
74186
- const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
75698
+ const version_1 = __webpack_require__(/*! ../version */ "../core/build/src/version.js");
74187
75699
  const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
74188
- const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
74189
- const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
74190
75700
  const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
74191
- class BeginSingleIncludeConf extends _basic_rule_config_1.BasicRuleConfig {
75701
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
75702
+ class BooleanFlagViaIfConf extends _basic_rule_config_1.BasicRuleConfig {
74192
75703
  }
74193
- exports.BeginSingleIncludeConf = BeginSingleIncludeConf;
74194
- class BeginSingleInclude extends _abap_rule_1.ABAPRule {
75704
+ exports.BooleanFlagViaIfConf = BooleanFlagViaIfConf;
75705
+ class BooleanFlagViaIf {
74195
75706
  constructor() {
74196
- super(...arguments);
74197
- this.conf = new BeginSingleIncludeConf();
75707
+ this.conf = new BooleanFlagViaIfConf();
74198
75708
  }
74199
75709
  getMetadata() {
74200
75710
  return {
74201
- key: "begin_single_include",
74202
- title: "BEGIN contains single INCLUDE",
74203
- shortDescription: `Finds TYPE BEGIN with just one INCLUDE TYPE, and DATA with single INCLUDE STRUCTURE`,
74204
- tags: [_irule_1.RuleTag.SingleFile],
74205
- badExample: `TYPES: BEGIN OF dummy1.
74206
- INCLUDE TYPE dselc.
74207
- TYPES: END OF dummy1.
75711
+ key: "boolean_flag_via_if",
75712
+ title: "Boolean flag via IF",
75713
+ shortDescription: `Finds a flag that is initialized to false and set to true in a single IF, use xsdbool`,
75714
+ extendedInformation: `Reports DATA(f) = VALUE abap_bool( )., DATA(f) = abap_false. or DATA f TYPE abap_bool.,
75715
+ later followed by IF cond. f = abap_true. ENDIF., when all of the following hold:
75716
+
75717
+ * f is a local variable of a METHOD, FORM or FUNCTION, of type c LENGTH 1, its address is never taken
75718
+ * the IF has no ELSEIF and no ELSE, its only statement is f = abap_true. and it contains no comments
75719
+ * f has no other write, and is not read before the IF
75720
+ * the IF is in the same block and the same loop as the declaration; DATA f TYPE abap_bool. is not
75721
+ executed per loop iteration, so neither it nor the IF may be in a loop
75722
+
75723
+ Requires xsdbool, ie. 7.40 SP08 or above, ABAP Cloud or open-abap.
75724
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
75725
+ INCLUDE, test seams, enhancements or native SQL.
75726
+
75727
+ The quick fix deletes an inline declaration and replaces the IF with DATA(f) = xsdbool( cond ).,
75728
+ or keeps DATA f TYPE abap_bool. and replaces the IF with f = xsdbool( cond ).
75729
+
75730
+ use_bool_expression covers IF with an ELSE branch, without looking at the declaration and the other uses.`,
75731
+ tags: [_irule_1.RuleTag.Quickfix],
75732
+ badExample: `DATA(lv_found) = abap_false.
75733
+ IF line_exists( lt_rows[ id = lv_id ] ).
75734
+ lv_found = abap_true.
75735
+ ENDIF.`,
75736
+ goodExample: `DATA(lv_found) = xsdbool( line_exists( lt_rows[ id = lv_id ] ) ).`,
75737
+ };
75738
+ }
75739
+ getConfig() {
75740
+ return this.conf;
75741
+ }
75742
+ setConfig(conf) {
75743
+ this.conf = conf;
75744
+ }
75745
+ initialize(reg) {
75746
+ this.reg = reg;
75747
+ return this;
75748
+ }
75749
+ run(obj) {
75750
+ var _a, _b;
75751
+ const config = this.reg.getConfig();
75752
+ if (!(0, version_1.releaseAtLeast)(config.getRelease(), version_1.Release.v740sp08)
75753
+ && config.getLanguageVersion() !== version_1.LanguageVersion.Cloud
75754
+ && !config.isOpenABAP()) {
75755
+ return [];
75756
+ }
75757
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
75758
+ if (analysis === undefined) {
75759
+ return [];
75760
+ }
75761
+ const issues = [];
75762
+ for (const procedure of analysis.procedures) {
75763
+ if (procedure.supported === false) {
75764
+ continue;
75765
+ }
75766
+ for (const variable of procedure.locals()) {
75767
+ const declaration = variable.declaration;
75768
+ const type = variable.identifier.getType();
75769
+ const writes = variable.writes();
75770
+ if (!(type instanceof basic_1.CharacterType) || type.getLength() !== 1 || variable.escapes()
75771
+ || writes.length !== 1 || !this.initiallyFalse(procedure, variable.inline, declaration)) {
75772
+ continue;
75773
+ }
75774
+ const write = writes[0];
75775
+ const move = (0, _procedure_analysis_1.plainMove)(write.statement);
75776
+ const value = move === undefined ? undefined : (0, _procedure_analysis_1.characterConstant)(procedure, move.source);
75777
+ const check = procedure.statements[write.index - 1];
75778
+ const structure = procedure.ifStructure(check);
75779
+ const branches = structure === undefined ? undefined : (0, _procedure_analysis_1.ifBranches)(structure);
75780
+ const endIf = structure === null || structure === void 0 ? void 0 : structure.findDirectStatement(Statements.EndIf);
75781
+ if (move === undefined || move.operator !== "=" || value === undefined || !(0, _procedure_analysis_1.sameCharacters)(value, "X")
75782
+ || ((_a = (0, _procedure_analysis_1.singleTarget)(move.target)) === null || _a === void 0 ? void 0 : _a.getStart().equals(write.token.getStart())) !== true
75783
+ || !((check === null || check === void 0 ? void 0 : check.get()) instanceof Statements.If) || check.getColon() !== undefined
75784
+ || structure === undefined || endIf === undefined || (branches === null || branches === void 0 ? void 0 : branches.length) !== 1
75785
+ || ((_b = branches[0].body) === null || _b === void 0 ? void 0 : _b.findAllStatementNodes().length) !== 1
75786
+ || procedure.block(check) !== procedure.block(declaration)
75787
+ || !procedure.sameLoop(check, declaration)
75788
+ || (!variable.inline && (procedure.loop(check) !== undefined || procedure.loop(declaration) !== undefined))
75789
+ || variable.occurrences.some(o => o.kind === _procedure_analysis_1.OccurrenceKind.Read && o.index <= procedure.index(endIf))
75790
+ || procedure.hasComment(check.getStart(), endIf.getEnd())) {
75791
+ continue;
75792
+ }
75793
+ const cond = check.findDirectExpression(Expressions.Cond);
75794
+ if (cond === undefined) {
75795
+ continue;
75796
+ }
75797
+ const name = write.token.getStr();
75798
+ const assignment = (variable.inline ? "DATA(" + name + ")" : name) + " = xsdbool( " + (0, _procedure_analysis_1.nodeText)(procedure.file, cond) + " ).";
75799
+ const edits = [edit_helper_1.EditHelper.replaceRange(procedure.file, check.getStart(), endIf.getEnd(), assignment)];
75800
+ if (variable.inline) {
75801
+ edits.push((0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration));
75802
+ }
75803
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
75804
+ issues.push(issue_1.Issue.atStatement(procedure.file, check, "Use xsdbool to set " + name, this.getMetadata().key, this.conf.severity, fix));
75805
+ }
75806
+ }
75807
+ return issues;
75808
+ }
75809
+ /** DATA(f) = VALUE abap_bool( ). DATA(f) = abap_false. or DATA f TYPE abap_bool. */
75810
+ initiallyFalse(procedure, inline, declaration) {
75811
+ if (inline === false) {
75812
+ return (0, _procedure_analysis_1.plainData)(declaration) && declaration.getColon() === undefined;
75813
+ }
75814
+ const move = (0, _procedure_analysis_1.plainMove)(declaration);
75815
+ if (move === undefined || move.operator !== "=" || move.target.getChildren().length !== 1
75816
+ || move.target.findDirectExpression(Expressions.InlineData) === undefined) {
75817
+ return false;
75818
+ }
75819
+ const constant = (0, _procedure_analysis_1.characterConstant)(procedure, move.source);
75820
+ return (constant !== undefined && (0, _procedure_analysis_1.sameCharacters)(constant, "")) || this.initialValue(move.source);
75821
+ }
75822
+ /** VALUE type( ) */
75823
+ initialValue(source) {
75824
+ const tokens = source.getTokens();
75825
+ return tokens.length === 4 && tokens[0].getStr().toUpperCase() === "VALUE"
75826
+ && source.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined
75827
+ && tokens[1].getStr() !== "#" && tokens[2].getStr() === "(" && tokens[3].getStr() === ")";
75828
+ }
75829
+ }
75830
+ exports.BooleanFlagViaIf = BooleanFlagViaIf;
75831
+ //# sourceMappingURL=boolean_flag_via_if.js.map
74208
75832
 
74209
- DATA BEGIN OF foo.
74210
- INCLUDE STRUCTURE syst.
74211
- DATA END OF foo.
75833
+ /***/ },
74212
75834
 
74213
- STATICS BEGIN OF bar.
74214
- INCLUDE STRUCTURE syst.
74215
- STATICS END OF bar.`,
74216
- goodExample: `DATA BEGIN OF foo.
74217
- DATA field TYPE i.
74218
- INCLUDE STRUCTURE dselc.
74219
- DATA END OF foo.`,
75835
+ /***/ "../core/build/src/rules/bound_check_after_create.js"
75836
+ /*!***********************************************************!*\
75837
+ !*** ../core/build/src/rules/bound_check_after_create.js ***!
75838
+ \***********************************************************/
75839
+ (__unused_webpack_module, exports, __webpack_require__) {
75840
+
75841
+ "use strict";
75842
+
75843
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
75844
+ if (k2 === undefined) k2 = k;
75845
+ var desc = Object.getOwnPropertyDescriptor(m, k);
75846
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
75847
+ desc = { enumerable: true, get: function() { return m[k]; } };
75848
+ }
75849
+ Object.defineProperty(o, k2, desc);
75850
+ }) : (function(o, m, k, k2) {
75851
+ if (k2 === undefined) k2 = k;
75852
+ o[k2] = m[k];
75853
+ }));
75854
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
75855
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
75856
+ }) : function(o, v) {
75857
+ o["default"] = v;
75858
+ });
75859
+ var __importStar = (this && this.__importStar) || (function () {
75860
+ var ownKeys = function(o) {
75861
+ ownKeys = Object.getOwnPropertyNames || function (o) {
75862
+ var ar = [];
75863
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
75864
+ return ar;
75865
+ };
75866
+ return ownKeys(o);
75867
+ };
75868
+ return function (mod) {
75869
+ if (mod && mod.__esModule) return mod;
75870
+ var result = {};
75871
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
75872
+ __setModuleDefault(result, mod);
75873
+ return result;
75874
+ };
75875
+ })();
75876
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
75877
+ exports.BoundCheckAfterCreate = exports.BoundCheckAfterCreateConf = void 0;
75878
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
75879
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
75880
+ const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
75881
+ const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
75882
+ const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
75883
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
75884
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
75885
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
75886
+ class BoundCheckAfterCreateConf extends _basic_rule_config_1.BasicRuleConfig {
75887
+ }
75888
+ exports.BoundCheckAfterCreateConf = BoundCheckAfterCreateConf;
75889
+ class BoundCheckAfterCreate {
75890
+ constructor() {
75891
+ this.conf = new BoundCheckAfterCreateConf();
75892
+ }
75893
+ getMetadata() {
75894
+ return {
75895
+ key: "bound_check_after_create",
75896
+ title: "Bound check after create",
75897
+ shortDescription: `Finds IF r IS BOUND / IS NOT BOUND directly after r was created`,
75898
+ extendedInformation: `Reports IF r IS BOUND. and IF r IS NOT BOUND. after CREATE OBJECT r., r = NEW ...( ). or
75899
+ DATA(r) = NEW ...( ). in the same block, when all of the following hold:
75900
+
75901
+ * r is a local variable whose address is never taken, or an attribute: attr, me->attr or local->attr
75902
+ * CREATE OBJECT has no EXCEPTIONS addition and no dynamic type, NEW is not followed by a method call
75903
+ * every statement in between is a direct statement of the same block, not a nested structure
75904
+ * a local r is not written in between
75905
+ * for an attribute: no method, function or form call and no constructor in between, the local before ->
75906
+ is not written, and no write in between can change the attribute: no write to an attribute with the
75907
+ same name, to a field symbol, via ->*, or to a parameter passed by reference
75908
+
75909
+ The quick fix keeps the IS BOUND branch and removes the rest, or removes the IS NOT BOUND branch;
75910
+ nothing is reported if a removed branch declares data that is used outside of it.
75911
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
75912
+ INCLUDE, test seams, enhancements or native SQL. No release requirement.`,
75913
+ tags: [_irule_1.RuleTag.Quickfix],
75914
+ badExample: `CREATE OBJECT lo_log.
75915
+ IF lo_log IS BOUND.
75916
+ lo_log->add( 'started' ).
75917
+ ENDIF.`,
75918
+ goodExample: `CREATE OBJECT lo_log.
75919
+ lo_log->add( 'started' ).`,
74220
75920
  };
74221
75921
  }
74222
75922
  getConfig() {
@@ -74225,54 +75925,182 @@ DATA END OF foo.`,
74225
75925
  setConfig(conf) {
74226
75926
  this.conf = conf;
74227
75927
  }
74228
- runParsed(file) {
74229
- const issues = [];
74230
- const stru = file.getStructure();
74231
- if (stru === undefined) {
75928
+ initialize(reg) {
75929
+ this.reg = reg;
75930
+ return this;
75931
+ }
75932
+ run(obj) {
75933
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
75934
+ if (analysis === undefined) {
74232
75935
  return [];
74233
75936
  }
74234
- for (const t of stru.findAllStructures(Structures.Types)) {
74235
- if (t.getChildren().length !== 3) {
75937
+ const issues = [];
75938
+ for (const procedure of analysis.procedures) {
75939
+ if (procedure.supported === false) {
74236
75940
  continue;
74237
75941
  }
74238
- if (t.findFirstStatement(Statements.IncludeType)) {
74239
- const token = t.getFirstToken();
74240
- const message = "TYPE BEGIN with single INCLUDE";
74241
- const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
74242
- issues.push(issue);
75942
+ const candidates = [];
75943
+ for (const statement of procedure.statements) {
75944
+ const predicate = (0, _procedure_analysis_1.simplePredicate)(statement);
75945
+ if (!(statement.get() instanceof Statements.If) || (predicate === null || predicate === void 0 ? void 0 : predicate.kind) !== _procedure_analysis_1.PredicateKind.Bound) {
75946
+ continue;
75947
+ }
75948
+ const checked = this.path(procedure, predicate.left);
75949
+ const create = checked === undefined ? undefined : this.findCreate(procedure, statement, checked);
75950
+ const structure = procedure.ifStructure(statement);
75951
+ if (create === undefined || structure === undefined) {
75952
+ continue;
75953
+ }
75954
+ const bound = predicate.negated === false;
75955
+ const fix = (0, _procedure_analysis_1.foldIf)(procedure, structure, statement, bound);
75956
+ if (fix === undefined) {
75957
+ continue;
75958
+ }
75959
+ const message = predicate.left.concatTokens() + " is always bound, it is created in line " + create.getStart().getRow();
75960
+ candidates.push({ structure, statement, message, fix });
74243
75961
  }
75962
+ issues.push(...(0, _procedure_analysis_1.foldIssues)(procedure.file, candidates, this.getMetadata().key, this.conf.severity));
74244
75963
  }
74245
- for (const t of stru.findAllStructures(Structures.Data)) {
74246
- if (t.getChildren().length !== 3) {
74247
- continue;
75964
+ return issues;
75965
+ }
75966
+ /** the CREATE OBJECT or NEW before the IF in the same block, with only straight statements in between
75967
+ * that cannot change the reference */
75968
+ findCreate(procedure, check, path) {
75969
+ const index = procedure.index(check);
75970
+ const block = procedure.block(check);
75971
+ for (let i = index - 1; i >= 0; i--) {
75972
+ const statement = procedure.statements[i];
75973
+ if (procedure.block(statement) !== block || !procedure.isSimple(statement)) {
75974
+ return undefined;
74248
75975
  }
74249
- const data = t.findFirstStatement(Statements.DataBegin);
74250
- if (data === null || data === void 0 ? void 0 : data.findDirectTokenByText("OCCURS")) {
74251
- continue;
75976
+ const target = this.createdTarget(statement);
75977
+ const created = target === undefined ? undefined : this.path(procedure, target);
75978
+ if (created !== undefined && this.samePath(created, path)) {
75979
+ const between = procedure.straightBetween(statement, check);
75980
+ return between !== undefined && between.every(s => this.keeps(procedure, s, path)) ? statement : undefined;
74252
75981
  }
74253
- if (t.findFirstStatement(Statements.IncludeType)) {
74254
- const token = t.getFirstToken();
74255
- const message = "DATA BEGIN with single INCLUDE";
74256
- const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
74257
- issues.push(issue);
75982
+ }
75983
+ return undefined;
75984
+ }
75985
+ /** the target of CREATE OBJECT r. or r = NEW ...( ). */
75986
+ createdTarget(statement) {
75987
+ if (statement.get() instanceof Statements.CreateObject) {
75988
+ if (statement.findDirectTokenByText("EXCEPTIONS") !== undefined
75989
+ || statement.findFirstExpression(Expressions.Dynamic) !== undefined
75990
+ || statement.getColon() !== undefined) {
75991
+ return undefined;
74258
75992
  }
75993
+ return statement.findDirectExpression(Expressions.Target);
74259
75994
  }
74260
- for (const t of stru.findAllStructures(Structures.Statics)) {
74261
- if (t.getChildren().length !== 3) {
75995
+ const move = (0, _procedure_analysis_1.plainMove)(statement);
75996
+ const chain = move === null || move === void 0 ? void 0 : move.source.findDirectExpression(Expressions.MethodCallChain);
75997
+ if (move === undefined || move.operator !== "=" || move.source.getChildren().length !== 1
75998
+ || (chain === null || chain === void 0 ? void 0 : chain.getChildren().length) !== 1 || chain.findDirectExpression(Expressions.NewObject) === undefined) {
75999
+ return undefined;
76000
+ }
76001
+ return move.target;
76002
+ }
76003
+ /** r, DATA(r), attr, me->attr or local->attr, as target or source */
76004
+ path(procedure, node) {
76005
+ var _a;
76006
+ let children = node.getChildren();
76007
+ if (node.get() instanceof Expressions.Source) {
76008
+ const chain = node.findDirectExpression(Expressions.FieldChain);
76009
+ if (children.length !== 1 || chain === undefined) {
76010
+ return undefined;
76011
+ }
76012
+ children = chain.getChildren();
76013
+ }
76014
+ else if (children.length === 1 && node.findDirectExpression(Expressions.InlineData) !== undefined) {
76015
+ const name = node.findDirectExpression(Expressions.InlineData).findDirectExpression(Expressions.TargetField);
76016
+ const local = name === undefined ? undefined : procedure.local(procedure.identifierAt(name.getFirstToken()));
76017
+ return local === undefined || local.escapes() ? undefined : { local, attribute: undefined };
76018
+ }
76019
+ const first = procedure.identifierAt((_a = children[0]) === null || _a === void 0 ? void 0 : _a.getFirstToken());
76020
+ if (!(children[0] instanceof nodes_1.ExpressionNode) || !(first instanceof _typed_identifier_1.TypedIdentifier)) {
76021
+ return undefined;
76022
+ }
76023
+ const local = procedure.local(first);
76024
+ if (children.length === 1) {
76025
+ if (local !== undefined) {
76026
+ return local.escapes() ? undefined : { local, attribute: undefined };
76027
+ }
76028
+ return this.isAttribute(procedure, first) ? { local: undefined, attribute: first } : undefined;
76029
+ }
76030
+ const attribute = children[2] instanceof nodes_1.ExpressionNode && children[2].get() instanceof Expressions.AttributeName
76031
+ ? procedure.identifierAt(children[2].getFirstToken()) : undefined;
76032
+ if (children.length !== 3 || !(children[1] instanceof nodes_1.TokenNode) || children[1].getFirstToken().getStr() !== "->"
76033
+ || attribute === undefined || !this.isAttribute(procedure, attribute)) {
76034
+ return undefined;
76035
+ }
76036
+ if ((0, _procedure_analysis_1.isImmutable)(first) && first.getType() instanceof basic_1.ObjectReferenceType) {
76037
+ return { local: undefined, attribute };
76038
+ }
76039
+ else if (local !== undefined && !local.escapes()) {
76040
+ return { local, attribute };
76041
+ }
76042
+ return undefined;
76043
+ }
76044
+ isAttribute(procedure, identifier) {
76045
+ if (!(identifier instanceof _typed_identifier_1.TypedIdentifier) || identifier.getMeta().includes("static" /* IdentifierMeta.Static */)
76046
+ || procedure.contains(identifier)) {
76047
+ return false;
76048
+ }
76049
+ const meta = identifier.getMeta();
76050
+ return !meta.some(m => m === "importing" /* IdentifierMeta.MethodImporting */ || m === "exporting" /* IdentifierMeta.MethodExporting */
76051
+ || m === "changing" /* IdentifierMeta.MethodChanging */ || m === "returning" /* IdentifierMeta.MethodReturning */
76052
+ || m === "form_parameter" /* IdentifierMeta.FormParameter */ || m === "event_parameter" /* IdentifierMeta.EventParameter */
76053
+ || m === "function_module_importing" /* IdentifierMeta.FunctionModuleImporting */ || m === "function_module_exporting" /* IdentifierMeta.FunctionModuleExporting */
76054
+ || m === "function_module_changing" /* IdentifierMeta.FunctionModuleChanging */ || m === "function_module_tables" /* IdentifierMeta.FunctionModuleTables */
76055
+ || m === "built-in" /* IdentifierMeta.BuiltIn */ || m === "inline" /* IdentifierMeta.InlineDefinition */);
76056
+ }
76057
+ samePath(a, b) {
76058
+ const key = (i) => i === undefined ? "" : _procedure_analysis_1.ObjectAnalysis.key(i);
76059
+ return a.local === b.local && key(a.attribute) === key(b.attribute);
76060
+ }
76061
+ /** the statement between the create and the check cannot change the reference */
76062
+ keeps(procedure, statement, path) {
76063
+ const index = procedure.index(statement);
76064
+ if (path.local !== undefined && path.local.writes().some(w => w.index === index)) {
76065
+ return false;
76066
+ }
76067
+ if (path.attribute === undefined) {
76068
+ return true;
76069
+ }
76070
+ if (!procedure.isCallFree(statement)) {
76071
+ return false;
76072
+ }
76073
+ const attribute = _procedure_analysis_1.ObjectAnalysis.key(path.attribute);
76074
+ for (const target of statement.findAllExpressionsRecursive(Expressions.Target)) {
76075
+ if (target.findFirstExpression(Expressions.TargetFieldSymbol) !== undefined
76076
+ || target.findFirstExpression(Expressions.Dereference) !== undefined) {
76077
+ return false;
76078
+ }
76079
+ if (target.findDirectExpression(Expressions.InlineData) !== undefined) {
74262
76080
  continue;
74263
76081
  }
74264
- if (t.findFirstStatement(Statements.IncludeType)) {
74265
- const token = t.getFirstToken();
74266
- const message = "STATICS BEGIN with single INCLUDE";
74267
- const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
74268
- issues.push(issue);
76082
+ // the storage changed is inside the last attribute of the chain, or inside the first field
76083
+ const attributes = target.findDirectExpressions(Expressions.AttributeName);
76084
+ const field = attributes.length > 0 ? attributes[attributes.length - 1] : target.findDirectExpression(Expressions.TargetField);
76085
+ const changed = field === undefined ? undefined : procedure.identifierAt(field.getFirstToken());
76086
+ if (!(changed instanceof _typed_identifier_1.TypedIdentifier) || _procedure_analysis_1.ObjectAnalysis.key(changed) === attribute) {
76087
+ return false;
76088
+ }
76089
+ const meta = changed.getMeta();
76090
+ const variable = procedure.variable(changed);
76091
+ const parameter = !procedure.contains(changed) && !this.isAttribute(procedure, changed);
76092
+ if (parameter && !meta.includes("pass_by_value" /* IdentifierMeta.PassByValue */) && !meta.includes("returning" /* IdentifierMeta.MethodReturning */)) {
76093
+ return false;
76094
+ }
76095
+ else if ((variable === null || variable === void 0 ? void 0 : variable.isLocal()) === true && variable.escapes()) {
76096
+ return false;
74269
76097
  }
74270
76098
  }
74271
- return issues;
76099
+ return true;
74272
76100
  }
74273
76101
  }
74274
- exports.BeginSingleInclude = BeginSingleInclude;
74275
- //# sourceMappingURL=begin_single_include.js.map
76102
+ exports.BoundCheckAfterCreate = BoundCheckAfterCreate;
76103
+ //# sourceMappingURL=bound_check_after_create.js.map
74276
76104
 
74277
76105
  /***/ },
74278
76106
 
@@ -77274,6 +79102,93 @@ exports.ClassicExceptionsOverlap = ClassicExceptionsOverlap;
77274
79102
 
77275
79103
  /***/ },
77276
79104
 
79105
+ /***/ "../core/build/src/rules/clear_after_declaration.js"
79106
+ /*!**********************************************************!*\
79107
+ !*** ../core/build/src/rules/clear_after_declaration.js ***!
79108
+ \**********************************************************/
79109
+ (__unused_webpack_module, exports, __webpack_require__) {
79110
+
79111
+ "use strict";
79112
+
79113
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
79114
+ exports.ClearAfterDeclaration = exports.ClearAfterDeclarationConf = void 0;
79115
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
79116
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
79117
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
79118
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
79119
+ class ClearAfterDeclarationConf extends _basic_rule_config_1.BasicRuleConfig {
79120
+ }
79121
+ exports.ClearAfterDeclarationConf = ClearAfterDeclarationConf;
79122
+ class ClearAfterDeclaration {
79123
+ constructor() {
79124
+ this.conf = new ClearAfterDeclarationConf();
79125
+ }
79126
+ getMetadata() {
79127
+ return {
79128
+ key: "clear_after_declaration",
79129
+ title: "CLEAR after declaration",
79130
+ shortDescription: `Finds CLEAR of a local variable that is still initial since its declaration`,
79131
+ extendedInformation: `Reports CLEAR x. when all of the following hold:
79132
+
79133
+ * x is a local variable of a METHOD, FORM or FUNCTION, declared with DATA x TYPE/LIKE ... without VALUE
79134
+ * the CLEAR is the first reference to x after the declaration, it has no WITH addition
79135
+ * neither the DATA nor the CLEAR is inside a LOOP, DO, WHILE, SELECT loop, PROVIDE, or a TRY block with
79136
+ RETRY, RESUME or CATCH BEFORE UNWIND. DATA is not executed per iteration, so a CLEAR in a loop can be needed
79137
+
79138
+ Any later use of x does not matter, the CLEAR can only be reached with x still initial.
79139
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
79140
+ INCLUDE, test seams, enhancements or native SQL.
79141
+
79142
+ The quick fix deletes the CLEAR. No release requirement.`,
79143
+ tags: [_irule_1.RuleTag.Quickfix],
79144
+ badExample: `DATA lv_count TYPE i.
79145
+ CLEAR lv_count.`,
79146
+ goodExample: `DATA lv_count TYPE i.`,
79147
+ };
79148
+ }
79149
+ getConfig() {
79150
+ return this.conf;
79151
+ }
79152
+ setConfig(conf) {
79153
+ this.conf = conf;
79154
+ }
79155
+ initialize(reg) {
79156
+ this.reg = reg;
79157
+ return this;
79158
+ }
79159
+ run(obj) {
79160
+ var _a;
79161
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
79162
+ if (analysis === undefined) {
79163
+ return [];
79164
+ }
79165
+ const issues = [];
79166
+ for (const procedure of analysis.procedures) {
79167
+ if (procedure.supported === false) {
79168
+ continue;
79169
+ }
79170
+ for (const variable of procedure.locals()) {
79171
+ const declaration = variable.declaration;
79172
+ const first = variable.occurrences[0];
79173
+ if (variable.inline || !(0, _procedure_analysis_1.plainData)(declaration) || first === undefined
79174
+ || first.kind !== _procedure_analysis_1.OccurrenceKind.Write
79175
+ || ((_a = (0, _procedure_analysis_1.plainClear)(first.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(first.token.getStart())) !== true
79176
+ || procedure.loop(declaration) !== undefined
79177
+ || procedure.loop(first.statement) !== undefined) {
79178
+ continue;
79179
+ }
79180
+ const fix = (0, _procedure_analysis_1.deleteStatement)(procedure.file, first.statement);
79181
+ issues.push(issue_1.Issue.atStatement(procedure.file, first.statement, "CLEAR of " + variable.identifier.getName() + ", which is still initial", this.getMetadata().key, this.conf.severity, fix));
79182
+ }
79183
+ }
79184
+ return issues;
79185
+ }
79186
+ }
79187
+ exports.ClearAfterDeclaration = ClearAfterDeclaration;
79188
+ //# sourceMappingURL=clear_after_declaration.js.map
79189
+
79190
+ /***/ },
79191
+
77277
79192
  /***/ "../core/build/src/rules/clear_exporting_parameters.js"
77278
79193
  /*!*************************************************************!*\
77279
79194
  !*** ../core/build/src/rules/clear_exporting_parameters.js ***!
@@ -78045,6 +79960,218 @@ exports.ConstantClasses = ConstantClasses;
78045
79960
 
78046
79961
  /***/ },
78047
79962
 
79963
+ /***/ "../core/build/src/rules/constant_condition.js"
79964
+ /*!*****************************************************!*\
79965
+ !*** ../core/build/src/rules/constant_condition.js ***!
79966
+ \*****************************************************/
79967
+ (__unused_webpack_module, exports, __webpack_require__) {
79968
+
79969
+ "use strict";
79970
+
79971
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
79972
+ if (k2 === undefined) k2 = k;
79973
+ var desc = Object.getOwnPropertyDescriptor(m, k);
79974
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
79975
+ desc = { enumerable: true, get: function() { return m[k]; } };
79976
+ }
79977
+ Object.defineProperty(o, k2, desc);
79978
+ }) : (function(o, m, k, k2) {
79979
+ if (k2 === undefined) k2 = k;
79980
+ o[k2] = m[k];
79981
+ }));
79982
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
79983
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
79984
+ }) : function(o, v) {
79985
+ o["default"] = v;
79986
+ });
79987
+ var __importStar = (this && this.__importStar) || (function () {
79988
+ var ownKeys = function(o) {
79989
+ ownKeys = Object.getOwnPropertyNames || function (o) {
79990
+ var ar = [];
79991
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
79992
+ return ar;
79993
+ };
79994
+ return ownKeys(o);
79995
+ };
79996
+ return function (mod) {
79997
+ if (mod && mod.__esModule) return mod;
79998
+ var result = {};
79999
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
80000
+ __setModuleDefault(result, mod);
80001
+ return result;
80002
+ };
80003
+ })();
80004
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
80005
+ exports.ConstantCondition = exports.ConstantConditionConf = void 0;
80006
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
80007
+ const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
80008
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
80009
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
80010
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
80011
+ class ConstantConditionConf extends _basic_rule_config_1.BasicRuleConfig {
80012
+ }
80013
+ exports.ConstantConditionConf = ConstantConditionConf;
80014
+ class ConstantCondition {
80015
+ constructor() {
80016
+ this.conf = new ConstantConditionConf();
80017
+ }
80018
+ getMetadata() {
80019
+ return {
80020
+ key: "constant_condition",
80021
+ title: "Constant condition",
80022
+ shortDescription: `Finds IF and ELSEIF conditions on local variables whose value is known`,
80023
+ extendedInformation: `Reports two cases, for local variables of a METHOD, FORM or FUNCTION.
80024
+
80025
+ 1. DATA(c) = <constant>. where the constant is a character literal like 'X', or a character constant like
80026
+ abap_true, abap_false or space, and the only other reference to c is the condition of an IF or ELSEIF:
80027
+ c = <constant>, c <> <constant>, EQ, NE, c IS INITIAL, c IS NOT INITIAL, optionally with NOT.
80028
+ The declaration must be executed before the condition on every path: the IF is in the block of the
80029
+ declaration or a nested block. The quick fix deletes the declaration.
80030
+
80031
+ 2. DATA v TYPE ... without VALUE, where v is never changed, except by CLEAR v., and its address is never taken,
80032
+ in a condition v IS [NOT] INITIAL or v IS [NOT] BOUND. The declaration is kept.
80033
+
80034
+ The quick fix removes the IF branch that is never taken, or keeps the branch that is always taken and
80035
+ removes the rest, also in ELSEIF chains: a first IF branch that is never taken turns the next ELSEIF into IF,
80036
+ an ELSEIF branch that is always taken turns into ELSE. Nothing is reported if a removed branch declares
80037
+ data that is used outside of it.
80038
+
80039
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
80040
+ INCLUDE, test seams, enhancements or native SQL. No release requirement.`,
80041
+ tags: [_irule_1.RuleTag.Quickfix],
80042
+ badExample: `DATA(lv_active) = abap_true.
80043
+ IF lv_active = abap_true.
80044
+ run( ).
80045
+ ELSE.
80046
+ skip( ).
80047
+ ENDIF.`,
80048
+ goodExample: `run( ).`,
80049
+ };
80050
+ }
80051
+ getConfig() {
80052
+ return this.conf;
80053
+ }
80054
+ setConfig(conf) {
80055
+ this.conf = conf;
80056
+ }
80057
+ initialize(reg) {
80058
+ this.reg = reg;
80059
+ return this;
80060
+ }
80061
+ run(obj) {
80062
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
80063
+ if (analysis === undefined) {
80064
+ return [];
80065
+ }
80066
+ const issues = [];
80067
+ for (const procedure of analysis.procedures) {
80068
+ if (procedure.supported === false) {
80069
+ continue;
80070
+ }
80071
+ const candidates = [];
80072
+ for (const variable of procedure.locals()) {
80073
+ if (variable.inline) {
80074
+ this.constantVariable(procedure, variable, candidates);
80075
+ }
80076
+ else {
80077
+ this.initialVariable(procedure, variable, candidates);
80078
+ }
80079
+ }
80080
+ issues.push(...(0, _procedure_analysis_1.foldIssues)(procedure.file, candidates, this.getMetadata().key, this.conf.severity));
80081
+ }
80082
+ return issues;
80083
+ }
80084
+ /** DATA(c) = abap_true. IF c = abap_true. */
80085
+ constantVariable(procedure, variable, candidates) {
80086
+ const declaration = variable.declaration;
80087
+ const move = (0, _procedure_analysis_1.plainMove)(declaration);
80088
+ const read = variable.occurrences[0];
80089
+ if (move === undefined || move.operator !== "="
80090
+ || move.target.getChildren().length !== 1
80091
+ || move.target.findDirectExpression(Expressions.InlineData) === undefined
80092
+ || !(variable.identifier.getType() instanceof basic_1.CharacterType)
80093
+ || variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
80094
+ || !procedure.dominates(declaration, read.statement)) {
80095
+ return;
80096
+ }
80097
+ const value = (0, _procedure_analysis_1.characterConstant)(procedure, move.source);
80098
+ const result = value === undefined ? undefined : this.evaluate(procedure, read, value);
80099
+ if (result === undefined) {
80100
+ return;
80101
+ }
80102
+ const structure = procedure.ifStructure(read.statement);
80103
+ const fold = structure === undefined ? undefined : (0, _procedure_analysis_1.foldIf)(procedure, structure, read.statement, result);
80104
+ if (structure === undefined || fold === undefined) {
80105
+ return;
80106
+ }
80107
+ candidates.push({
80108
+ structure,
80109
+ statement: read.statement,
80110
+ message: "Condition is always " + (result ? "true" : "false") + ", " + variable.identifier.getName() + " is constant",
80111
+ fix: (0, _procedure_analysis_1.mergeEdits)(procedure.file, [fold, (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)]),
80112
+ });
80113
+ }
80114
+ /** DATA v TYPE ... never changed: IF v IS INITIAL / IS BOUND */
80115
+ initialVariable(procedure, variable, candidates) {
80116
+ if (!(0, _procedure_analysis_1.plainData)(variable.declaration) || variable.escapes()
80117
+ || variable.writes().some(w => { var _a; return ((_a = (0, _procedure_analysis_1.plainClear)(w.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(w.token.getStart())) !== true; })) {
80118
+ return;
80119
+ }
80120
+ for (const read of variable.reads()) {
80121
+ const predicate = (0, _procedure_analysis_1.simplePredicate)(read.statement);
80122
+ if (predicate === undefined || !this.isOperand(predicate.left, read)
80123
+ || (predicate.kind !== _procedure_analysis_1.PredicateKind.Initial && predicate.kind !== _procedure_analysis_1.PredicateKind.Bound)) {
80124
+ continue;
80125
+ }
80126
+ // initial: IS INITIAL is true, IS BOUND is false
80127
+ const result = (predicate.kind === _procedure_analysis_1.PredicateKind.Initial) !== predicate.negated;
80128
+ const structure = procedure.ifStructure(read.statement);
80129
+ const fix = structure === undefined ? undefined : (0, _procedure_analysis_1.foldIf)(procedure, structure, read.statement, result);
80130
+ if (structure === undefined || fix === undefined) {
80131
+ continue;
80132
+ }
80133
+ candidates.push({
80134
+ structure,
80135
+ statement: read.statement,
80136
+ message: "Condition is always " + (result ? "true" : "false") + ", " + variable.identifier.getName() + " is never changed",
80137
+ fix,
80138
+ });
80139
+ }
80140
+ }
80141
+ evaluate(procedure, read, value) {
80142
+ const predicate = (0, _procedure_analysis_1.simplePredicate)(read.statement);
80143
+ if (predicate === undefined) {
80144
+ return undefined;
80145
+ }
80146
+ if (predicate.kind === _procedure_analysis_1.PredicateKind.Initial && this.isOperand(predicate.left, read)) {
80147
+ return (0, _procedure_analysis_1.sameCharacters)(value, "") !== predicate.negated;
80148
+ }
80149
+ else if (predicate.kind === _procedure_analysis_1.PredicateKind.Equal) {
80150
+ let other = predicate.right;
80151
+ if (!this.isOperand(predicate.left, read)) {
80152
+ if (!this.isOperand(predicate.right, read)) {
80153
+ return undefined;
80154
+ }
80155
+ other = predicate.left;
80156
+ }
80157
+ const compared = (0, _procedure_analysis_1.characterConstant)(procedure, other);
80158
+ if (compared === undefined) {
80159
+ return undefined;
80160
+ }
80161
+ return (0, _procedure_analysis_1.sameCharacters)(value, compared) !== predicate.negated;
80162
+ }
80163
+ return undefined;
80164
+ }
80165
+ isOperand(source, read) {
80166
+ return source.countTokens() === 1 && source.findDirectExpression(Expressions.FieldChain) !== undefined
80167
+ && source.getFirstToken().getStart().equals(read.token.getStart());
80168
+ }
80169
+ }
80170
+ exports.ConstantCondition = ConstantCondition;
80171
+ //# sourceMappingURL=constant_condition.js.map
80172
+
80173
+ /***/ },
80174
+
78048
80175
  /***/ "../core/build/src/rules/constructor_visibility_public.js"
78049
80176
  /*!****************************************************************!*\
78050
80177
  !*** ../core/build/src/rules/constructor_visibility_public.js ***!
@@ -78205,6 +80332,323 @@ exports.ContainsTab = ContainsTab;
78205
80332
 
78206
80333
  /***/ },
78207
80334
 
80335
+ /***/ "../core/build/src/rules/copy_chain.js"
80336
+ /*!*********************************************!*\
80337
+ !*** ../core/build/src/rules/copy_chain.js ***!
80338
+ \*********************************************/
80339
+ (__unused_webpack_module, exports, __webpack_require__) {
80340
+
80341
+ "use strict";
80342
+
80343
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
80344
+ if (k2 === undefined) k2 = k;
80345
+ var desc = Object.getOwnPropertyDescriptor(m, k);
80346
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
80347
+ desc = { enumerable: true, get: function() { return m[k]; } };
80348
+ }
80349
+ Object.defineProperty(o, k2, desc);
80350
+ }) : (function(o, m, k, k2) {
80351
+ if (k2 === undefined) k2 = k;
80352
+ o[k2] = m[k];
80353
+ }));
80354
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
80355
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
80356
+ }) : function(o, v) {
80357
+ o["default"] = v;
80358
+ });
80359
+ var __importStar = (this && this.__importStar) || (function () {
80360
+ var ownKeys = function(o) {
80361
+ ownKeys = Object.getOwnPropertyNames || function (o) {
80362
+ var ar = [];
80363
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
80364
+ return ar;
80365
+ };
80366
+ return ownKeys(o);
80367
+ };
80368
+ return function (mod) {
80369
+ if (mod && mod.__esModule) return mod;
80370
+ var result = {};
80371
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
80372
+ __setModuleDefault(result, mod);
80373
+ return result;
80374
+ };
80375
+ })();
80376
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
80377
+ exports.CopyChain = exports.CopyChainConf = void 0;
80378
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
80379
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
80380
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
80381
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
80382
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
80383
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
80384
+ class CopyChainConf extends _basic_rule_config_1.BasicRuleConfig {
80385
+ }
80386
+ exports.CopyChainConf = CopyChainConf;
80387
+ class CopyChain {
80388
+ constructor() {
80389
+ this.conf = new CopyChainConf();
80390
+ }
80391
+ getMetadata() {
80392
+ return {
80393
+ key: "copy_chain",
80394
+ title: "Copy chain",
80395
+ shortDescription: `Finds a local variable that only passes a value on from one variable to another`,
80396
+ extendedInformation: `Reports DATA v TYPE ... [CLEAR v.] v = src. ... y = v. when all of the following hold:
80397
+
80398
+ * v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE
80399
+ * v has exactly one write besides CLEAR: v = src., and all CLEARs are before it
80400
+ * v has exactly one read, the complete source of y = v.
80401
+ * src is a local variable, its address is never taken, and it is not written from v = src. until y = v.
80402
+ * v = src. is executed before y = v. on every path: y = v. is in the same block or a nested block,
80403
+ and both are in the same loop
80404
+ * v and src are both reference types, or have identical types; for other types the copy into v can convert,
80405
+ e.g. truncate a string into a c field. For DATA(y) = v. the types must be identical, else y changes its type
80406
+ * the declaration, the CLEARs and v = src. are not chained
80407
+
80408
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
80409
+ INCLUDE, test seams, enhancements or native SQL.
80410
+
80411
+ The quick fix deletes the declaration, the CLEARs and v = src., and changes the read to y = src.
80412
+ No release requirement.`,
80413
+ tags: [_irule_1.RuleTag.Quickfix],
80414
+ badExample: `DATA lo_copy TYPE REF TO zcl_node.
80415
+ lo_copy = lo_node.
80416
+ ro_result = lo_copy.`,
80417
+ goodExample: `ro_result = lo_node.`,
80418
+ };
80419
+ }
80420
+ getConfig() {
80421
+ return this.conf;
80422
+ }
80423
+ setConfig(conf) {
80424
+ this.conf = conf;
80425
+ }
80426
+ initialize(reg) {
80427
+ this.reg = reg;
80428
+ return this;
80429
+ }
80430
+ run(obj) {
80431
+ var _a, _b, _c;
80432
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
80433
+ if (analysis === undefined) {
80434
+ return [];
80435
+ }
80436
+ const issues = [];
80437
+ for (const procedure of analysis.procedures) {
80438
+ if (procedure.supported === false) {
80439
+ continue;
80440
+ }
80441
+ for (const variable of procedure.locals()) {
80442
+ const declaration = variable.declaration;
80443
+ if (variable.inline || !(0, _procedure_analysis_1.plainData)(declaration) || declaration.getColon() !== undefined
80444
+ || variable.escapes()) {
80445
+ continue;
80446
+ }
80447
+ const clears = [];
80448
+ const writes = [];
80449
+ for (const write of variable.writes()) {
80450
+ if (((_a = (0, _procedure_analysis_1.plainClear)(write.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(write.token.getStart())) === true
80451
+ && write.statement.getColon() === undefined) {
80452
+ clears.push(write);
80453
+ }
80454
+ else {
80455
+ writes.push(write);
80456
+ }
80457
+ }
80458
+ const reads = variable.reads();
80459
+ if (writes.length !== 1 || reads.length !== 1) {
80460
+ continue;
80461
+ }
80462
+ const write = writes[0];
80463
+ const read = reads[0];
80464
+ const assign = (0, _procedure_analysis_1.plainMove)(write.statement);
80465
+ const use = (0, _procedure_analysis_1.plainMove)(read.statement);
80466
+ if (assign === undefined || use === undefined || assign.operator !== "=" || use.operator !== "="
80467
+ || ((_b = (0, _procedure_analysis_1.singleTarget)(assign.target)) === null || _b === void 0 ? void 0 : _b.getStart().equals(write.token.getStart())) !== true
80468
+ || ((_c = (0, _procedure_analysis_1.singleField)(use.source)) === null || _c === void 0 ? void 0 : _c.getStart().equals(read.token.getStart())) !== true
80469
+ || clears.some(c => c.index > write.index)
80470
+ || !procedure.dominates(write.statement, read.statement)
80471
+ || !procedure.sameLoop(write.statement, read.statement)) {
80472
+ continue;
80473
+ }
80474
+ const source = (0, _procedure_analysis_1.dataSource)(procedure, assign.source);
80475
+ if (source === undefined || source.kind !== _procedure_analysis_1.SourceKind.Local || source.base === variable
80476
+ || (0, _procedure_analysis_1.singleField)(assign.source) === undefined
80477
+ || !(0, _procedure_analysis_1.unchangedBetween)(procedure, source, write.statement, read.statement)) {
80478
+ continue;
80479
+ }
80480
+ // an inline declaration DATA(y) = v. would get the type of src instead of the type of v
80481
+ const type = variable.identifier.getType();
80482
+ const inline = use.target.findFirstExpression(Expressions.InlineData) !== undefined;
80483
+ if (!(0, _procedure_analysis_1.identicalTypes)(type, source.type) && (inline || !(0, _procedure_analysis_1.isReferenceType)(type) || !(0, _procedure_analysis_1.isReferenceType)(source.type))) {
80484
+ continue;
80485
+ }
80486
+ const edits = [
80487
+ (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration),
80488
+ (0, _procedure_analysis_1.deleteStatement)(procedure.file, write.statement),
80489
+ edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, source.text)
80490
+ ];
80491
+ for (const clear of clears) {
80492
+ edits.push((0, _procedure_analysis_1.deleteStatement)(procedure.file, clear.statement));
80493
+ }
80494
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
80495
+ const message = "Copy chain via " + variable.identifier.getName() + ", assign " + source.text + " directly";
80496
+ issues.push(issue_1.Issue.atStatement(procedure.file, read.statement, message, this.getMetadata().key, this.conf.severity, fix));
80497
+ }
80498
+ }
80499
+ return issues;
80500
+ }
80501
+ }
80502
+ exports.CopyChain = CopyChain;
80503
+ //# sourceMappingURL=copy_chain.js.map
80504
+
80505
+ /***/ },
80506
+
80507
+ /***/ "../core/build/src/rules/copy_of_initial_variable.js"
80508
+ /*!***********************************************************!*\
80509
+ !*** ../core/build/src/rules/copy_of_initial_variable.js ***!
80510
+ \***********************************************************/
80511
+ (__unused_webpack_module, exports, __webpack_require__) {
80512
+
80513
+ "use strict";
80514
+
80515
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
80516
+ if (k2 === undefined) k2 = k;
80517
+ var desc = Object.getOwnPropertyDescriptor(m, k);
80518
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
80519
+ desc = { enumerable: true, get: function() { return m[k]; } };
80520
+ }
80521
+ Object.defineProperty(o, k2, desc);
80522
+ }) : (function(o, m, k, k2) {
80523
+ if (k2 === undefined) k2 = k;
80524
+ o[k2] = m[k];
80525
+ }));
80526
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
80527
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
80528
+ }) : function(o, v) {
80529
+ o["default"] = v;
80530
+ });
80531
+ var __importStar = (this && this.__importStar) || (function () {
80532
+ var ownKeys = function(o) {
80533
+ ownKeys = Object.getOwnPropertyNames || function (o) {
80534
+ var ar = [];
80535
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
80536
+ return ar;
80537
+ };
80538
+ return ownKeys(o);
80539
+ };
80540
+ return function (mod) {
80541
+ if (mod && mod.__esModule) return mod;
80542
+ var result = {};
80543
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
80544
+ __setModuleDefault(result, mod);
80545
+ return result;
80546
+ };
80547
+ })();
80548
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
80549
+ exports.CopyOfInitialVariable = exports.CopyOfInitialVariableConf = void 0;
80550
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
80551
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
80552
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
80553
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
80554
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
80555
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
80556
+ class CopyOfInitialVariableConf extends _basic_rule_config_1.BasicRuleConfig {
80557
+ }
80558
+ exports.CopyOfInitialVariableConf = CopyOfInitialVariableConf;
80559
+ class CopyOfInitialVariable {
80560
+ constructor() {
80561
+ this.conf = new CopyOfInitialVariableConf();
80562
+ }
80563
+ getMetadata() {
80564
+ return {
80565
+ key: "copy_of_initial_variable",
80566
+ title: "Copy of initial variable",
80567
+ shortDescription: `Finds assignments from a local variable that is always initial`,
80568
+ extendedInformation: `Reports DATA v TYPE ... [CLEAR v.] x = v. when all of the following hold:
80569
+
80570
+ * v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE
80571
+ * v is never changed, except by CLEAR v., and its address is never taken
80572
+ * v has exactly one read, the complete source of x = v., where x is not an inline declaration
80573
+ * x and v are both reference types, or have identical types. Initial values convert differently between
80574
+ types, e.g. an initial d becomes '00000000' in a string
80575
+ * the declaration and the CLEARs are not chained
80576
+
80577
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
80578
+ INCLUDE, test seams, enhancements or native SQL.
80579
+
80580
+ The quick fix deletes the declaration and the CLEARs, and replaces x = v. with CLEAR x.
80581
+ No release requirement.`,
80582
+ tags: [_irule_1.RuleTag.Quickfix],
80583
+ badExample: `DATA lo_empty TYPE REF TO zcl_node.
80584
+ ro_result = lo_empty.`,
80585
+ goodExample: `CLEAR ro_result.`,
80586
+ };
80587
+ }
80588
+ getConfig() {
80589
+ return this.conf;
80590
+ }
80591
+ setConfig(conf) {
80592
+ this.conf = conf;
80593
+ }
80594
+ initialize(reg) {
80595
+ this.reg = reg;
80596
+ return this;
80597
+ }
80598
+ run(obj) {
80599
+ var _a;
80600
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
80601
+ if (analysis === undefined) {
80602
+ return [];
80603
+ }
80604
+ const issues = [];
80605
+ for (const procedure of analysis.procedures) {
80606
+ if (procedure.supported === false) {
80607
+ continue;
80608
+ }
80609
+ for (const variable of procedure.locals()) {
80610
+ const declaration = variable.declaration;
80611
+ const reads = variable.reads();
80612
+ const writes = variable.writes();
80613
+ if (variable.inline || !(0, _procedure_analysis_1.plainData)(declaration) || declaration.getColon() !== undefined
80614
+ || variable.escapes() || reads.length !== 1
80615
+ || writes.some(w => { var _a; return ((_a = (0, _procedure_analysis_1.plainClear)(w.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(w.token.getStart())) !== true
80616
+ || w.statement.getColon() !== undefined; })) {
80617
+ continue;
80618
+ }
80619
+ const read = reads[0];
80620
+ const move = (0, _procedure_analysis_1.plainMove)(read.statement);
80621
+ if (move === undefined || move.operator !== "="
80622
+ || ((_a = (0, _procedure_analysis_1.singleField)(move.source)) === null || _a === void 0 ? void 0 : _a.getStart().equals(read.token.getStart())) !== true
80623
+ || move.target.findFirstExpression(Expressions.InlineData) !== undefined) {
80624
+ continue;
80625
+ }
80626
+ const type = variable.identifier.getType();
80627
+ const target = (0, _procedure_analysis_1.targetType)(procedure, move.target);
80628
+ if (target === undefined
80629
+ || (!((0, _procedure_analysis_1.isReferenceType)(type) && (0, _procedure_analysis_1.isReferenceType)(target)) && !(0, _procedure_analysis_1.identicalTypes)(type, target))) {
80630
+ continue;
80631
+ }
80632
+ const edits = [
80633
+ (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration),
80634
+ edit_helper_1.EditHelper.replaceRange(procedure.file, read.statement.getStart(), read.statement.getEnd(), "CLEAR " + (0, _procedure_analysis_1.nodeText)(procedure.file, move.target) + ".")
80635
+ ];
80636
+ for (const write of writes) {
80637
+ edits.push((0, _procedure_analysis_1.deleteStatement)(procedure.file, write.statement));
80638
+ }
80639
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
80640
+ const message = variable.identifier.getName() + " is always initial, use CLEAR";
80641
+ issues.push(issue_1.Issue.atStatement(procedure.file, read.statement, message, this.getMetadata().key, this.conf.severity, fix));
80642
+ }
80643
+ }
80644
+ return issues;
80645
+ }
80646
+ }
80647
+ exports.CopyOfInitialVariable = CopyOfInitialVariable;
80648
+ //# sourceMappingURL=copy_of_initial_variable.js.map
80649
+
80650
+ /***/ },
80651
+
78208
80652
  /***/ "../core/build/src/rules/cyclic_oo.js"
78209
80653
  /*!********************************************!*\
78210
80654
  !*** ../core/build/src/rules/cyclic_oo.js ***!
@@ -87172,6 +89616,7 @@ __exportStar(__webpack_require__(/*! ./abapdoc_leading_at */ "../core/build/src/
87172
89616
  __exportStar(__webpack_require__(/*! ./abapdoc_parameter_names */ "../core/build/src/rules/abapdoc_parameter_names.js"), exports);
87173
89617
  __exportStar(__webpack_require__(/*! ./add_test_attributes */ "../core/build/src/rules/add_test_attributes.js"), exports);
87174
89618
  __exportStar(__webpack_require__(/*! ./aff_and_xml */ "../core/build/src/rules/aff_and_xml.js"), exports);
89619
+ __exportStar(__webpack_require__(/*! ./alias_never_reassigned */ "../core/build/src/rules/alias_never_reassigned.js"), exports);
87175
89620
  __exportStar(__webpack_require__(/*! ./align_parameters */ "../core/build/src/rules/align_parameters.js"), exports);
87176
89621
  __exportStar(__webpack_require__(/*! ./align_pseudo_comments */ "../core/build/src/rules/align_pseudo_comments.js"), exports);
87177
89622
  __exportStar(__webpack_require__(/*! ./align_type_expressions */ "../core/build/src/rules/align_type_expressions.js"), exports);
@@ -87181,6 +89626,8 @@ __exportStar(__webpack_require__(/*! ./ambiguous_statement */ "../core/build/src
87181
89626
  __exportStar(__webpack_require__(/*! ./avoid_use */ "../core/build/src/rules/avoid_use.js"), exports);
87182
89627
  __exportStar(__webpack_require__(/*! ./begin_end_names */ "../core/build/src/rules/begin_end_names.js"), exports);
87183
89628
  __exportStar(__webpack_require__(/*! ./begin_single_include */ "../core/build/src/rules/begin_single_include.js"), exports);
89629
+ __exportStar(__webpack_require__(/*! ./boolean_flag_via_if */ "../core/build/src/rules/boolean_flag_via_if.js"), exports);
89630
+ __exportStar(__webpack_require__(/*! ./bound_check_after_create */ "../core/build/src/rules/bound_check_after_create.js"), exports);
87184
89631
  __exportStar(__webpack_require__(/*! ./call_transaction_authority_check */ "../core/build/src/rules/call_transaction_authority_check.js"), exports);
87185
89632
  __exportStar(__webpack_require__(/*! ./catch_and_raise */ "../core/build/src/rules/catch_and_raise.js"), exports);
87186
89633
  __exportStar(__webpack_require__(/*! ./cds_association_name */ "../core/build/src/rules/cds_association_name.js"), exports);
@@ -87201,6 +89648,7 @@ __exportStar(__webpack_require__(/*! ./check_subrc */ "../core/build/src/rules/c
87201
89648
  __exportStar(__webpack_require__(/*! ./check_syntax */ "../core/build/src/rules/check_syntax.js"), exports);
87202
89649
  __exportStar(__webpack_require__(/*! ./check_text_elements */ "../core/build/src/rules/check_text_elements.js"), exports);
87203
89650
  __exportStar(__webpack_require__(/*! ./check_transformation_exists */ "../core/build/src/rules/check_transformation_exists.js"), exports);
89651
+ __exportStar(__webpack_require__(/*! ./clear_after_declaration */ "../core/build/src/rules/clear_after_declaration.js"), exports);
87204
89652
  __exportStar(__webpack_require__(/*! ./clear_exporting_parameters */ "../core/build/src/rules/clear_exporting_parameters.js"), exports);
87205
89653
  __exportStar(__webpack_require__(/*! ./class_attribute_names */ "../core/build/src/rules/class_attribute_names.js"), exports);
87206
89654
  __exportStar(__webpack_require__(/*! ./classic_exceptions_overlap */ "../core/build/src/rules/classic_exceptions_overlap.js"), exports);
@@ -87208,8 +89656,11 @@ __exportStar(__webpack_require__(/*! ./cloud_types */ "../core/build/src/rules/c
87208
89656
  __exportStar(__webpack_require__(/*! ./colon_missing_space */ "../core/build/src/rules/colon_missing_space.js"), exports);
87209
89657
  __exportStar(__webpack_require__(/*! ./commented_code */ "../core/build/src/rules/commented_code.js"), exports);
87210
89658
  __exportStar(__webpack_require__(/*! ./constant_classes */ "../core/build/src/rules/constant_classes.js"), exports);
89659
+ __exportStar(__webpack_require__(/*! ./constant_condition */ "../core/build/src/rules/constant_condition.js"), exports);
87211
89660
  __exportStar(__webpack_require__(/*! ./constructor_visibility_public */ "../core/build/src/rules/constructor_visibility_public.js"), exports);
87212
89661
  __exportStar(__webpack_require__(/*! ./contains_tab */ "../core/build/src/rules/contains_tab.js"), exports);
89662
+ __exportStar(__webpack_require__(/*! ./copy_chain */ "../core/build/src/rules/copy_chain.js"), exports);
89663
+ __exportStar(__webpack_require__(/*! ./copy_of_initial_variable */ "../core/build/src/rules/copy_of_initial_variable.js"), exports);
87213
89664
  __exportStar(__webpack_require__(/*! ./cyclic_oo */ "../core/build/src/rules/cyclic_oo.js"), exports);
87214
89665
  __exportStar(__webpack_require__(/*! ./cyclomatic_complexity */ "../core/build/src/rules/cyclomatic_complexity.js"), exports);
87215
89666
  __exportStar(__webpack_require__(/*! ./dangerous_statement */ "../core/build/src/rules/dangerous_statement.js"), exports);
@@ -87335,6 +89786,7 @@ __exportStar(__webpack_require__(/*! ./selection_screen_texts_missing */ "../cor
87335
89786
  __exportStar(__webpack_require__(/*! ./sequential_blank */ "../core/build/src/rules/sequential_blank.js"), exports);
87336
89787
  __exportStar(__webpack_require__(/*! ./short_case */ "../core/build/src/rules/short_case.js"), exports);
87337
89788
  __exportStar(__webpack_require__(/*! ./sicf_consistency */ "../core/build/src/rules/sicf_consistency.js"), exports);
89789
+ __exportStar(__webpack_require__(/*! ./single_use_expression_temp */ "../core/build/src/rules/single_use_expression_temp.js"), exports);
87338
89790
  __exportStar(__webpack_require__(/*! ./slow_parameter_passing */ "../core/build/src/rules/slow_parameter_passing.js"), exports);
87339
89791
  __exportStar(__webpack_require__(/*! ./smim_consistency */ "../core/build/src/rules/smim_consistency.js"), exports);
87340
89792
  __exportStar(__webpack_require__(/*! ./sort_empty_key */ "../core/build/src/rules/sort_empty_key.js"), exports);
@@ -87352,12 +89804,14 @@ __exportStar(__webpack_require__(/*! ./sy_modification */ "../core/build/src/rul
87352
89804
  __exportStar(__webpack_require__(/*! ./sy_read_restriction */ "../core/build/src/rules/sy_read_restriction.js"), exports);
87353
89805
  __exportStar(__webpack_require__(/*! ./tabl_enhancement_category */ "../core/build/src/rules/tabl_enhancement_category.js"), exports);
87354
89806
  __exportStar(__webpack_require__(/*! ./tables_declared_locally */ "../core/build/src/rules/tables_declared_locally.js"), exports);
89807
+ __exportStar(__webpack_require__(/*! ./try_cast_empty_catch */ "../core/build/src/rules/try_cast_empty_catch.js"), exports);
87355
89808
  __exportStar(__webpack_require__(/*! ./try_without_catch */ "../core/build/src/rules/try_without_catch.js"), exports);
87356
89809
  __exportStar(__webpack_require__(/*! ./type_form_parameters */ "../core/build/src/rules/type_form_parameters.js"), exports);
87357
89810
  __exportStar(__webpack_require__(/*! ./types_naming */ "../core/build/src/rules/types_naming.js"), exports);
87358
89811
  __exportStar(__webpack_require__(/*! ./uncaught_exception */ "../core/build/src/rules/uncaught_exception.js"), exports);
87359
89812
  __exportStar(__webpack_require__(/*! ./unknown_types */ "../core/build/src/rules/unknown_types.js"), exports);
87360
89813
  __exportStar(__webpack_require__(/*! ./unnecessary_chaining */ "../core/build/src/rules/unnecessary_chaining.js"), exports);
89814
+ __exportStar(__webpack_require__(/*! ./unnecessary_copy */ "../core/build/src/rules/unnecessary_copy.js"), exports);
87361
89815
  __exportStar(__webpack_require__(/*! ./unnecessary_loop_guard */ "../core/build/src/rules/unnecessary_loop_guard.js"), exports);
87362
89816
  __exportStar(__webpack_require__(/*! ./unnecessary_pragma */ "../core/build/src/rules/unnecessary_pragma.js"), exports);
87363
89817
  __exportStar(__webpack_require__(/*! ./unnecessary_return */ "../core/build/src/rules/unnecessary_return.js"), exports);
@@ -100064,6 +102518,218 @@ exports.SICFConsistency = SICFConsistency;
100064
102518
 
100065
102519
  /***/ },
100066
102520
 
102521
+ /***/ "../core/build/src/rules/single_use_expression_temp.js"
102522
+ /*!*************************************************************!*\
102523
+ !*** ../core/build/src/rules/single_use_expression_temp.js ***!
102524
+ \*************************************************************/
102525
+ (__unused_webpack_module, exports, __webpack_require__) {
102526
+
102527
+ "use strict";
102528
+
102529
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
102530
+ if (k2 === undefined) k2 = k;
102531
+ var desc = Object.getOwnPropertyDescriptor(m, k);
102532
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
102533
+ desc = { enumerable: true, get: function() { return m[k]; } };
102534
+ }
102535
+ Object.defineProperty(o, k2, desc);
102536
+ }) : (function(o, m, k, k2) {
102537
+ if (k2 === undefined) k2 = k;
102538
+ o[k2] = m[k];
102539
+ }));
102540
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
102541
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
102542
+ }) : function(o, v) {
102543
+ o["default"] = v;
102544
+ });
102545
+ var __importStar = (this && this.__importStar) || (function () {
102546
+ var ownKeys = function(o) {
102547
+ ownKeys = Object.getOwnPropertyNames || function (o) {
102548
+ var ar = [];
102549
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
102550
+ return ar;
102551
+ };
102552
+ return ownKeys(o);
102553
+ };
102554
+ return function (mod) {
102555
+ if (mod && mod.__esModule) return mod;
102556
+ var result = {};
102557
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
102558
+ __setModuleDefault(result, mod);
102559
+ return result;
102560
+ };
102561
+ })();
102562
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
102563
+ exports.SingleUseExpressionTemp = exports.SingleUseExpressionTempConf = void 0;
102564
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
102565
+ const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
102566
+ const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
102567
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
102568
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
102569
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
102570
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
102571
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
102572
+ class SingleUseExpressionTempConf extends _basic_rule_config_1.BasicRuleConfig {
102573
+ }
102574
+ exports.SingleUseExpressionTempConf = SingleUseExpressionTempConf;
102575
+ /** builtin functions whose result type follows the type of the argument */
102576
+ const NUMERIC_FUNCTIONS = new Set(["abs", "sign", "ceil", "floor", "trunc", "frac", "ipow", "nmax", "nmin",
102577
+ "round", "rescale"]);
102578
+ /** constructor expressions that can build the result directly in the target */
102579
+ const IN_PLACE = new Set(["VALUE", "CORRESPONDING", "COND", "SWITCH", "REDUCE", "FILTER"]);
102580
+ class SingleUseExpressionTemp {
102581
+ constructor() {
102582
+ this.conf = new SingleUseExpressionTempConf();
102583
+ }
102584
+ getMetadata() {
102585
+ return {
102586
+ key: "single_use_expression_temp",
102587
+ title: "Single use expression temporary",
102588
+ shortDescription: `Finds DATA(a) = <expression>. directly followed by x = a., assign the expression to x`,
102589
+ extendedInformation: `Reports DATA(a) = <expression>. when all of the following hold:
102590
+
102591
+ * a is a local variable of a METHOD, FORM or FUNCTION, with no other reference than the next statement,
102592
+ which is x = a., in the same block
102593
+ * the result type of the expression does not depend on the target: no arithmetic or bit operators, no unary
102594
+ minus, no numeric functions like abs( ) or trunc( ) whose type follows the argument, no CONV or EXACT,
102595
+ no # type inference at the top. String templates, && concatenations, literals, method calls, NEW, CAST,
102596
+ constructor expressions with explicit type and table expressions are fine
102597
+ * VALUE, CORRESPONDING, COND, SWITCH, REDUCE and FILTER can build their result directly in the target,
102598
+ they are only inlined into a new variable, or a local variable that they do not read and whose address
102599
+ is never taken
102600
+ * plain data objects are left for unnecessary_copy
102601
+
102602
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
102603
+ INCLUDE, test seams, enhancements or native SQL.
102604
+
102605
+ The quick fix deletes the declaration and writes x = <expression>. No release requirement.`,
102606
+ tags: [_irule_1.RuleTag.Quickfix],
102607
+ badExample: `DATA(lo_conf) = NEW zcl_conf( ).
102608
+ mo_conf = lo_conf.`,
102609
+ goodExample: `mo_conf = NEW zcl_conf( ).`,
102610
+ };
102611
+ }
102612
+ getConfig() {
102613
+ return this.conf;
102614
+ }
102615
+ setConfig(conf) {
102616
+ this.conf = conf;
102617
+ }
102618
+ initialize(reg) {
102619
+ this.reg = reg;
102620
+ return this;
102621
+ }
102622
+ run(obj) {
102623
+ var _a;
102624
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
102625
+ if (analysis === undefined) {
102626
+ return [];
102627
+ }
102628
+ const issues = [];
102629
+ for (const procedure of analysis.procedures) {
102630
+ if (procedure.supported === false) {
102631
+ continue;
102632
+ }
102633
+ for (const variable of procedure.locals()) {
102634
+ const declaration = variable.declaration;
102635
+ const move = variable.inline ? (0, _procedure_analysis_1.plainMove)(declaration) : undefined;
102636
+ const read = variable.occurrences[0];
102637
+ if (move === undefined || move.operator !== "="
102638
+ || move.target.getChildren().length !== 1
102639
+ || move.target.findDirectExpression(Expressions.InlineData) === undefined
102640
+ || variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
102641
+ || read.statement !== procedure.statements[procedure.index(declaration) + 1]
102642
+ || procedure.block(read.statement) !== procedure.block(declaration)
102643
+ || !procedure.isSimple(read.statement)) {
102644
+ continue;
102645
+ }
102646
+ const use = (0, _procedure_analysis_1.plainMove)(read.statement);
102647
+ if (use === undefined || use.operator !== "="
102648
+ || ((_a = (0, _procedure_analysis_1.singleField)(use.source)) === null || _a === void 0 ? void 0 : _a.getStart().equals(read.token.getStart())) !== true
102649
+ || (0, _procedure_analysis_1.dataSource)(procedure, move.source) !== undefined
102650
+ || !this.targetIndependent(procedure, move.source)
102651
+ || !this.noAliasing(procedure, move.source, use.target)) {
102652
+ continue;
102653
+ }
102654
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
102655
+ edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, (0, _procedure_analysis_1.nodeText)(procedure.file, move.source)),
102656
+ (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)
102657
+ ]);
102658
+ const message = "Assign the expression directly instead of via " + variable.identifier.getName();
102659
+ issues.push(issue_1.Issue.atStatement(procedure.file, declaration, message, this.getMetadata().key, this.conf.severity, fix));
102660
+ }
102661
+ }
102662
+ return issues;
102663
+ }
102664
+ /** the type of the expression does not depend on where it is assigned to */
102665
+ targetIndependent(procedure, source) {
102666
+ var _a, _b;
102667
+ const first = source.getFirstToken().getStr().toUpperCase();
102668
+ if (first === "CONV" || first === "EXACT"
102669
+ || ((_a = source.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _a === void 0 ? void 0 : _a.concatTokens()) === "#"
102670
+ || source.findFirstExpression(Expressions.ArithOperator) !== undefined
102671
+ || source.getTokens().some(t => t.getStr().toUpperCase().startsWith("BIT-"))
102672
+ || !this.concatenationOnly(source)) {
102673
+ return false;
102674
+ }
102675
+ for (const call of source.findAllExpressionsRecursive(Expressions.MethodCall)) {
102676
+ const name = (_b = call.findDirectExpression(Expressions.MethodName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
102677
+ if (name === undefined) {
102678
+ return false;
102679
+ }
102680
+ const builtin = procedure.analysis.referencesAt(procedure.file.getFilename(), name)
102681
+ .some(r => r.referenceType === _reference_1.ReferenceType.BuiltinMethodReference);
102682
+ if (builtin && NUMERIC_FUNCTIONS.has(name.getStr().toLowerCase())) {
102683
+ return false;
102684
+ }
102685
+ }
102686
+ return true;
102687
+ }
102688
+ /** one operand, or operands joined by && */
102689
+ concatenationOnly(source) {
102690
+ const children = source.getChildren();
102691
+ if (children.length === 1) {
102692
+ return true;
102693
+ }
102694
+ if (children.length === 3 && children[1] instanceof nodes_1.TokenNode && children[1].getFirstToken().getStr() === "&&"
102695
+ && children[0] instanceof nodes_1.ExpressionNode && children[2] instanceof nodes_1.ExpressionNode
102696
+ && children[2].get() instanceof Expressions.Source) {
102697
+ return !(children[0].get() instanceof Expressions.Source) && this.concatenationOnly(children[2]);
102698
+ }
102699
+ const first = children[0] instanceof nodes_1.TokenNode ? children[0].getFirstToken().getStr().toUpperCase() : "";
102700
+ if ((first === "XSDBOOL" || first === "BOOLC") && source.findDirectExpression(Expressions.Cond) !== undefined) {
102701
+ return true;
102702
+ }
102703
+ // constructor expressions: KEYWORD type( ... )
102704
+ return first !== "" && first !== "-"
102705
+ && children[1] instanceof nodes_1.ExpressionNode && children[1].get() instanceof Expressions.TypeNameOrInfer;
102706
+ }
102707
+ /** constructor expressions that build their result directly in the target are only inlined into a new
102708
+ * variable, or into a local variable which the expression does not read and which nothing else can reach */
102709
+ noAliasing(procedure, source, target) {
102710
+ if (!IN_PLACE.has(source.getFirstToken().getStr().toUpperCase())
102711
+ || target.findDirectExpression(Expressions.InlineData) !== undefined) {
102712
+ return true;
102713
+ }
102714
+ const field = target.getChildren()[0];
102715
+ const local = target.getChildren().length === 1 && field instanceof nodes_1.ExpressionNode
102716
+ && field.get() instanceof Expressions.TargetField
102717
+ ? procedure.local(procedure.identifierAt(field.getFirstToken())) : undefined;
102718
+ if (local === undefined || local.escapes()) {
102719
+ return false;
102720
+ }
102721
+ const key = _procedure_analysis_1.ObjectAnalysis.key(local.identifier);
102722
+ return source.getTokens().every(t => {
102723
+ const identifier = procedure.identifierAt(t);
102724
+ return identifier === undefined || _procedure_analysis_1.ObjectAnalysis.key(identifier) !== key;
102725
+ });
102726
+ }
102727
+ }
102728
+ exports.SingleUseExpressionTemp = SingleUseExpressionTemp;
102729
+ //# sourceMappingURL=single_use_expression_temp.js.map
102730
+
102731
+ /***/ },
102732
+
100067
102733
  /***/ "../core/build/src/rules/slow_parameter_passing.js"
100068
102734
  /*!*********************************************************!*\
100069
102735
  !*** ../core/build/src/rules/slow_parameter_passing.js ***!
@@ -102138,6 +104804,175 @@ exports.TablesDeclaredLocally = TablesDeclaredLocally;
102138
104804
 
102139
104805
  /***/ },
102140
104806
 
104807
+ /***/ "../core/build/src/rules/try_cast_empty_catch.js"
104808
+ /*!*******************************************************!*\
104809
+ !*** ../core/build/src/rules/try_cast_empty_catch.js ***!
104810
+ \*******************************************************/
104811
+ (__unused_webpack_module, exports, __webpack_require__) {
104812
+
104813
+ "use strict";
104814
+
104815
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
104816
+ if (k2 === undefined) k2 = k;
104817
+ var desc = Object.getOwnPropertyDescriptor(m, k);
104818
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
104819
+ desc = { enumerable: true, get: function() { return m[k]; } };
104820
+ }
104821
+ Object.defineProperty(o, k2, desc);
104822
+ }) : (function(o, m, k, k2) {
104823
+ if (k2 === undefined) k2 = k;
104824
+ o[k2] = m[k];
104825
+ }));
104826
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
104827
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
104828
+ }) : function(o, v) {
104829
+ o["default"] = v;
104830
+ });
104831
+ var __importStar = (this && this.__importStar) || (function () {
104832
+ var ownKeys = function(o) {
104833
+ ownKeys = Object.getOwnPropertyNames || function (o) {
104834
+ var ar = [];
104835
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
104836
+ return ar;
104837
+ };
104838
+ return ownKeys(o);
104839
+ };
104840
+ return function (mod) {
104841
+ if (mod && mod.__esModule) return mod;
104842
+ var result = {};
104843
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
104844
+ __setModuleDefault(result, mod);
104845
+ return result;
104846
+ };
104847
+ })();
104848
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
104849
+ exports.TryCastEmptyCatch = exports.TryCastEmptyCatchConf = void 0;
104850
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
104851
+ const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
104852
+ const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
104853
+ const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
104854
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
104855
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
104856
+ const version_1 = __webpack_require__(/*! ../version */ "../core/build/src/version.js");
104857
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
104858
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
104859
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
104860
+ class TryCastEmptyCatchConf extends _basic_rule_config_1.BasicRuleConfig {
104861
+ }
104862
+ exports.TryCastEmptyCatchConf = TryCastEmptyCatchConf;
104863
+ class TryCastEmptyCatch {
104864
+ constructor() {
104865
+ this.conf = new TryCastEmptyCatchConf();
104866
+ }
104867
+ getMetadata() {
104868
+ return {
104869
+ key: "try_cast_empty_catch",
104870
+ title: "TRY around cast with empty CATCH",
104871
+ shortDescription: `Finds a down cast in TRY with an empty CATCH cx_sy_move_cast_error, use IS INSTANCE OF`,
104872
+ extendedInformation: `Reports TRY. a ?= b. CATCH cx_sy_move_cast_error. ENDTRY. when all of the following hold:
104873
+
104874
+ * the cast is the only statement of the TRY block, there is exactly one CATCH, for cx_sy_move_cast_error only,
104875
+ without INTO or BEFORE UNWIND, its block is empty, and there is no CLEANUP
104876
+ * the static type of a is a class or interface, not a generic REF TO object
104877
+ * b is a plain data object: variable, attribute or a chain of components and attributes, without calls,
104878
+ so evaluating it again has no side effects
104879
+
104880
+ a ?= b. also succeeds when b is initial, and then clears a, while b IS INSTANCE OF is false for an initial b,
104881
+ so the quick fix replaces the TRY with IF b IS INSTANCE OF <type of a> OR b IS INITIAL. a ?= b. ENDIF.
104882
+
104883
+ Requires IS INSTANCE OF, ie. 7.50 or above, ABAP Cloud or open-abap.
104884
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
104885
+ INCLUDE, test seams, enhancements or native SQL.`,
104886
+ tags: [_irule_1.RuleTag.Quickfix],
104887
+ badExample: `TRY.
104888
+ lo_node ?= io_object.
104889
+ CATCH cx_sy_move_cast_error.
104890
+ ENDTRY.`,
104891
+ goodExample: `IF io_object IS INSTANCE OF zcl_node OR io_object IS INITIAL.
104892
+ lo_node ?= io_object.
104893
+ ENDIF.`,
104894
+ };
104895
+ }
104896
+ getConfig() {
104897
+ return this.conf;
104898
+ }
104899
+ setConfig(conf) {
104900
+ this.conf = conf;
104901
+ }
104902
+ initialize(reg) {
104903
+ this.reg = reg;
104904
+ return this;
104905
+ }
104906
+ run(obj) {
104907
+ const config = this.reg.getConfig();
104908
+ if (!(0, version_1.releaseAtLeast)(config.getRelease(), version_1.Release.v750)
104909
+ && config.getLanguageVersion() !== version_1.LanguageVersion.Cloud
104910
+ && !config.isOpenABAP()) {
104911
+ return [];
104912
+ }
104913
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
104914
+ if (analysis === undefined) {
104915
+ return [];
104916
+ }
104917
+ const issues = [];
104918
+ for (const procedure of analysis.procedures) {
104919
+ if (procedure.supported === false) {
104920
+ continue;
104921
+ }
104922
+ for (const structure of procedure.structure.findAllStructuresRecursive(Structures.Try)) {
104923
+ this.check(procedure, structure, issues);
104924
+ }
104925
+ }
104926
+ return issues;
104927
+ }
104928
+ check(procedure, structure, issues) {
104929
+ const children = structure.getChildren();
104930
+ const tryStatement = children[0];
104931
+ const body = children[1];
104932
+ const catchStructure = children[2];
104933
+ const endTry = children[3];
104934
+ if (children.length !== 4
104935
+ || !(tryStatement instanceof nodes_1.StatementNode) || tryStatement.getColon() !== undefined
104936
+ || !(body instanceof nodes_1.StructureNode) || !(body.get() instanceof Structures.Body)
104937
+ || !(catchStructure instanceof nodes_1.StructureNode) || !(catchStructure.get() instanceof Structures.Catch)
104938
+ || !(endTry instanceof nodes_1.StatementNode) || !(endTry.get() instanceof Statements.EndTry)
104939
+ || endTry.getColon() !== undefined) {
104940
+ return;
104941
+ }
104942
+ const statements = body.findAllStatementNodes();
104943
+ const catchStatements = catchStructure.findAllStatementNodes();
104944
+ const catchStatement = catchStatements[0];
104945
+ const tokens = catchStatement === null || catchStatement === void 0 ? void 0 : catchStatement.getTokens().map(t => t.getStr().toUpperCase());
104946
+ if (statements.length !== 1 || catchStatements.length !== 1 || catchStatement.getColon() !== undefined
104947
+ || (tokens === null || tokens === void 0 ? void 0 : tokens.join(" ")) !== "CATCH CX_SY_MOVE_CAST_ERROR .") {
104948
+ return;
104949
+ }
104950
+ const cast = statements[0];
104951
+ const move = (0, _procedure_analysis_1.plainMove)(cast);
104952
+ const target = move === undefined ? undefined : (0, _procedure_analysis_1.targetType)(procedure, move.target);
104953
+ const source = move === undefined ? undefined : (0, _procedure_analysis_1.dataSource)(procedure, move.source);
104954
+ if (move === undefined || move.operator !== "?=" || source === undefined
104955
+ || !(target instanceof basic_1.ObjectReferenceType)
104956
+ || target.getIdentifierName().toUpperCase() === "OBJECT"
104957
+ || procedure.hasComment(tryStatement.getStart(), endTry.getEnd())) {
104958
+ return;
104959
+ }
104960
+ const condition = "IF " + source.text + " IS INSTANCE OF " + target.getIdentifierName()
104961
+ + " OR " + source.text + " IS INITIAL.";
104962
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
104963
+ edit_helper_1.EditHelper.replaceRange(procedure.file, tryStatement.getStart(), tryStatement.getEnd(), condition),
104964
+ (0, _procedure_analysis_1.deleteStatement)(procedure.file, catchStatement),
104965
+ edit_helper_1.EditHelper.replaceToken(procedure.file, endTry.getFirstToken(), "ENDIF")
104966
+ ]);
104967
+ const message = "Check with IS INSTANCE OF instead of catching cx_sy_move_cast_error";
104968
+ issues.push(issue_1.Issue.atStatement(procedure.file, tryStatement, message, this.getMetadata().key, this.conf.severity, fix));
104969
+ }
104970
+ }
104971
+ exports.TryCastEmptyCatch = TryCastEmptyCatch;
104972
+ //# sourceMappingURL=try_cast_empty_catch.js.map
104973
+
104974
+ /***/ },
104975
+
102141
104976
  /***/ "../core/build/src/rules/try_without_catch.js"
102142
104977
  /*!****************************************************!*\
102143
104978
  !*** ../core/build/src/rules/try_without_catch.js ***!
@@ -103048,6 +105883,149 @@ exports.UnnecessaryChaining = UnnecessaryChaining;
103048
105883
 
103049
105884
  /***/ },
103050
105885
 
105886
+ /***/ "../core/build/src/rules/unnecessary_copy.js"
105887
+ /*!***************************************************!*\
105888
+ !*** ../core/build/src/rules/unnecessary_copy.js ***!
105889
+ \***************************************************/
105890
+ (__unused_webpack_module, exports, __webpack_require__) {
105891
+
105892
+ "use strict";
105893
+
105894
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
105895
+ if (k2 === undefined) k2 = k;
105896
+ var desc = Object.getOwnPropertyDescriptor(m, k);
105897
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
105898
+ desc = { enumerable: true, get: function() { return m[k]; } };
105899
+ }
105900
+ Object.defineProperty(o, k2, desc);
105901
+ }) : (function(o, m, k, k2) {
105902
+ if (k2 === undefined) k2 = k;
105903
+ o[k2] = m[k];
105904
+ }));
105905
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
105906
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
105907
+ }) : function(o, v) {
105908
+ o["default"] = v;
105909
+ });
105910
+ var __importStar = (this && this.__importStar) || (function () {
105911
+ var ownKeys = function(o) {
105912
+ ownKeys = Object.getOwnPropertyNames || function (o) {
105913
+ var ar = [];
105914
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
105915
+ return ar;
105916
+ };
105917
+ return ownKeys(o);
105918
+ };
105919
+ return function (mod) {
105920
+ if (mod && mod.__esModule) return mod;
105921
+ var result = {};
105922
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
105923
+ __setModuleDefault(result, mod);
105924
+ return result;
105925
+ };
105926
+ })();
105927
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
105928
+ exports.UnnecessaryCopy = exports.UnnecessaryCopyConf = void 0;
105929
+ const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
105930
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
105931
+ const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
105932
+ const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
105933
+ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
105934
+ const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
105935
+ class UnnecessaryCopyConf extends _basic_rule_config_1.BasicRuleConfig {
105936
+ }
105937
+ exports.UnnecessaryCopyConf = UnnecessaryCopyConf;
105938
+ class UnnecessaryCopy {
105939
+ constructor() {
105940
+ this.conf = new UnnecessaryCopyConf();
105941
+ }
105942
+ getMetadata() {
105943
+ return {
105944
+ key: "unnecessary_copy",
105945
+ title: "Unnecessary copy",
105946
+ shortDescription: `Finds DATA(a) = b. where a is read exactly once, and b can be read instead`,
105947
+ extendedInformation: `Reports DATA(a) = b. when all of the following hold:
105948
+
105949
+ * a is a local variable of a METHOD, FORM or FUNCTION, and has exactly one more reference: a read,
105950
+ which does not take its address, bind a field symbol to it, or pass it to USING, CHANGING or EXPORTING
105951
+ * b is a plain data object: variable, constant, attribute, or a chain of components and attributes,
105952
+ without calls, offsets, table expressions, field symbols or ->*
105953
+ * the declaration is executed before the read on every path: the read is in the block of the declaration
105954
+ or a nested block, and both are in the same loop
105955
+ * b keeps its value from the declaration until the read: for a local b, no write to it and its address is
105956
+ never taken; for other b, in addition no method, function or form call and no write except to local
105957
+ variables, by value parameters and RETURNING in between
105958
+
105959
+ a has the type of b, so reading b instead does not change any conversion.
105960
+ A constant b read in IF, ELSEIF, WHILE, CHECK, CASE or WHEN is not reported, see constant_condition.
105961
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
105962
+ INCLUDE, test seams, enhancements or native SQL.
105963
+
105964
+ The quick fix deletes the declaration and replaces the read of a with b. No release requirement,
105965
+ inline declarations need 7.40 SP02 already.
105966
+
105967
+ See also alias_never_reassigned for copies that are read several times.`,
105968
+ tags: [_irule_1.RuleTag.Quickfix],
105969
+ badExample: `DATA(lv_name) = iv_name.
105970
+ rv_text = |Hello { lv_name }|.`,
105971
+ goodExample: `rv_text = |Hello { iv_name }|.`,
105972
+ };
105973
+ }
105974
+ getConfig() {
105975
+ return this.conf;
105976
+ }
105977
+ setConfig(conf) {
105978
+ this.conf = conf;
105979
+ }
105980
+ initialize(reg) {
105981
+ this.reg = reg;
105982
+ return this;
105983
+ }
105984
+ run(obj) {
105985
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
105986
+ if (analysis === undefined) {
105987
+ return [];
105988
+ }
105989
+ const issues = [];
105990
+ for (const procedure of analysis.procedures) {
105991
+ if (procedure.supported === false) {
105992
+ continue;
105993
+ }
105994
+ for (const variable of procedure.locals()) {
105995
+ const declaration = variable.declaration;
105996
+ const move = variable.inline ? (0, _procedure_analysis_1.plainMove)(declaration) : undefined;
105997
+ const read = variable.occurrences[0];
105998
+ if (move === undefined || move.operator !== "="
105999
+ || move.target.getChildren().length !== 1
106000
+ || move.target.findDirectExpression(Expressions.InlineData) === undefined
106001
+ || variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
106002
+ || variable.identifier.getType().isGeneric()
106003
+ || !procedure.dominates(declaration, read.statement)
106004
+ || !procedure.sameLoop(declaration, read.statement)) {
106005
+ continue;
106006
+ }
106007
+ const source = (0, _procedure_analysis_1.dataSource)(procedure, move.source);
106008
+ if (source === undefined || source.base === variable
106009
+ || (source.kind === _procedure_analysis_1.SourceKind.Immutable && (0, _procedure_analysis_1.isCondition)(read.statement))
106010
+ || !(0, _procedure_analysis_1.unchangedBetween)(procedure, source, declaration, read.statement, read.token)) {
106011
+ continue;
106012
+ }
106013
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
106014
+ edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, source.text),
106015
+ (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)
106016
+ ]);
106017
+ const message = "Unnecessary copy " + variable.identifier.getName() + ", read " + source.text + " instead";
106018
+ issues.push(issue_1.Issue.atStatement(procedure.file, declaration, message, this.getMetadata().key, this.conf.severity, fix));
106019
+ }
106020
+ }
106021
+ return issues;
106022
+ }
106023
+ }
106024
+ exports.UnnecessaryCopy = UnnecessaryCopy;
106025
+ //# sourceMappingURL=unnecessary_copy.js.map
106026
+
106027
+ /***/ },
106028
+
103051
106029
  /***/ "../core/build/src/rules/unnecessary_loop_guard.js"
103052
106030
  /*!*********************************************************!*\
103053
106031
  !*** ../core/build/src/rules/unnecessary_loop_guard.js ***!