@abaplint/core 2.120.80 → 2.120.82

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.
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SingleUseExpressionTemp = exports.SingleUseExpressionTempConf = void 0;
37
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
38
+ const nodes_1 = require("../abap/nodes");
39
+ const _reference_1 = require("../abap/5_syntax/_reference");
40
+ const edit_helper_1 = require("../edit_helper");
41
+ const issue_1 = require("../issue");
42
+ const _basic_rule_config_1 = require("./_basic_rule_config");
43
+ const _irule_1 = require("./_irule");
44
+ const _procedure_analysis_1 = require("./_procedure_analysis");
45
+ class SingleUseExpressionTempConf extends _basic_rule_config_1.BasicRuleConfig {
46
+ }
47
+ exports.SingleUseExpressionTempConf = SingleUseExpressionTempConf;
48
+ /** builtin functions whose result type follows the type of the argument */
49
+ const NUMERIC_FUNCTIONS = new Set(["abs", "sign", "ceil", "floor", "trunc", "frac", "ipow", "nmax", "nmin",
50
+ "round", "rescale"]);
51
+ /** constructor expressions that can build the result directly in the target */
52
+ const IN_PLACE = new Set(["VALUE", "CORRESPONDING", "COND", "SWITCH", "REDUCE", "FILTER"]);
53
+ class SingleUseExpressionTemp {
54
+ constructor() {
55
+ this.conf = new SingleUseExpressionTempConf();
56
+ }
57
+ getMetadata() {
58
+ return {
59
+ key: "single_use_expression_temp",
60
+ title: "Single use expression temporary",
61
+ shortDescription: `Finds DATA(a) = <expression>. directly followed by x = a., assign the expression to x`,
62
+ extendedInformation: `Reports DATA(a) = <expression>. when all of the following hold:
63
+
64
+ * a is a local variable of a METHOD, FORM or FUNCTION, with no other reference than the next statement,
65
+ which is x = a., in the same block
66
+ * the result type of the expression does not depend on the target: no arithmetic or bit operators, no unary
67
+ minus, no numeric functions like abs( ) or trunc( ) whose type follows the argument, no CONV or EXACT,
68
+ no # type inference at the top. String templates, && concatenations, literals, method calls, NEW, CAST,
69
+ constructor expressions with explicit type and table expressions are fine
70
+ * VALUE, CORRESPONDING, COND, SWITCH, REDUCE and FILTER can build their result directly in the target,
71
+ they are only inlined into a new variable, or a local variable that they do not read and whose address
72
+ is never taken
73
+ * plain data objects are left for unnecessary_copy
74
+
75
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
76
+ INCLUDE, test seams, enhancements or native SQL.
77
+
78
+ The quick fix deletes the declaration and writes x = <expression>. No release requirement.`,
79
+ tags: [_irule_1.RuleTag.Quickfix],
80
+ badExample: `DATA(lo_conf) = NEW zcl_conf( ).
81
+ mo_conf = lo_conf.`,
82
+ goodExample: `mo_conf = NEW zcl_conf( ).`,
83
+ };
84
+ }
85
+ getConfig() {
86
+ return this.conf;
87
+ }
88
+ setConfig(conf) {
89
+ this.conf = conf;
90
+ }
91
+ initialize(reg) {
92
+ this.reg = reg;
93
+ return this;
94
+ }
95
+ run(obj) {
96
+ var _a;
97
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
98
+ if (analysis === undefined) {
99
+ return [];
100
+ }
101
+ const issues = [];
102
+ for (const procedure of analysis.procedures) {
103
+ if (procedure.supported === false) {
104
+ continue;
105
+ }
106
+ for (const variable of procedure.locals()) {
107
+ const declaration = variable.declaration;
108
+ const move = variable.inline ? (0, _procedure_analysis_1.plainMove)(declaration) : undefined;
109
+ const read = variable.occurrences[0];
110
+ if (move === undefined || move.operator !== "="
111
+ || move.target.getChildren().length !== 1
112
+ || move.target.findDirectExpression(Expressions.InlineData) === undefined
113
+ || variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
114
+ || read.statement !== procedure.statements[procedure.index(declaration) + 1]
115
+ || procedure.block(read.statement) !== procedure.block(declaration)
116
+ || !procedure.isSimple(read.statement)) {
117
+ continue;
118
+ }
119
+ const use = (0, _procedure_analysis_1.plainMove)(read.statement);
120
+ if (use === undefined || use.operator !== "="
121
+ || ((_a = (0, _procedure_analysis_1.singleField)(use.source)) === null || _a === void 0 ? void 0 : _a.getStart().equals(read.token.getStart())) !== true
122
+ || (0, _procedure_analysis_1.dataSource)(procedure, move.source) !== undefined
123
+ || !this.targetIndependent(procedure, move.source)
124
+ || !this.noAliasing(procedure, move.source, use.target)) {
125
+ continue;
126
+ }
127
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
128
+ edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, (0, _procedure_analysis_1.nodeText)(procedure.file, move.source)),
129
+ (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)
130
+ ]);
131
+ const message = "Assign the expression directly instead of via " + variable.identifier.getName();
132
+ issues.push(issue_1.Issue.atStatement(procedure.file, declaration, message, this.getMetadata().key, this.conf.severity, fix));
133
+ }
134
+ }
135
+ return issues;
136
+ }
137
+ /** the type of the expression does not depend on where it is assigned to */
138
+ targetIndependent(procedure, source) {
139
+ var _a, _b;
140
+ const first = source.getFirstToken().getStr().toUpperCase();
141
+ if (first === "CONV" || first === "EXACT"
142
+ || ((_a = source.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _a === void 0 ? void 0 : _a.concatTokens()) === "#"
143
+ || source.findFirstExpression(Expressions.ArithOperator) !== undefined
144
+ || source.getTokens().some(t => t.getStr().toUpperCase().startsWith("BIT-"))
145
+ || !this.concatenationOnly(source)) {
146
+ return false;
147
+ }
148
+ for (const call of source.findAllExpressionsRecursive(Expressions.MethodCall)) {
149
+ const name = (_b = call.findDirectExpression(Expressions.MethodName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
150
+ if (name === undefined) {
151
+ return false;
152
+ }
153
+ const builtin = procedure.analysis.referencesAt(procedure.file.getFilename(), name)
154
+ .some(r => r.referenceType === _reference_1.ReferenceType.BuiltinMethodReference);
155
+ if (builtin && NUMERIC_FUNCTIONS.has(name.getStr().toLowerCase())) {
156
+ return false;
157
+ }
158
+ }
159
+ return true;
160
+ }
161
+ /** one operand, or operands joined by && */
162
+ concatenationOnly(source) {
163
+ const children = source.getChildren();
164
+ if (children.length === 1) {
165
+ return true;
166
+ }
167
+ if (children.length === 3 && children[1] instanceof nodes_1.TokenNode && children[1].getFirstToken().getStr() === "&&"
168
+ && children[0] instanceof nodes_1.ExpressionNode && children[2] instanceof nodes_1.ExpressionNode
169
+ && children[2].get() instanceof Expressions.Source) {
170
+ return !(children[0].get() instanceof Expressions.Source) && this.concatenationOnly(children[2]);
171
+ }
172
+ const first = children[0] instanceof nodes_1.TokenNode ? children[0].getFirstToken().getStr().toUpperCase() : "";
173
+ if ((first === "XSDBOOL" || first === "BOOLC") && source.findDirectExpression(Expressions.Cond) !== undefined) {
174
+ return true;
175
+ }
176
+ // constructor expressions: KEYWORD type( ... )
177
+ return first !== "" && first !== "-"
178
+ && children[1] instanceof nodes_1.ExpressionNode && children[1].get() instanceof Expressions.TypeNameOrInfer;
179
+ }
180
+ /** constructor expressions that build their result directly in the target are only inlined into a new
181
+ * variable, or into a local variable which the expression does not read and which nothing else can reach */
182
+ noAliasing(procedure, source, target) {
183
+ if (!IN_PLACE.has(source.getFirstToken().getStr().toUpperCase())
184
+ || target.findDirectExpression(Expressions.InlineData) !== undefined) {
185
+ return true;
186
+ }
187
+ const field = target.getChildren()[0];
188
+ const local = target.getChildren().length === 1 && field instanceof nodes_1.ExpressionNode
189
+ && field.get() instanceof Expressions.TargetField
190
+ ? procedure.local(procedure.identifierAt(field.getFirstToken())) : undefined;
191
+ if (local === undefined || local.escapes()) {
192
+ return false;
193
+ }
194
+ const key = _procedure_analysis_1.ObjectAnalysis.key(local.identifier);
195
+ return source.getTokens().every(t => {
196
+ const identifier = procedure.identifierAt(t);
197
+ return identifier === undefined || _procedure_analysis_1.ObjectAnalysis.key(identifier) !== key;
198
+ });
199
+ }
200
+ }
201
+ exports.SingleUseExpressionTemp = SingleUseExpressionTemp;
202
+ //# sourceMappingURL=single_use_expression_temp.js.map
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TryCastEmptyCatch = exports.TryCastEmptyCatchConf = void 0;
37
+ const Statements = __importStar(require("../abap/2_statements/statements"));
38
+ const Structures = __importStar(require("../abap/3_structures/structures"));
39
+ const nodes_1 = require("../abap/nodes");
40
+ const basic_1 = require("../abap/types/basic");
41
+ const edit_helper_1 = require("../edit_helper");
42
+ const issue_1 = require("../issue");
43
+ const version_1 = require("../version");
44
+ const _basic_rule_config_1 = require("./_basic_rule_config");
45
+ const _irule_1 = require("./_irule");
46
+ const _procedure_analysis_1 = require("./_procedure_analysis");
47
+ class TryCastEmptyCatchConf extends _basic_rule_config_1.BasicRuleConfig {
48
+ }
49
+ exports.TryCastEmptyCatchConf = TryCastEmptyCatchConf;
50
+ class TryCastEmptyCatch {
51
+ constructor() {
52
+ this.conf = new TryCastEmptyCatchConf();
53
+ }
54
+ getMetadata() {
55
+ return {
56
+ key: "try_cast_empty_catch",
57
+ title: "TRY around cast with empty CATCH",
58
+ shortDescription: `Finds a down cast in TRY with an empty CATCH cx_sy_move_cast_error, use IS INSTANCE OF`,
59
+ extendedInformation: `Reports TRY. a ?= b. CATCH cx_sy_move_cast_error. ENDTRY. when all of the following hold:
60
+
61
+ * the cast is the only statement of the TRY block, there is exactly one CATCH, for cx_sy_move_cast_error only,
62
+ without INTO or BEFORE UNWIND, its block is empty, and there is no CLEANUP
63
+ * the static type of a is a class or interface, not a generic REF TO object
64
+ * b is a plain data object: variable, attribute or a chain of components and attributes, without calls,
65
+ so evaluating it again has no side effects
66
+
67
+ a ?= b. also succeeds when b is initial, and then clears a, while b IS INSTANCE OF is false for an initial b,
68
+ so the quick fix replaces the TRY with IF b IS INSTANCE OF <type of a> OR b IS INITIAL. a ?= b. ENDIF.
69
+
70
+ Requires IS INSTANCE OF, ie. 7.50 or above, ABAP Cloud or open-abap.
71
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
72
+ INCLUDE, test seams, enhancements or native SQL.`,
73
+ tags: [_irule_1.RuleTag.Quickfix],
74
+ badExample: `TRY.
75
+ lo_node ?= io_object.
76
+ CATCH cx_sy_move_cast_error.
77
+ ENDTRY.`,
78
+ goodExample: `IF io_object IS INSTANCE OF zcl_node OR io_object IS INITIAL.
79
+ lo_node ?= io_object.
80
+ ENDIF.`,
81
+ };
82
+ }
83
+ getConfig() {
84
+ return this.conf;
85
+ }
86
+ setConfig(conf) {
87
+ this.conf = conf;
88
+ }
89
+ initialize(reg) {
90
+ this.reg = reg;
91
+ return this;
92
+ }
93
+ run(obj) {
94
+ const config = this.reg.getConfig();
95
+ if (!(0, version_1.releaseAtLeast)(config.getRelease(), version_1.Release.v750)
96
+ && config.getLanguageVersion() !== version_1.LanguageVersion.Cloud
97
+ && !config.isOpenABAP()) {
98
+ return [];
99
+ }
100
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
101
+ if (analysis === undefined) {
102
+ return [];
103
+ }
104
+ const issues = [];
105
+ for (const procedure of analysis.procedures) {
106
+ if (procedure.supported === false) {
107
+ continue;
108
+ }
109
+ for (const structure of procedure.structure.findAllStructuresRecursive(Structures.Try)) {
110
+ this.check(procedure, structure, issues);
111
+ }
112
+ }
113
+ return issues;
114
+ }
115
+ check(procedure, structure, issues) {
116
+ const children = structure.getChildren();
117
+ const tryStatement = children[0];
118
+ const body = children[1];
119
+ const catchStructure = children[2];
120
+ const endTry = children[3];
121
+ if (children.length !== 4
122
+ || !(tryStatement instanceof nodes_1.StatementNode) || tryStatement.getColon() !== undefined
123
+ || !(body instanceof nodes_1.StructureNode) || !(body.get() instanceof Structures.Body)
124
+ || !(catchStructure instanceof nodes_1.StructureNode) || !(catchStructure.get() instanceof Structures.Catch)
125
+ || !(endTry instanceof nodes_1.StatementNode) || !(endTry.get() instanceof Statements.EndTry)
126
+ || endTry.getColon() !== undefined) {
127
+ return;
128
+ }
129
+ const statements = body.findAllStatementNodes();
130
+ const catchStatements = catchStructure.findAllStatementNodes();
131
+ const catchStatement = catchStatements[0];
132
+ const tokens = catchStatement === null || catchStatement === void 0 ? void 0 : catchStatement.getTokens().map(t => t.getStr().toUpperCase());
133
+ if (statements.length !== 1 || catchStatements.length !== 1 || catchStatement.getColon() !== undefined
134
+ || (tokens === null || tokens === void 0 ? void 0 : tokens.join(" ")) !== "CATCH CX_SY_MOVE_CAST_ERROR .") {
135
+ return;
136
+ }
137
+ const cast = statements[0];
138
+ const move = (0, _procedure_analysis_1.plainMove)(cast);
139
+ const target = move === undefined ? undefined : (0, _procedure_analysis_1.targetType)(procedure, move.target);
140
+ const source = move === undefined ? undefined : (0, _procedure_analysis_1.dataSource)(procedure, move.source);
141
+ if (move === undefined || move.operator !== "?=" || source === undefined
142
+ || !(target instanceof basic_1.ObjectReferenceType)
143
+ || target.getIdentifierName().toUpperCase() === "OBJECT"
144
+ || procedure.hasComment(tryStatement.getStart(), endTry.getEnd())) {
145
+ return;
146
+ }
147
+ const condition = "IF " + source.text + " IS INSTANCE OF " + target.getIdentifierName()
148
+ + " OR " + source.text + " IS INITIAL.";
149
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
150
+ edit_helper_1.EditHelper.replaceRange(procedure.file, tryStatement.getStart(), tryStatement.getEnd(), condition),
151
+ (0, _procedure_analysis_1.deleteStatement)(procedure.file, catchStatement),
152
+ edit_helper_1.EditHelper.replaceToken(procedure.file, endTry.getFirstToken(), "ENDIF")
153
+ ]);
154
+ const message = "Check with IS INSTANCE OF instead of catching cx_sy_move_cast_error";
155
+ issues.push(issue_1.Issue.atStatement(procedure.file, tryStatement, message, this.getMetadata().key, this.conf.severity, fix));
156
+ }
157
+ }
158
+ exports.TryCastEmptyCatch = TryCastEmptyCatch;
159
+ //# sourceMappingURL=try_cast_empty_catch.js.map
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.UnnecessaryCopy = exports.UnnecessaryCopyConf = void 0;
37
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
38
+ const edit_helper_1 = require("../edit_helper");
39
+ const issue_1 = require("../issue");
40
+ const _basic_rule_config_1 = require("./_basic_rule_config");
41
+ const _irule_1 = require("./_irule");
42
+ const _procedure_analysis_1 = require("./_procedure_analysis");
43
+ class UnnecessaryCopyConf extends _basic_rule_config_1.BasicRuleConfig {
44
+ }
45
+ exports.UnnecessaryCopyConf = UnnecessaryCopyConf;
46
+ class UnnecessaryCopy {
47
+ constructor() {
48
+ this.conf = new UnnecessaryCopyConf();
49
+ }
50
+ getMetadata() {
51
+ return {
52
+ key: "unnecessary_copy",
53
+ title: "Unnecessary copy",
54
+ shortDescription: `Finds DATA(a) = b. where a is read exactly once, and b can be read instead`,
55
+ extendedInformation: `Reports DATA(a) = b. when all of the following hold:
56
+
57
+ * a is a local variable of a METHOD, FORM or FUNCTION, and has exactly one more reference: a read,
58
+ which does not take its address, bind a field symbol to it, or pass it to USING, CHANGING or EXPORTING
59
+ * b is a plain data object: variable, constant, attribute, or a chain of components and attributes,
60
+ without calls, offsets, table expressions, field symbols or ->*
61
+ * the declaration is executed before the read on every path: the read is in the block of the declaration
62
+ or a nested block, and both are in the same loop
63
+ * b keeps its value from the declaration until the read: for a local b, no write to it and its address is
64
+ never taken; for other b, in addition no method, function or form call and no write except to local
65
+ variables, by value parameters and RETURNING in between
66
+
67
+ a has the type of b, so reading b instead does not change any conversion.
68
+ A constant b read in IF, ELSEIF, WHILE, CHECK, CASE or WHEN is not reported, see constant_condition.
69
+ Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
70
+ INCLUDE, test seams, enhancements or native SQL.
71
+
72
+ The quick fix deletes the declaration and replaces the read of a with b. No release requirement,
73
+ inline declarations need 7.40 SP02 already.
74
+
75
+ See also alias_never_reassigned for copies that are read several times.`,
76
+ tags: [_irule_1.RuleTag.Quickfix],
77
+ badExample: `DATA(lv_name) = iv_name.
78
+ rv_text = |Hello { lv_name }|.`,
79
+ goodExample: `rv_text = |Hello { iv_name }|.`,
80
+ };
81
+ }
82
+ getConfig() {
83
+ return this.conf;
84
+ }
85
+ setConfig(conf) {
86
+ this.conf = conf;
87
+ }
88
+ initialize(reg) {
89
+ this.reg = reg;
90
+ return this;
91
+ }
92
+ run(obj) {
93
+ const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
94
+ if (analysis === undefined) {
95
+ return [];
96
+ }
97
+ const issues = [];
98
+ for (const procedure of analysis.procedures) {
99
+ if (procedure.supported === false) {
100
+ continue;
101
+ }
102
+ for (const variable of procedure.locals()) {
103
+ const declaration = variable.declaration;
104
+ const move = variable.inline ? (0, _procedure_analysis_1.plainMove)(declaration) : undefined;
105
+ const read = variable.occurrences[0];
106
+ if (move === undefined || move.operator !== "="
107
+ || move.target.getChildren().length !== 1
108
+ || move.target.findDirectExpression(Expressions.InlineData) === undefined
109
+ || variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
110
+ || variable.identifier.getType().isGeneric()
111
+ || !procedure.dominates(declaration, read.statement)
112
+ || !procedure.sameLoop(declaration, read.statement)) {
113
+ continue;
114
+ }
115
+ const source = (0, _procedure_analysis_1.dataSource)(procedure, move.source);
116
+ if (source === undefined || source.base === variable
117
+ || (source.kind === _procedure_analysis_1.SourceKind.Immutable && (0, _procedure_analysis_1.isCondition)(read.statement))
118
+ || !(0, _procedure_analysis_1.unchangedBetween)(procedure, source, declaration, read.statement, read.token)) {
119
+ continue;
120
+ }
121
+ const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
122
+ edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, source.text),
123
+ (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)
124
+ ]);
125
+ const message = "Unnecessary copy " + variable.identifier.getName() + ", read " + source.text + " instead";
126
+ issues.push(issue_1.Issue.atStatement(procedure.file, declaration, message, this.getMetadata().key, this.conf.severity, fix));
127
+ }
128
+ }
129
+ return issues;
130
+ }
131
+ }
132
+ exports.UnnecessaryCopy = UnnecessaryCopy;
133
+ //# sourceMappingURL=unnecessary_copy.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.80",
3
+ "version": "2.120.82",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",