@abaplint/cli 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.
- package/build/cli.js +3316 -307
- package/package.json +2 -2
package/build/cli.js
CHANGED
|
@@ -24712,6 +24712,7 @@ class ABAPFileInformationParser {
|
|
|
24712
24712
|
return results;
|
|
24713
24713
|
}
|
|
24714
24714
|
parseAttributes(node, visibility) {
|
|
24715
|
+
var _a;
|
|
24715
24716
|
if (node === undefined) {
|
|
24716
24717
|
return [];
|
|
24717
24718
|
}
|
|
@@ -24720,23 +24721,34 @@ class ABAPFileInformationParser {
|
|
|
24720
24721
|
return [];
|
|
24721
24722
|
}
|
|
24722
24723
|
const ret = [];
|
|
24723
|
-
|
|
24724
|
+
const data = contents.findDirectStatements(Statements.Data);
|
|
24725
|
+
for (const structure of contents.findDirectStructures(Structures.Data)) {
|
|
24726
|
+
const begin = structure.findDirectStatement(Statements.DataBegin);
|
|
24727
|
+
if (begin.findDirectExpression(Expressions.DefinitionName)) {
|
|
24728
|
+
data.push(begin);
|
|
24729
|
+
}
|
|
24730
|
+
}
|
|
24731
|
+
for (const d of data) {
|
|
24724
24732
|
const name = d.findFirstExpression(Expressions.DefinitionName).getFirstToken();
|
|
24725
24733
|
ret.push({
|
|
24726
24734
|
name: name.getStr(),
|
|
24727
24735
|
identifier: new _identifier_1.Identifier(name, this.filename),
|
|
24728
24736
|
level: _abap_file_information_1.AttributeLevel.Instance,
|
|
24729
|
-
readOnly:
|
|
24737
|
+
readOnly: this.isReadOnly(d),
|
|
24730
24738
|
visibility,
|
|
24731
24739
|
});
|
|
24732
24740
|
}
|
|
24733
|
-
|
|
24734
|
-
|
|
24741
|
+
const classData = contents.findDirectStatements(Statements.ClassData);
|
|
24742
|
+
for (const structure of contents.findDirectStructures(Structures.ClassData)) {
|
|
24743
|
+
classData.push(structure.findDirectStatement(Statements.ClassDataBegin));
|
|
24744
|
+
}
|
|
24745
|
+
for (const d of classData) {
|
|
24746
|
+
const name = ((_a = d.findFirstExpression(Expressions.DefinitionName)) !== null && _a !== void 0 ? _a : d.findDirectExpression(Expressions.NamespaceSimpleName)).getFirstToken();
|
|
24735
24747
|
ret.push({
|
|
24736
24748
|
name: name.getStr(),
|
|
24737
24749
|
identifier: new _identifier_1.Identifier(name, this.filename),
|
|
24738
24750
|
level: _abap_file_information_1.AttributeLevel.Static,
|
|
24739
|
-
readOnly:
|
|
24751
|
+
readOnly: this.isReadOnly(d),
|
|
24740
24752
|
visibility,
|
|
24741
24753
|
});
|
|
24742
24754
|
}
|
|
@@ -24752,6 +24764,12 @@ class ABAPFileInformationParser {
|
|
|
24752
24764
|
}
|
|
24753
24765
|
return ret;
|
|
24754
24766
|
}
|
|
24767
|
+
isReadOnly(statement) {
|
|
24768
|
+
const definition = statement.findDirectExpression(Expressions.DataDefinition);
|
|
24769
|
+
const nodes = definition ? [definition, ...definition.findAllExpressions(Expressions.TypeTableKey)] : [statement];
|
|
24770
|
+
// In these grammar nodes, a direct READ token only occurs in the READ-ONLY modifier.
|
|
24771
|
+
return nodes.some(node => node.findDirectTokenByText("READ") !== undefined);
|
|
24772
|
+
}
|
|
24755
24773
|
parseMethodDefinition(node, visibility) {
|
|
24756
24774
|
var _a;
|
|
24757
24775
|
if (node === undefined) {
|
|
@@ -27553,7 +27571,9 @@ class Procedural {
|
|
|
27553
27571
|
}
|
|
27554
27572
|
}
|
|
27555
27573
|
if (found === undefined) {
|
|
27556
|
-
|
|
27574
|
+
const lookup = ddic.lookup(param.type);
|
|
27575
|
+
this.addDDICUsing(lookup.object, nameToken, filename);
|
|
27576
|
+
found = lookup.type;
|
|
27557
27577
|
}
|
|
27558
27578
|
if (param.direction === types_1.FunctionModuleParameterDirection.tables) {
|
|
27559
27579
|
if (found instanceof basic_1.TableType) {
|
|
@@ -27565,10 +27585,12 @@ class Procedural {
|
|
|
27565
27585
|
}
|
|
27566
27586
|
if ((found instanceof basic_1.UnknownType || found instanceof basic_1.VoidType) && ((_a = param.type) === null || _a === void 0 ? void 0 : _a.includes("-"))) {
|
|
27567
27587
|
const [name, field] = param.type.split("-");
|
|
27568
|
-
const
|
|
27588
|
+
const lookup = ddic.lookupTableOrView(name);
|
|
27589
|
+
const f = lookup.type;
|
|
27569
27590
|
if (f && f instanceof basic_1.StructureType) {
|
|
27570
27591
|
const c = f.getComponentByName(field);
|
|
27571
27592
|
if (c) {
|
|
27593
|
+
this.addDDICUsing(lookup.object, nameToken, filename);
|
|
27572
27594
|
found = c;
|
|
27573
27595
|
}
|
|
27574
27596
|
}
|
|
@@ -27632,6 +27654,12 @@ class Procedural {
|
|
|
27632
27654
|
}
|
|
27633
27655
|
}
|
|
27634
27656
|
}
|
|
27657
|
+
addDDICUsing(object, token, filename) {
|
|
27658
|
+
if (object === undefined) {
|
|
27659
|
+
return;
|
|
27660
|
+
}
|
|
27661
|
+
this.scope.getDDICReferences().addUsing(this.scope.getParentObj(), { object, token, filename });
|
|
27662
|
+
}
|
|
27635
27663
|
functionModuleParameterMeta(param) {
|
|
27636
27664
|
const ret = [];
|
|
27637
27665
|
if (param.direction === types_1.FunctionModuleParameterDirection.importing) {
|
|
@@ -33521,7 +33549,7 @@ class MethodCallChain {
|
|
|
33521
33549
|
context = component_name_1.ComponentName.runSyntax(context, current, input);
|
|
33522
33550
|
}
|
|
33523
33551
|
else if (current instanceof nodes_1.ExpressionNode && current.get() instanceof Expressions.AttributeName) {
|
|
33524
|
-
context = attribute_name_1.AttributeName.runSyntax(context, current, input);
|
|
33552
|
+
context = attribute_name_1.AttributeName.runSyntax(context, current, input, _reference_1.ReferenceType.DataReadReference);
|
|
33525
33553
|
}
|
|
33526
33554
|
previous = current;
|
|
33527
33555
|
}
|
|
@@ -50563,22 +50591,35 @@ class AbstractNode {
|
|
|
50563
50591
|
}
|
|
50564
50592
|
addChild(n) {
|
|
50565
50593
|
if (this.children === EMPTY) {
|
|
50566
|
-
this.children =
|
|
50594
|
+
this.children = n;
|
|
50595
|
+
}
|
|
50596
|
+
else if (Array.isArray(this.children)) {
|
|
50597
|
+
this.children.push(n);
|
|
50598
|
+
}
|
|
50599
|
+
else {
|
|
50600
|
+
this.children = [this.children, n];
|
|
50567
50601
|
}
|
|
50568
|
-
this.children.push(n);
|
|
50569
50602
|
}
|
|
50570
50603
|
setChildren(children) {
|
|
50571
|
-
|
|
50572
|
-
|
|
50604
|
+
if (children.length === 1) {
|
|
50605
|
+
this.children = children[0];
|
|
50606
|
+
}
|
|
50607
|
+
else {
|
|
50608
|
+
// copy, input arrays are built via push() and carry over-allocated backing stores
|
|
50609
|
+
this.children = children.length === 0 ? EMPTY : children.slice();
|
|
50610
|
+
}
|
|
50573
50611
|
}
|
|
50574
50612
|
getChildren() {
|
|
50575
|
-
|
|
50613
|
+
const children = this.children;
|
|
50614
|
+
return Array.isArray(children) ? children : [children];
|
|
50576
50615
|
}
|
|
50577
50616
|
getFirstChild() {
|
|
50578
|
-
|
|
50617
|
+
const children = this.children;
|
|
50618
|
+
return Array.isArray(children) ? children[0] : children;
|
|
50579
50619
|
}
|
|
50580
50620
|
getLastChild() {
|
|
50581
|
-
|
|
50621
|
+
const children = this.children;
|
|
50622
|
+
return Array.isArray(children) ? children[children.length - 1] : children;
|
|
50582
50623
|
}
|
|
50583
50624
|
}
|
|
50584
50625
|
exports.AbstractNode = AbstractNode;
|
|
@@ -71509,7 +71550,7 @@ class Registry {
|
|
|
71509
71550
|
}
|
|
71510
71551
|
static abaplintVersion() {
|
|
71511
71552
|
// magic, see build script "version.js"
|
|
71512
|
-
return "2.120.
|
|
71553
|
+
return "2.120.82";
|
|
71513
71554
|
}
|
|
71514
71555
|
getDDICReferences() {
|
|
71515
71556
|
return this.ddicReferences;
|
|
@@ -72023,6 +72064,1220 @@ exports.NamingRuleConfig = NamingRuleConfig;
|
|
|
72023
72064
|
|
|
72024
72065
|
/***/ },
|
|
72025
72066
|
|
|
72067
|
+
/***/ "../core/build/src/rules/_procedure_analysis.js"
|
|
72068
|
+
/*!******************************************************!*\
|
|
72069
|
+
!*** ../core/build/src/rules/_procedure_analysis.js ***!
|
|
72070
|
+
\******************************************************/
|
|
72071
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
72072
|
+
|
|
72073
|
+
"use strict";
|
|
72074
|
+
|
|
72075
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
72076
|
+
if (k2 === undefined) k2 = k;
|
|
72077
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
72078
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
72079
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
72080
|
+
}
|
|
72081
|
+
Object.defineProperty(o, k2, desc);
|
|
72082
|
+
}) : (function(o, m, k, k2) {
|
|
72083
|
+
if (k2 === undefined) k2 = k;
|
|
72084
|
+
o[k2] = m[k];
|
|
72085
|
+
}));
|
|
72086
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
72087
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
72088
|
+
}) : function(o, v) {
|
|
72089
|
+
o["default"] = v;
|
|
72090
|
+
});
|
|
72091
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
72092
|
+
var ownKeys = function(o) {
|
|
72093
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
72094
|
+
var ar = [];
|
|
72095
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
72096
|
+
return ar;
|
|
72097
|
+
};
|
|
72098
|
+
return ownKeys(o);
|
|
72099
|
+
};
|
|
72100
|
+
return function (mod) {
|
|
72101
|
+
if (mod && mod.__esModule) return mod;
|
|
72102
|
+
var result = {};
|
|
72103
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
72104
|
+
__setModuleDefault(result, mod);
|
|
72105
|
+
return result;
|
|
72106
|
+
};
|
|
72107
|
+
})();
|
|
72108
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
72109
|
+
exports.SourceKind = exports.PredicateKind = exports.Procedure = exports.ObjectAnalysis = exports.Variable = exports.OccurrenceKind = void 0;
|
|
72110
|
+
exports.findStructures = findStructures;
|
|
72111
|
+
exports.expressionPath = expressionPath;
|
|
72112
|
+
exports.plainMove = plainMove;
|
|
72113
|
+
exports.singleField = singleField;
|
|
72114
|
+
exports.singleTarget = singleTarget;
|
|
72115
|
+
exports.plainClear = plainClear;
|
|
72116
|
+
exports.plainData = plainData;
|
|
72117
|
+
exports.isImmutable = isImmutable;
|
|
72118
|
+
exports.isReferenceType = isReferenceType;
|
|
72119
|
+
exports.identicalTypes = identicalTypes;
|
|
72120
|
+
exports.simplePredicate = simplePredicate;
|
|
72121
|
+
exports.characterConstant = characterConstant;
|
|
72122
|
+
exports.sameCharacters = sameCharacters;
|
|
72123
|
+
exports.isCondition = isCondition;
|
|
72124
|
+
exports.dataSource = dataSource;
|
|
72125
|
+
exports.targetType = targetType;
|
|
72126
|
+
exports.unchangedBetween = unchangedBetween;
|
|
72127
|
+
exports.mergeEdits = mergeEdits;
|
|
72128
|
+
exports.deleteRegion = deleteRegion;
|
|
72129
|
+
exports.deleteStatement = deleteStatement;
|
|
72130
|
+
exports.rawText = rawText;
|
|
72131
|
+
exports.nodeText = nodeText;
|
|
72132
|
+
exports.ifBranches = ifBranches;
|
|
72133
|
+
exports.selfContained = selfContained;
|
|
72134
|
+
exports.foldIf = foldIf;
|
|
72135
|
+
exports.foldIssues = foldIssues;
|
|
72136
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
72137
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
72138
|
+
const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
|
|
72139
|
+
const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "../core/build/src/abap/2_statements/statements/_statement.js");
|
|
72140
|
+
const tokens_1 = __webpack_require__(/*! ../abap/1_lexer/tokens */ "../core/build/src/abap/1_lexer/tokens/index.js");
|
|
72141
|
+
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
|
|
72142
|
+
const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/build/src/abap/5_syntax/syntax.js");
|
|
72143
|
+
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
|
|
72144
|
+
const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
|
|
72145
|
+
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
72146
|
+
const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "../core/build/src/objects/_abap_object.js");
|
|
72147
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
72148
|
+
const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
|
|
72149
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
72150
|
+
// Shared analysis for the rules that remove redundant code around local variables:
|
|
72151
|
+
// clear_after_declaration, unnecessary_copy, constant_condition, copy_chain, copy_of_initial_variable,
|
|
72152
|
+
// bound_check_after_create, boolean_flag_via_if, alias_never_reassigned, single_use_expression_temp
|
|
72153
|
+
// and try_cast_empty_catch.
|
|
72154
|
+
//
|
|
72155
|
+
// Everything is derived from the syntax tree and the resolved references of the syntax check,
|
|
72156
|
+
// statements are never matched as text.
|
|
72157
|
+
var OccurrenceKind;
|
|
72158
|
+
(function (OccurrenceKind) {
|
|
72159
|
+
/** the value is read, or only used to reach a referenced object (ref->attr, ref->*) */
|
|
72160
|
+
OccurrenceKind["Read"] = "read";
|
|
72161
|
+
/** the variable itself is changed */
|
|
72162
|
+
OccurrenceKind["Write"] = "write";
|
|
72163
|
+
/** address taken, field symbol binding, USING/TABLES, dynamic, type reference, or a statement
|
|
72164
|
+
* that is not known to only read its operands */
|
|
72165
|
+
OccurrenceKind["Escape"] = "escape";
|
|
72166
|
+
})(OccurrenceKind || (exports.OccurrenceKind = OccurrenceKind = {}));
|
|
72167
|
+
class Variable {
|
|
72168
|
+
constructor(identifier, declaration, inline, occurrences, complete) {
|
|
72169
|
+
this.identifier = identifier;
|
|
72170
|
+
this.declaration = declaration;
|
|
72171
|
+
this.inline = inline;
|
|
72172
|
+
this.occurrences = occurrences;
|
|
72173
|
+
this.complete = complete;
|
|
72174
|
+
}
|
|
72175
|
+
/** declared by DATA, or inline, in the procedure; not a parameter, attribute or STATICS */
|
|
72176
|
+
isLocal() {
|
|
72177
|
+
return this.declaration !== undefined;
|
|
72178
|
+
}
|
|
72179
|
+
reads() {
|
|
72180
|
+
return this.occurrences.filter(o => o.kind === OccurrenceKind.Read);
|
|
72181
|
+
}
|
|
72182
|
+
writes() {
|
|
72183
|
+
return this.occurrences.filter(o => o.kind === OccurrenceKind.Write);
|
|
72184
|
+
}
|
|
72185
|
+
escapes() {
|
|
72186
|
+
return this.occurrences.some(o => o.kind === OccurrenceKind.Escape);
|
|
72187
|
+
}
|
|
72188
|
+
}
|
|
72189
|
+
exports.Variable = Variable;
|
|
72190
|
+
/** References of one object, after a successful syntax check */
|
|
72191
|
+
class ObjectAnalysis {
|
|
72192
|
+
/** returns undefined if the object is not supported, or has syntax errors */
|
|
72193
|
+
static run(reg, obj) {
|
|
72194
|
+
var _a;
|
|
72195
|
+
if (!(obj instanceof _abap_object_1.ABAPObject)) {
|
|
72196
|
+
return undefined;
|
|
72197
|
+
}
|
|
72198
|
+
const syntax = new syntax_1.SyntaxLogic(reg, obj).run();
|
|
72199
|
+
// the rules run one after the other on the same object, the syntax result changes when the object changes
|
|
72200
|
+
if (((_a = ObjectAnalysis.last) === null || _a === void 0 ? void 0 : _a.obj) === obj && ObjectAnalysis.last.syntax === syntax) {
|
|
72201
|
+
return ObjectAnalysis.last.analysis;
|
|
72202
|
+
}
|
|
72203
|
+
const analysis = ObjectAnalysis.build(obj, syntax);
|
|
72204
|
+
ObjectAnalysis.last = { obj, syntax, analysis };
|
|
72205
|
+
return analysis;
|
|
72206
|
+
}
|
|
72207
|
+
static build(obj, syntax) {
|
|
72208
|
+
// Neither macro expansion nor unknown statements have reliable references.
|
|
72209
|
+
for (const file of obj.getABAPFiles()) {
|
|
72210
|
+
for (const statement of file.getStatements()) {
|
|
72211
|
+
const type = statement.get();
|
|
72212
|
+
if (type instanceof _statement_1.Unknown || type instanceof Statements.Define
|
|
72213
|
+
|| type instanceof _statement_1.MacroCall || type instanceof _statement_1.MacroContent || type instanceof _statement_1.MacroRecursion) {
|
|
72214
|
+
return undefined;
|
|
72215
|
+
}
|
|
72216
|
+
}
|
|
72217
|
+
}
|
|
72218
|
+
if (syntax.issues.length > 0) {
|
|
72219
|
+
return undefined;
|
|
72220
|
+
}
|
|
72221
|
+
return new ObjectAnalysis(obj, syntax.spaghetti);
|
|
72222
|
+
}
|
|
72223
|
+
constructor(obj, spaghetti) {
|
|
72224
|
+
this.procedures = [];
|
|
72225
|
+
this.byResolved = new Map();
|
|
72226
|
+
this.byPosition = new Map();
|
|
72227
|
+
this.obj = obj;
|
|
72228
|
+
this.spaghetti = spaghetti;
|
|
72229
|
+
const stack = [spaghetti.getTop()];
|
|
72230
|
+
while (stack.length > 0) {
|
|
72231
|
+
const node = stack.pop();
|
|
72232
|
+
for (const reference of node.getData().references) {
|
|
72233
|
+
const position = ObjectAnalysis.key(reference.position);
|
|
72234
|
+
const atPosition = this.byPosition.get(position) || [];
|
|
72235
|
+
atPosition.push(reference);
|
|
72236
|
+
this.byPosition.set(position, atPosition);
|
|
72237
|
+
if (reference.resolved !== undefined) {
|
|
72238
|
+
const resolved = ObjectAnalysis.key(reference.resolved);
|
|
72239
|
+
const list = this.byResolved.get(resolved) || [];
|
|
72240
|
+
list.push(reference);
|
|
72241
|
+
this.byResolved.set(resolved, list);
|
|
72242
|
+
}
|
|
72243
|
+
}
|
|
72244
|
+
stack.push(...node.getChildren());
|
|
72245
|
+
}
|
|
72246
|
+
for (const file of obj.getABAPFiles()) {
|
|
72247
|
+
const structure = file.getStructure();
|
|
72248
|
+
if (structure === undefined) {
|
|
72249
|
+
continue;
|
|
72250
|
+
}
|
|
72251
|
+
for (const procedure of findStructures(structure, [Structures.Method, Structures.Form, Structures.FunctionModule])) {
|
|
72252
|
+
this.procedures.push(new Procedure(this, file, procedure));
|
|
72253
|
+
}
|
|
72254
|
+
}
|
|
72255
|
+
}
|
|
72256
|
+
static key(identifier) {
|
|
72257
|
+
const start = identifier.getStart();
|
|
72258
|
+
return identifier.getFilename() + "," + start.getRow() + "," + start.getCol();
|
|
72259
|
+
}
|
|
72260
|
+
static tokenKey(filename, token) {
|
|
72261
|
+
return filename + "," + token.getRow() + "," + token.getCol();
|
|
72262
|
+
}
|
|
72263
|
+
referencesTo(identifier) {
|
|
72264
|
+
return this.byResolved.get(ObjectAnalysis.key(identifier)) || [];
|
|
72265
|
+
}
|
|
72266
|
+
referencesAt(filename, token) {
|
|
72267
|
+
return this.byPosition.get(ObjectAnalysis.tokenKey(filename, token)) || [];
|
|
72268
|
+
}
|
|
72269
|
+
/** all resolved identifiers, with the positions of their references */
|
|
72270
|
+
allReferences() {
|
|
72271
|
+
return this.byResolved.entries();
|
|
72272
|
+
}
|
|
72273
|
+
}
|
|
72274
|
+
exports.ObjectAnalysis = ObjectAnalysis;
|
|
72275
|
+
const LOOPS = [Structures.Loop, Structures.Do, Structures.While, Structures.Select,
|
|
72276
|
+
Structures.Provide, Structures.LoopAtScreen, Structures.LoopExtract, Structures.With];
|
|
72277
|
+
/** Statements whose data read references are known to only read the value */
|
|
72278
|
+
const READING = [Statements.Move, Statements.Call, Statements.If, Statements.ElseIf,
|
|
72279
|
+
Statements.Case, Statements.When, Statements.While, Statements.Check, Statements.Assert, Statements.Append,
|
|
72280
|
+
Statements.InsertInternal, Statements.ModifyInternal, Statements.DeleteInternal, Statements.ReadTable,
|
|
72281
|
+
Statements.Loop, Statements.CreateObject, Statements.Raise, Statements.Message, Statements.Concatenate,
|
|
72282
|
+
Statements.Split, Statements.Condense, Statements.Translate, Statements.Replace, Statements.Find,
|
|
72283
|
+
Statements.Select, Statements.SelectLoop, Statements.Do, Statements.Write, Statements.Collect,
|
|
72284
|
+
Statements.Describe, Statements.Shift, Statements.Return, Statements.Clear, Statements.Sort,
|
|
72285
|
+
Statements.InsertDatabase, Statements.ModifyDatabase, Statements.UpdateDatabase, Statements.DeleteDatabase];
|
|
72286
|
+
/** Statements which cannot run other ABAP code, unless they contain a method call or NEW */
|
|
72287
|
+
const CALL_FREE = [Statements.Move, Statements.Data, Statements.Clear, Statements.Free,
|
|
72288
|
+
Statements.Append, Statements.InsertInternal, Statements.ModifyInternal, Statements.DeleteInternal,
|
|
72289
|
+
Statements.ReadTable, Statements.Sort, Statements.Concatenate, Statements.Condense, Statements.Split,
|
|
72290
|
+
Statements.Translate, Statements.Replace, Statements.Find, Statements.Shift, Statements.Collect,
|
|
72291
|
+
Statements.Describe, Statements.FieldSymbol, Statements.Constant, Statements.Type, Statements.Unassign,
|
|
72292
|
+
Statements.If, Statements.ElseIf, Statements.Else, Statements.EndIf, Statements.Case, Statements.When,
|
|
72293
|
+
Statements.WhenOthers, Statements.EndCase, Statements.Do, Statements.EndDo, Statements.While, Statements.EndWhile,
|
|
72294
|
+
Statements.Loop, Statements.EndLoop, Statements.Check, Statements.Exit, Statements.Continue, Statements.Return,
|
|
72295
|
+
Statements.Try, Statements.Catch, Statements.Cleanup, Statements.EndTry];
|
|
72296
|
+
/** A METHOD, FORM or FUNCTION implementation */
|
|
72297
|
+
class Procedure {
|
|
72298
|
+
constructor(analysis, file, structure) {
|
|
72299
|
+
var _a, _b, _c;
|
|
72300
|
+
/** all statements, including METHOD and ENDMETHOD */
|
|
72301
|
+
this.statements = [];
|
|
72302
|
+
this.info = new Map();
|
|
72303
|
+
this.parents = new Map();
|
|
72304
|
+
/** identifier tokens by lower case name, positions as row * 100000 + column, the procedure is in one file */
|
|
72305
|
+
this.names = new Map();
|
|
72306
|
+
this.declarations = new Map();
|
|
72307
|
+
this.declarationTokens = [];
|
|
72308
|
+
this.tokens = new Map();
|
|
72309
|
+
this.variables = new Map();
|
|
72310
|
+
this.own = undefined;
|
|
72311
|
+
this.comments = undefined;
|
|
72312
|
+
this.analysis = analysis;
|
|
72313
|
+
this.file = file;
|
|
72314
|
+
this.structure = structure;
|
|
72315
|
+
this.walk(structure, [], undefined, false);
|
|
72316
|
+
this.supported = this.isSupported();
|
|
72317
|
+
if (this.supported === false) {
|
|
72318
|
+
return;
|
|
72319
|
+
}
|
|
72320
|
+
for (const statement of this.statements) {
|
|
72321
|
+
const tokens = this.tokensOf(statement);
|
|
72322
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
72323
|
+
const token = tokens[i];
|
|
72324
|
+
const previous = tokens[i - 1];
|
|
72325
|
+
if (!(token instanceof tokens_1.Identifier)
|
|
72326
|
+
|| (previous !== undefined && (previous.getStr() === "->" || previous.getStr() === "=>"
|
|
72327
|
+
|| previous.getStr() === "~" || previous instanceof tokens_1.Dash))) {
|
|
72328
|
+
continue;
|
|
72329
|
+
}
|
|
72330
|
+
const name = token.getStr().toLowerCase();
|
|
72331
|
+
const list = this.names.get(name);
|
|
72332
|
+
if (list === undefined) {
|
|
72333
|
+
this.names.set(name, [position(token)]);
|
|
72334
|
+
}
|
|
72335
|
+
else {
|
|
72336
|
+
list.push(position(token));
|
|
72337
|
+
}
|
|
72338
|
+
}
|
|
72339
|
+
const type = statement.get();
|
|
72340
|
+
if (type instanceof Statements.Data && this.isSimple(statement)) {
|
|
72341
|
+
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();
|
|
72342
|
+
if (name !== undefined) {
|
|
72343
|
+
this.declarations.set(this.tokenKey(name), statement);
|
|
72344
|
+
this.declarationTokens.push(name);
|
|
72345
|
+
}
|
|
72346
|
+
}
|
|
72347
|
+
if (!(type instanceof Statements.Form) && tokens.some((t, i) => { var _a; return t.getStr().toUpperCase() === "DATA"
|
|
72348
|
+
&& ((_a = tokens[i + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) === "("; })) {
|
|
72349
|
+
for (const inline of statement.findAllExpressionsRecursive(Expressions.InlineData)) {
|
|
72350
|
+
const name = (_c = inline.findDirectExpression(Expressions.TargetField)) === null || _c === void 0 ? void 0 : _c.getFirstToken();
|
|
72351
|
+
if (name !== undefined) {
|
|
72352
|
+
this.declarations.set(this.tokenKey(name), statement);
|
|
72353
|
+
this.declarationTokens.push(name);
|
|
72354
|
+
}
|
|
72355
|
+
}
|
|
72356
|
+
}
|
|
72357
|
+
}
|
|
72358
|
+
}
|
|
72359
|
+
getStart() {
|
|
72360
|
+
return this.structure.getFirstToken().getStart();
|
|
72361
|
+
}
|
|
72362
|
+
getEnd() {
|
|
72363
|
+
return this.structure.getLastToken().getEnd();
|
|
72364
|
+
}
|
|
72365
|
+
contains(identifier) {
|
|
72366
|
+
return identifier.getFilename() === this.file.getFilename()
|
|
72367
|
+
&& !identifier.getStart().isBefore(this.getStart())
|
|
72368
|
+
&& !identifier.getStart().isAfter(this.getEnd());
|
|
72369
|
+
}
|
|
72370
|
+
tokenKey(token) {
|
|
72371
|
+
return ObjectAnalysis.tokenKey(this.file.getFilename(), token);
|
|
72372
|
+
}
|
|
72373
|
+
index(statement) {
|
|
72374
|
+
var _a;
|
|
72375
|
+
var _b;
|
|
72376
|
+
return (_b = (_a = this.info.get(statement)) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : -1;
|
|
72377
|
+
}
|
|
72378
|
+
block(statement) {
|
|
72379
|
+
var _a;
|
|
72380
|
+
return (_a = this.info.get(statement)) === null || _a === void 0 ? void 0 : _a.block;
|
|
72381
|
+
}
|
|
72382
|
+
loop(statement) {
|
|
72383
|
+
var _a;
|
|
72384
|
+
return (_a = this.info.get(statement)) === null || _a === void 0 ? void 0 : _a.loop;
|
|
72385
|
+
}
|
|
72386
|
+
/** a direct statement of its block, not the start, middle or end of a nested structure */
|
|
72387
|
+
isSimple(statement) {
|
|
72388
|
+
var _a;
|
|
72389
|
+
return ((_a = this.info.get(statement)) === null || _a === void 0 ? void 0 : _a.simple) === true;
|
|
72390
|
+
}
|
|
72391
|
+
/** first executes before second, on every path that reaches second within one iteration:
|
|
72392
|
+
* the block of first contains second, and first is before second */
|
|
72393
|
+
dominates(first, second) {
|
|
72394
|
+
const a = this.info.get(first);
|
|
72395
|
+
const b = this.info.get(second);
|
|
72396
|
+
return a !== undefined && b !== undefined && a.block !== undefined
|
|
72397
|
+
&& a.index < b.index && b.blockPath.includes(a.block);
|
|
72398
|
+
}
|
|
72399
|
+
sameLoop(first, second) {
|
|
72400
|
+
return this.loop(first) === this.loop(second);
|
|
72401
|
+
}
|
|
72402
|
+
/** statements strictly between two statements of the same block,
|
|
72403
|
+
* undefined if any of them is not a direct statement of that block */
|
|
72404
|
+
straightBetween(first, second) {
|
|
72405
|
+
const a = this.info.get(first);
|
|
72406
|
+
const b = this.info.get(second);
|
|
72407
|
+
if (a === undefined || b === undefined || a.block === undefined || a.block !== b.block || a.index >= b.index) {
|
|
72408
|
+
return undefined;
|
|
72409
|
+
}
|
|
72410
|
+
const between = this.statements.slice(a.index + 1, b.index);
|
|
72411
|
+
for (const statement of between) {
|
|
72412
|
+
if (this.block(statement) !== a.block || this.isSimple(statement) === false) {
|
|
72413
|
+
return undefined;
|
|
72414
|
+
}
|
|
72415
|
+
}
|
|
72416
|
+
return between;
|
|
72417
|
+
}
|
|
72418
|
+
/** a comment line or end of line comment between the two positions */
|
|
72419
|
+
hasComment(start, end) {
|
|
72420
|
+
if (this.comments === undefined) {
|
|
72421
|
+
this.comments = this.file.getStatements()
|
|
72422
|
+
.filter(s => s.get() instanceof _statement_1.Comment
|
|
72423
|
+
&& !s.getStart().isBefore(this.getStart()) && s.getStart().isBefore(this.getEnd()))
|
|
72424
|
+
.map(s => s.getStart());
|
|
72425
|
+
}
|
|
72426
|
+
return this.comments.some(c => !c.isBefore(start) && c.isBefore(end));
|
|
72427
|
+
}
|
|
72428
|
+
/** the IF structure of an IF or ELSEIF statement */
|
|
72429
|
+
ifStructure(statement) {
|
|
72430
|
+
let parent = this.parents.get(statement);
|
|
72431
|
+
if (statement.get() instanceof Statements.ElseIf && parent !== undefined) {
|
|
72432
|
+
parent = this.parents.get(parent);
|
|
72433
|
+
}
|
|
72434
|
+
return (parent === null || parent === void 0 ? void 0 : parent.get()) instanceof Structures.If ? parent : undefined;
|
|
72435
|
+
}
|
|
72436
|
+
/** the variable for an identifier referenced in this procedure,
|
|
72437
|
+
* undefined for identifiers without data references, e.g. types or methods */
|
|
72438
|
+
variable(identifier) {
|
|
72439
|
+
if (!(identifier instanceof _typed_identifier_1.TypedIdentifier)) {
|
|
72440
|
+
return undefined;
|
|
72441
|
+
}
|
|
72442
|
+
const key = ObjectAnalysis.key(identifier);
|
|
72443
|
+
if (this.variables.has(key)) {
|
|
72444
|
+
return this.variables.get(key);
|
|
72445
|
+
}
|
|
72446
|
+
const declaration = this.contains(identifier) ? this.declarations.get(key) : undefined;
|
|
72447
|
+
const inline = declaration !== undefined && !(declaration.get() instanceof Statements.Data);
|
|
72448
|
+
const occurrences = [];
|
|
72449
|
+
const known = new Set([position(identifier.getToken())]);
|
|
72450
|
+
for (const reference of this.analysis.referencesTo(identifier)) {
|
|
72451
|
+
if (!this.contains(reference.position)) {
|
|
72452
|
+
continue;
|
|
72453
|
+
}
|
|
72454
|
+
const token = reference.position.getToken();
|
|
72455
|
+
known.add(position(token));
|
|
72456
|
+
if (inline && reference.position.getStart().equals(identifier.getStart())
|
|
72457
|
+
&& reference.referenceType === _reference_1.ReferenceType.DataWriteReference) {
|
|
72458
|
+
continue;
|
|
72459
|
+
}
|
|
72460
|
+
const statement = this.statementOf(token);
|
|
72461
|
+
if (statement === undefined) {
|
|
72462
|
+
this.variables.set(key, undefined);
|
|
72463
|
+
return undefined;
|
|
72464
|
+
}
|
|
72465
|
+
occurrences.push({ token, statement, index: this.index(statement), kind: this.classify(reference, statement) });
|
|
72466
|
+
}
|
|
72467
|
+
// several references at the same position, e.g. read and write in LOOP AT itab ASSIGNING
|
|
72468
|
+
occurrences.sort((a, b) => a.token.getStart().isBefore(b.token.getStart()) ? -1
|
|
72469
|
+
: a.token.getStart().equals(b.token.getStart()) ? 0 : 1);
|
|
72470
|
+
const merged = [];
|
|
72471
|
+
for (const occurrence of occurrences) {
|
|
72472
|
+
const last = merged[merged.length - 1];
|
|
72473
|
+
if (last !== undefined && last.token.getStart().equals(occurrence.token.getStart())) {
|
|
72474
|
+
if (last.kind !== occurrence.kind) {
|
|
72475
|
+
merged[merged.length - 1] = Object.assign(Object.assign({}, last), { kind: rank(last.kind) > rank(occurrence.kind) ? last.kind : occurrence.kind });
|
|
72476
|
+
}
|
|
72477
|
+
continue;
|
|
72478
|
+
}
|
|
72479
|
+
merged.push(occurrence);
|
|
72480
|
+
}
|
|
72481
|
+
let complete = true;
|
|
72482
|
+
for (const named of this.names.get(identifier.getName().toLowerCase()) || []) {
|
|
72483
|
+
if (!known.has(named)) {
|
|
72484
|
+
complete = false;
|
|
72485
|
+
}
|
|
72486
|
+
}
|
|
72487
|
+
const variable = new Variable(identifier, declaration, inline, merged, complete);
|
|
72488
|
+
this.variables.set(key, variable);
|
|
72489
|
+
return variable;
|
|
72490
|
+
}
|
|
72491
|
+
/** local variable, declared in the procedure by DATA or inline, and with all its references understood */
|
|
72492
|
+
local(identifier) {
|
|
72493
|
+
const variable = this.variable(identifier);
|
|
72494
|
+
if (variable === undefined || variable.isLocal() === false || variable.complete === false
|
|
72495
|
+
|| variable.identifier.getMeta().includes("static" /* IdentifierMeta.Static */)) {
|
|
72496
|
+
return undefined;
|
|
72497
|
+
}
|
|
72498
|
+
return variable;
|
|
72499
|
+
}
|
|
72500
|
+
/** all local variables declared in the procedure */
|
|
72501
|
+
locals() {
|
|
72502
|
+
var _a;
|
|
72503
|
+
const ret = [];
|
|
72504
|
+
for (const token of this.declarationTokens) {
|
|
72505
|
+
const variable = this.local((_a = this.identifierAt(token)) !== null && _a !== void 0 ? _a : this.declaredIdentifier(token));
|
|
72506
|
+
if (variable !== undefined) {
|
|
72507
|
+
ret.push(variable);
|
|
72508
|
+
}
|
|
72509
|
+
}
|
|
72510
|
+
return ret;
|
|
72511
|
+
}
|
|
72512
|
+
/** tokens of the statement, getTokens() builds a new list on every call */
|
|
72513
|
+
tokensOf(statement) {
|
|
72514
|
+
let tokens = this.tokens.get(statement);
|
|
72515
|
+
if (tokens === undefined) {
|
|
72516
|
+
tokens = statement.getTokens();
|
|
72517
|
+
this.tokens.set(statement, tokens);
|
|
72518
|
+
}
|
|
72519
|
+
return tokens;
|
|
72520
|
+
}
|
|
72521
|
+
/** the resolved identifier of the data reference at the token, if any */
|
|
72522
|
+
identifierAt(token) {
|
|
72523
|
+
for (const reference of this.analysis.referencesAt(this.file.getFilename(), token)) {
|
|
72524
|
+
if (reference.referenceType === _reference_1.ReferenceType.DataReadReference
|
|
72525
|
+
|| reference.referenceType === _reference_1.ReferenceType.DataWriteReference) {
|
|
72526
|
+
return reference.resolved;
|
|
72527
|
+
}
|
|
72528
|
+
}
|
|
72529
|
+
return undefined;
|
|
72530
|
+
}
|
|
72531
|
+
/** the identifier declared at the token, also when it is never referenced */
|
|
72532
|
+
declaredIdentifier(token) {
|
|
72533
|
+
var _a;
|
|
72534
|
+
const found = (_a = this.analysis.spaghetti.lookupPosition(token.getStart(), this.file.getFilename())) === null || _a === void 0 ? void 0 : _a.findVariable(token.getStr());
|
|
72535
|
+
return found !== undefined && found.getFilename() === this.file.getFilename()
|
|
72536
|
+
&& found.getStart().equals(token.getStart()) ? found : undefined;
|
|
72537
|
+
}
|
|
72538
|
+
/** identifiers declared in the procedure, with all their references */
|
|
72539
|
+
ownReferences() {
|
|
72540
|
+
if (this.own === undefined) {
|
|
72541
|
+
this.own = [];
|
|
72542
|
+
for (const [, references] of this.analysis.allReferences()) {
|
|
72543
|
+
const resolved = references[0].resolved;
|
|
72544
|
+
if (resolved !== undefined && this.contains(resolved)) {
|
|
72545
|
+
this.own.push([resolved, references]);
|
|
72546
|
+
}
|
|
72547
|
+
}
|
|
72548
|
+
}
|
|
72549
|
+
return this.own;
|
|
72550
|
+
}
|
|
72551
|
+
statementOf(token) {
|
|
72552
|
+
// statement ends are increasing, also for chained statements which share their first tokens
|
|
72553
|
+
let low = 0;
|
|
72554
|
+
let high = this.statements.length;
|
|
72555
|
+
const start = token.getStart();
|
|
72556
|
+
while (low < high) {
|
|
72557
|
+
const middle = Math.floor((low + high) / 2);
|
|
72558
|
+
if (this.statements[middle].getEnd().isBefore(start)) {
|
|
72559
|
+
low = middle + 1;
|
|
72560
|
+
}
|
|
72561
|
+
else {
|
|
72562
|
+
high = middle;
|
|
72563
|
+
}
|
|
72564
|
+
}
|
|
72565
|
+
for (let i = low; i < this.statements.length && !start.isBefore(this.statements[i].getStart()); i++) {
|
|
72566
|
+
if (this.statements[i].includesToken(token)) {
|
|
72567
|
+
return this.statements[i];
|
|
72568
|
+
}
|
|
72569
|
+
}
|
|
72570
|
+
return undefined;
|
|
72571
|
+
}
|
|
72572
|
+
/** the statement cannot run other ABAP code: no method, function or form call, no constructor, no event */
|
|
72573
|
+
isCallFree(statement) {
|
|
72574
|
+
var _a;
|
|
72575
|
+
const type = statement.get();
|
|
72576
|
+
if (!CALL_FREE.some(t => type instanceof t)) {
|
|
72577
|
+
return false;
|
|
72578
|
+
}
|
|
72579
|
+
for (const call of statement.findAllExpressionsRecursive(Expressions.MethodCall)) {
|
|
72580
|
+
const name = (_a = call.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
|
72581
|
+
if (name === undefined) {
|
|
72582
|
+
return false;
|
|
72583
|
+
}
|
|
72584
|
+
const references = this.analysis.referencesAt(this.file.getFilename(), name);
|
|
72585
|
+
if (references.length === 0 || references.some(r => r.referenceType !== _reference_1.ReferenceType.BuiltinMethodReference)) {
|
|
72586
|
+
return false;
|
|
72587
|
+
}
|
|
72588
|
+
}
|
|
72589
|
+
return statement.findFirstExpression(Expressions.NewObject) === undefined;
|
|
72590
|
+
}
|
|
72591
|
+
/** every data write in the statement goes to a local variable, a pass-by-value parameter or the
|
|
72592
|
+
* RETURNING parameter, ie. memory that no other data object, field symbol or reference can share */
|
|
72593
|
+
writesOnlyPrivate(statement) {
|
|
72594
|
+
var _a;
|
|
72595
|
+
const tokens = this.tokensOf(statement);
|
|
72596
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
72597
|
+
for (const reference of this.analysis.referencesAt(this.file.getFilename(), tokens[i])) {
|
|
72598
|
+
if (reference.referenceType !== _reference_1.ReferenceType.DataWriteReference) {
|
|
72599
|
+
continue;
|
|
72600
|
+
}
|
|
72601
|
+
if (((_a = tokens[i + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) === "->") {
|
|
72602
|
+
return false;
|
|
72603
|
+
}
|
|
72604
|
+
const variable = this.variable(reference.resolved);
|
|
72605
|
+
if (variable === undefined || variable.escapes()) {
|
|
72606
|
+
return false;
|
|
72607
|
+
}
|
|
72608
|
+
const meta = variable.identifier.getMeta();
|
|
72609
|
+
if (!variable.isLocal() && !meta.includes("returning" /* IdentifierMeta.MethodReturning */)
|
|
72610
|
+
&& !meta.includes("pass_by_value" /* IdentifierMeta.PassByValue */)) {
|
|
72611
|
+
return false;
|
|
72612
|
+
}
|
|
72613
|
+
}
|
|
72614
|
+
}
|
|
72615
|
+
// writes without any reference, e.g. to field symbols assigned dynamically, are not expected after the
|
|
72616
|
+
// syntax check, but field symbol targets are excluded explicitly
|
|
72617
|
+
return statement.findFirstExpression(Expressions.TargetFieldSymbol) === undefined
|
|
72618
|
+
&& statement.findFirstExpression(Expressions.Dereference) === undefined;
|
|
72619
|
+
}
|
|
72620
|
+
classify(reference, statement) {
|
|
72621
|
+
var _a;
|
|
72622
|
+
if (reference.referenceType !== _reference_1.ReferenceType.DataReadReference
|
|
72623
|
+
&& reference.referenceType !== _reference_1.ReferenceType.DataWriteReference) {
|
|
72624
|
+
return OccurrenceKind.Escape;
|
|
72625
|
+
}
|
|
72626
|
+
const token = reference.position.getToken();
|
|
72627
|
+
const tokens = this.tokensOf(statement);
|
|
72628
|
+
const index = tokens.findIndex(t => t.getStart().equals(token.getStart()));
|
|
72629
|
+
if (index < 0) {
|
|
72630
|
+
return OccurrenceKind.Escape;
|
|
72631
|
+
}
|
|
72632
|
+
const path = expressionPath(statement, token);
|
|
72633
|
+
if (path.some(e => e.get() instanceof Expressions.Dynamic)) {
|
|
72634
|
+
return OccurrenceKind.Escape;
|
|
72635
|
+
}
|
|
72636
|
+
if (((_a = tokens[index + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) === "->") {
|
|
72637
|
+
// the reference itself is not changed, nor exposed, only the object or data it points to
|
|
72638
|
+
return OccurrenceKind.Read;
|
|
72639
|
+
}
|
|
72640
|
+
if (reference.referenceType === _reference_1.ReferenceType.DataWriteReference) {
|
|
72641
|
+
return OccurrenceKind.Write;
|
|
72642
|
+
}
|
|
72643
|
+
const type = statement.get();
|
|
72644
|
+
if (!READING.some(t => type instanceof t)
|
|
72645
|
+
|| statement.findFirstExpression(Expressions.FSTarget) !== undefined
|
|
72646
|
+
|| statement.findTokenSequencePosition("REFERENCE", "INTO") !== undefined
|
|
72647
|
+
|| path.some(e => e.get() instanceof Expressions.Source && isRefConstructor(e))) {
|
|
72648
|
+
return OccurrenceKind.Escape;
|
|
72649
|
+
}
|
|
72650
|
+
return OccurrenceKind.Read;
|
|
72651
|
+
}
|
|
72652
|
+
isSupported() {
|
|
72653
|
+
for (const statement of this.statements) {
|
|
72654
|
+
const type = statement.get();
|
|
72655
|
+
if (type instanceof Statements.Include || type instanceof _statement_1.NativeSQL
|
|
72656
|
+
|| type instanceof Statements.TestSeam || type instanceof Statements.TestInjection
|
|
72657
|
+
|| type instanceof Statements.Enhancement || type instanceof Statements.EnhancementSection
|
|
72658
|
+
|| type instanceof Statements.ExecSQL
|
|
72659
|
+
|| statement.findFirstExpression(Expressions.Dynamic) !== undefined) {
|
|
72660
|
+
return false;
|
|
72661
|
+
}
|
|
72662
|
+
}
|
|
72663
|
+
return true;
|
|
72664
|
+
}
|
|
72665
|
+
walk(node, blockPath, loop, simple) {
|
|
72666
|
+
const type = node.get();
|
|
72667
|
+
if (type instanceof Structures.Body) {
|
|
72668
|
+
blockPath = [...blockPath, node];
|
|
72669
|
+
}
|
|
72670
|
+
else if (LOOPS.some(l => type instanceof l) || (type instanceof Structures.Try && retries(node))) {
|
|
72671
|
+
loop = node;
|
|
72672
|
+
}
|
|
72673
|
+
for (const child of node.getChildren()) {
|
|
72674
|
+
this.parents.set(child, node);
|
|
72675
|
+
if (child instanceof nodes_1.StructureNode) {
|
|
72676
|
+
this.walk(child, blockPath, loop, child.get() instanceof Structures.Normal);
|
|
72677
|
+
}
|
|
72678
|
+
else if (child instanceof nodes_1.StatementNode) {
|
|
72679
|
+
this.info.set(child, {
|
|
72680
|
+
index: this.statements.length,
|
|
72681
|
+
block: blockPath[blockPath.length - 1],
|
|
72682
|
+
blockPath,
|
|
72683
|
+
loop,
|
|
72684
|
+
simple: simple && type instanceof Structures.Normal,
|
|
72685
|
+
});
|
|
72686
|
+
this.statements.push(child);
|
|
72687
|
+
}
|
|
72688
|
+
}
|
|
72689
|
+
}
|
|
72690
|
+
}
|
|
72691
|
+
exports.Procedure = Procedure;
|
|
72692
|
+
function position(token) {
|
|
72693
|
+
return token.getRow() * 100000 + token.getCol();
|
|
72694
|
+
}
|
|
72695
|
+
function rank(kind) {
|
|
72696
|
+
return kind === OccurrenceKind.Escape ? 2 : kind === OccurrenceKind.Write ? 1 : 0;
|
|
72697
|
+
}
|
|
72698
|
+
/** RETRY and RESUME jump back into the TRY block, as does a CATCH BEFORE UNWIND handler */
|
|
72699
|
+
function retries(node) {
|
|
72700
|
+
return node.findAllStatements(Statements.Retry).length > 0
|
|
72701
|
+
|| node.findAllStatements(Statements.Resume).length > 0
|
|
72702
|
+
|| node.findAllStatements(Statements.Catch).some(c => c.findDirectTokenByText("UNWIND") !== undefined);
|
|
72703
|
+
}
|
|
72704
|
+
function isRefConstructor(source) {
|
|
72705
|
+
const first = source.getChildren()[0];
|
|
72706
|
+
return first instanceof nodes_1.TokenNode && first.getFirstToken().getStr().toUpperCase() === "REF"
|
|
72707
|
+
&& source.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined;
|
|
72708
|
+
}
|
|
72709
|
+
function findStructures(node, types) {
|
|
72710
|
+
if (types.some(t => node.get() instanceof t)) {
|
|
72711
|
+
return [node];
|
|
72712
|
+
}
|
|
72713
|
+
const ret = [];
|
|
72714
|
+
for (const child of node.getChildren()) {
|
|
72715
|
+
if (child instanceof nodes_1.StructureNode) {
|
|
72716
|
+
ret.push(...findStructures(child, types));
|
|
72717
|
+
}
|
|
72718
|
+
}
|
|
72719
|
+
return ret;
|
|
72720
|
+
}
|
|
72721
|
+
/** expression nodes from the statement down to the token */
|
|
72722
|
+
function expressionPath(statement, token) {
|
|
72723
|
+
const ret = [];
|
|
72724
|
+
let children = statement.getChildren();
|
|
72725
|
+
for (;;) {
|
|
72726
|
+
let next = undefined;
|
|
72727
|
+
for (const child of children) {
|
|
72728
|
+
if (child instanceof nodes_1.ExpressionNode
|
|
72729
|
+
&& !token.getStart().isBefore(child.getFirstToken().getStart())
|
|
72730
|
+
&& !child.getLastToken().getStart().isBefore(token.getStart())) {
|
|
72731
|
+
next = child;
|
|
72732
|
+
break;
|
|
72733
|
+
}
|
|
72734
|
+
}
|
|
72735
|
+
if (next === undefined) {
|
|
72736
|
+
return ret;
|
|
72737
|
+
}
|
|
72738
|
+
ret.push(next);
|
|
72739
|
+
children = next.getChildren();
|
|
72740
|
+
}
|
|
72741
|
+
}
|
|
72742
|
+
/** target = source. or target ?= source. without chaining, pragmas or MOVE */
|
|
72743
|
+
function plainMove(statement) {
|
|
72744
|
+
if (!(statement.get() instanceof Statements.Move) || statement.getColon() !== undefined
|
|
72745
|
+
|| statement.getPragmas().length > 0) {
|
|
72746
|
+
return undefined;
|
|
72747
|
+
}
|
|
72748
|
+
const target = statement.findDirectExpression(Expressions.Target);
|
|
72749
|
+
const source = statement.findDirectExpression(Expressions.Source);
|
|
72750
|
+
const tokens = statement.getTokens();
|
|
72751
|
+
if (target === undefined || source === undefined
|
|
72752
|
+
|| tokens.length !== target.countTokens() + source.countTokens() + 2) {
|
|
72753
|
+
return undefined;
|
|
72754
|
+
}
|
|
72755
|
+
const operator = tokens[target.countTokens()].getStr();
|
|
72756
|
+
if (operator !== "=" && operator !== "?=") {
|
|
72757
|
+
return undefined;
|
|
72758
|
+
}
|
|
72759
|
+
return { target, source, operator };
|
|
72760
|
+
}
|
|
72761
|
+
/** the source is a single field, ie. one token */
|
|
72762
|
+
function singleField(source) {
|
|
72763
|
+
var _a;
|
|
72764
|
+
if (source.getChildren().length !== 1 || source.countTokens() !== 1) {
|
|
72765
|
+
return undefined;
|
|
72766
|
+
}
|
|
72767
|
+
const field = (_a = source.findDirectExpression(Expressions.FieldChain)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.SourceField);
|
|
72768
|
+
return field === null || field === void 0 ? void 0 : field.getFirstToken();
|
|
72769
|
+
}
|
|
72770
|
+
/** the target is a single field, ie. one token, not an inline declaration */
|
|
72771
|
+
function singleTarget(target) {
|
|
72772
|
+
if (target.countTokens() !== 1 || target.findDirectExpression(Expressions.TargetField) === undefined) {
|
|
72773
|
+
return undefined;
|
|
72774
|
+
}
|
|
72775
|
+
return target.getFirstToken();
|
|
72776
|
+
}
|
|
72777
|
+
/** CLEAR name. without chaining or WITH */
|
|
72778
|
+
function plainClear(statement) {
|
|
72779
|
+
if (!(statement.get() instanceof Statements.Clear) || statement.getPragmas().length > 0) {
|
|
72780
|
+
return undefined;
|
|
72781
|
+
}
|
|
72782
|
+
const targets = statement.findDirectExpressions(Expressions.Target);
|
|
72783
|
+
const tokens = statement.getTokens();
|
|
72784
|
+
if (targets.length !== 1 || tokens.length !== 3 || tokens[0].getStr().toUpperCase() !== "CLEAR") {
|
|
72785
|
+
return undefined;
|
|
72786
|
+
}
|
|
72787
|
+
return singleTarget(targets[0]);
|
|
72788
|
+
}
|
|
72789
|
+
/** DATA name TYPE/LIKE ... without VALUE, without chaining */
|
|
72790
|
+
function plainData(statement) {
|
|
72791
|
+
var _a;
|
|
72792
|
+
return statement.get() instanceof Statements.Data
|
|
72793
|
+
&& ((_a = statement.findDirectExpression(Expressions.DataDefinition)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Value)) === undefined;
|
|
72794
|
+
}
|
|
72795
|
+
/** constants of the class or program, builtin constants like abap_true, and me: never change */
|
|
72796
|
+
function isImmutable(identifier) {
|
|
72797
|
+
if (!(identifier instanceof _typed_identifier_1.TypedIdentifier)) {
|
|
72798
|
+
return false;
|
|
72799
|
+
}
|
|
72800
|
+
const meta = identifier.getMeta();
|
|
72801
|
+
if (identifier.getName().toLowerCase() === "me" && identifier.getType() instanceof basic_1.ObjectReferenceType) {
|
|
72802
|
+
return true;
|
|
72803
|
+
}
|
|
72804
|
+
return meta.includes("read_only" /* IdentifierMeta.ReadOnly */)
|
|
72805
|
+
&& (meta.includes("static" /* IdentifierMeta.Static */) || (meta.includes("built-in" /* IdentifierMeta.BuiltIn */) && identifier.getValue() !== undefined));
|
|
72806
|
+
}
|
|
72807
|
+
function isReferenceType(type) {
|
|
72808
|
+
return type instanceof basic_1.ObjectReferenceType || type instanceof basic_1.DataReference;
|
|
72809
|
+
}
|
|
72810
|
+
/** same runtime type, so assignments between the two never convert */
|
|
72811
|
+
function identicalTypes(first, second) {
|
|
72812
|
+
var _a, _b;
|
|
72813
|
+
if (first instanceof basic_1.UnknownType || second instanceof basic_1.UnknownType
|
|
72814
|
+
|| first instanceof basic_1.VoidType || second instanceof basic_1.VoidType
|
|
72815
|
+
|| first.isGeneric() || second.isGeneric()
|
|
72816
|
+
|| first.constructor !== second.constructor) {
|
|
72817
|
+
return false;
|
|
72818
|
+
}
|
|
72819
|
+
if (first instanceof basic_1.StructureType || first instanceof basic_1.TableType) {
|
|
72820
|
+
const firstName = (_a = first.getQualifiedName()) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
72821
|
+
return firstName !== undefined && firstName === ((_b = second.getQualifiedName()) === null || _b === void 0 ? void 0 : _b.toUpperCase());
|
|
72822
|
+
}
|
|
72823
|
+
if (isReferenceType(first)) {
|
|
72824
|
+
return first.toABAP().toUpperCase() === second.toABAP().toUpperCase();
|
|
72825
|
+
}
|
|
72826
|
+
return first.toABAP() === second.toABAP();
|
|
72827
|
+
}
|
|
72828
|
+
////////////////////////////////////////
|
|
72829
|
+
// conditions
|
|
72830
|
+
var PredicateKind;
|
|
72831
|
+
(function (PredicateKind) {
|
|
72832
|
+
PredicateKind["Equal"] = "equal";
|
|
72833
|
+
PredicateKind["Initial"] = "initial";
|
|
72834
|
+
PredicateKind["Bound"] = "bound";
|
|
72835
|
+
})(PredicateKind || (exports.PredicateKind = PredicateKind = {}));
|
|
72836
|
+
/** the condition of IF or ELSEIF is one comparison: a = b, a EQ b, a <> b, a NE b,
|
|
72837
|
+
* a IS [NOT] INITIAL, a IS [NOT] BOUND, optionally prefixed with NOT */
|
|
72838
|
+
function simplePredicate(statement) {
|
|
72839
|
+
if (!(statement.get() instanceof Statements.If || statement.get() instanceof Statements.ElseIf)
|
|
72840
|
+
|| statement.getColon() !== undefined) {
|
|
72841
|
+
return undefined;
|
|
72842
|
+
}
|
|
72843
|
+
const cond = statement.findDirectExpression(Expressions.Cond);
|
|
72844
|
+
if (cond === undefined || cond.getChildren().length !== 1) {
|
|
72845
|
+
return undefined;
|
|
72846
|
+
}
|
|
72847
|
+
const compare = cond.findDirectExpression(Expressions.Compare);
|
|
72848
|
+
if (compare === undefined) {
|
|
72849
|
+
return undefined;
|
|
72850
|
+
}
|
|
72851
|
+
const children = compare.getChildren();
|
|
72852
|
+
let negated = false;
|
|
72853
|
+
let i = 0;
|
|
72854
|
+
if (children[0] instanceof nodes_1.TokenNode && children[0].getFirstToken().getStr().toUpperCase() === "NOT") {
|
|
72855
|
+
negated = true;
|
|
72856
|
+
i = 1;
|
|
72857
|
+
}
|
|
72858
|
+
const left = children[i];
|
|
72859
|
+
if (!(left instanceof nodes_1.ExpressionNode) || !(left.get() instanceof Expressions.Source)) {
|
|
72860
|
+
return undefined;
|
|
72861
|
+
}
|
|
72862
|
+
const rest = children.slice(i + 1);
|
|
72863
|
+
const words = rest.map(c => c instanceof nodes_1.TokenNode ? c.getFirstToken().getStr().toUpperCase() : "");
|
|
72864
|
+
if (rest.length === 2 && rest[0].get() instanceof Expressions.CompareOperator
|
|
72865
|
+
&& rest[1] instanceof nodes_1.ExpressionNode && rest[1].get() instanceof Expressions.Source) {
|
|
72866
|
+
const operator = rest[0].getFirstToken().getStr().toUpperCase();
|
|
72867
|
+
if (rest[0].countTokens() !== 1 || !["=", "EQ", "<>", "NE"].includes(operator)) {
|
|
72868
|
+
return undefined;
|
|
72869
|
+
}
|
|
72870
|
+
return { kind: PredicateKind.Equal, left, right: rest[1], negated: negated !== (operator === "<>" || operator === "NE") };
|
|
72871
|
+
}
|
|
72872
|
+
else if (words.join(" ") === "IS INITIAL" || words.join(" ") === "IS NOT INITIAL") {
|
|
72873
|
+
return { kind: PredicateKind.Initial, left, negated: negated !== (words.length === 3) };
|
|
72874
|
+
}
|
|
72875
|
+
else if (words.join(" ") === "IS BOUND" || words.join(" ") === "IS NOT BOUND") {
|
|
72876
|
+
return { kind: PredicateKind.Bound, left, negated: negated !== (words.length === 3) };
|
|
72877
|
+
}
|
|
72878
|
+
return undefined;
|
|
72879
|
+
}
|
|
72880
|
+
/** value of a character literal 'abc', or of a character constant like abap_true, undefined otherwise */
|
|
72881
|
+
function characterConstant(procedure, source) {
|
|
72882
|
+
var _a;
|
|
72883
|
+
if (source.getChildren().length !== 1) {
|
|
72884
|
+
return undefined;
|
|
72885
|
+
}
|
|
72886
|
+
const literal = (_a = source.findDirectExpression(Expressions.Constant)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.ConstantString);
|
|
72887
|
+
if (literal !== undefined) {
|
|
72888
|
+
return literal.countTokens() === 1 ? textLiteral(literal.getFirstToken().getStr()) : undefined;
|
|
72889
|
+
}
|
|
72890
|
+
const field = singleField(source);
|
|
72891
|
+
const identifier = field === undefined ? undefined : procedure.identifierAt(field);
|
|
72892
|
+
if (identifier instanceof _typed_identifier_1.TypedIdentifier && isImmutable(identifier)
|
|
72893
|
+
&& identifier.getType() instanceof basic_1.CharacterType) {
|
|
72894
|
+
const value = identifier.getValue();
|
|
72895
|
+
return typeof value === "string" ? textLiteral(value) : undefined;
|
|
72896
|
+
}
|
|
72897
|
+
return undefined;
|
|
72898
|
+
}
|
|
72899
|
+
function textLiteral(text) {
|
|
72900
|
+
if (text.length < 2 || !text.startsWith("'") || !text.endsWith("'")) {
|
|
72901
|
+
return undefined;
|
|
72902
|
+
}
|
|
72903
|
+
return text.substring(1, text.length - 1).replace(/''/g, "'");
|
|
72904
|
+
}
|
|
72905
|
+
/** character values compare after padding the shorter one with blanks */
|
|
72906
|
+
function sameCharacters(first, second) {
|
|
72907
|
+
return first.replace(/ +$/, "") === second.replace(/ +$/, "");
|
|
72908
|
+
}
|
|
72909
|
+
/** IF, ELSEIF, WHILE, CHECK, CASE or WHEN: a constant compared there is left for constant_condition,
|
|
72910
|
+
* instead of replacing a variable by a constant and comparing two constants */
|
|
72911
|
+
function isCondition(statement) {
|
|
72912
|
+
const type = statement.get();
|
|
72913
|
+
return type instanceof Statements.If || type instanceof Statements.ElseIf || type instanceof Statements.While
|
|
72914
|
+
|| type instanceof Statements.Check || type instanceof Statements.Case || type instanceof Statements.When;
|
|
72915
|
+
}
|
|
72916
|
+
////////////////////////////////////////
|
|
72917
|
+
// data sources
|
|
72918
|
+
var SourceKind;
|
|
72919
|
+
(function (SourceKind) {
|
|
72920
|
+
/** constants and me, never change */
|
|
72921
|
+
SourceKind["Immutable"] = "immutable";
|
|
72922
|
+
/** a local variable, or a component of it, changes only by references to the variable */
|
|
72923
|
+
SourceKind["Local"] = "local";
|
|
72924
|
+
/** attributes, parameters, globals, anything reached via a reference: may change by other code */
|
|
72925
|
+
SourceKind["Volatile"] = "volatile";
|
|
72926
|
+
})(SourceKind || (exports.SourceKind = SourceKind = {}));
|
|
72927
|
+
/** a plain data object: field, constant, attribute or component chain without calls, offsets, table
|
|
72928
|
+
* expressions, field symbols or dereferencing with ->* */
|
|
72929
|
+
function dataSource(procedure, source) {
|
|
72930
|
+
var _a;
|
|
72931
|
+
if (source.getChildren().length !== 1) {
|
|
72932
|
+
return undefined;
|
|
72933
|
+
}
|
|
72934
|
+
const chain = source.findDirectExpression(Expressions.FieldChain);
|
|
72935
|
+
if (chain === undefined) {
|
|
72936
|
+
return undefined;
|
|
72937
|
+
}
|
|
72938
|
+
const children = chain.getChildren();
|
|
72939
|
+
let first;
|
|
72940
|
+
let next;
|
|
72941
|
+
if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.SourceField) {
|
|
72942
|
+
first = procedure.identifierAt(children[0].getFirstToken());
|
|
72943
|
+
next = 1;
|
|
72944
|
+
}
|
|
72945
|
+
else if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.ClassName
|
|
72946
|
+
&& ((_a = children[1]) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr()) === "=>" && children[2] instanceof nodes_1.ExpressionNode
|
|
72947
|
+
&& children[2].get() instanceof Expressions.AttributeName) {
|
|
72948
|
+
first = procedure.identifierAt(children[2].getFirstToken());
|
|
72949
|
+
next = 3;
|
|
72950
|
+
}
|
|
72951
|
+
else {
|
|
72952
|
+
return undefined;
|
|
72953
|
+
}
|
|
72954
|
+
if (!(first instanceof _typed_identifier_1.TypedIdentifier)
|
|
72955
|
+
|| (first.getMeta().includes("built-in" /* IdentifierMeta.BuiltIn */) && !isImmutable(first))) {
|
|
72956
|
+
// system fields like sy-subrc and sy-tabix are changed by many statements without a write reference
|
|
72957
|
+
return undefined;
|
|
72958
|
+
}
|
|
72959
|
+
let type = first.getType();
|
|
72960
|
+
let deref = false;
|
|
72961
|
+
for (let i = next; i < children.length; i += 2) {
|
|
72962
|
+
const separator = children[i];
|
|
72963
|
+
const name = children[i + 1];
|
|
72964
|
+
if (!(separator instanceof nodes_1.TokenNode) || !(name instanceof nodes_1.ExpressionNode) || type === undefined) {
|
|
72965
|
+
return undefined;
|
|
72966
|
+
}
|
|
72967
|
+
if (type instanceof basic_1.TableType && type.isWithHeader()) {
|
|
72968
|
+
return undefined;
|
|
72969
|
+
}
|
|
72970
|
+
else if (separator.getFirstToken().getStr() === "->" && name.get() instanceof Expressions.AttributeName) {
|
|
72971
|
+
const attribute = procedure.identifierAt(name.getFirstToken());
|
|
72972
|
+
type = attribute instanceof _typed_identifier_1.TypedIdentifier ? attribute.getType() : undefined;
|
|
72973
|
+
deref = true;
|
|
72974
|
+
}
|
|
72975
|
+
else if (separator.getFirstToken().getStr() === "-" && name.get() instanceof Expressions.ComponentName
|
|
72976
|
+
&& type instanceof basic_1.StructureType) {
|
|
72977
|
+
type = type.getComponentByName(name.getFirstToken().getStr());
|
|
72978
|
+
}
|
|
72979
|
+
else {
|
|
72980
|
+
return undefined;
|
|
72981
|
+
}
|
|
72982
|
+
}
|
|
72983
|
+
if (type === undefined || type.isGeneric() || (type instanceof basic_1.TableType && type.isWithHeader())) {
|
|
72984
|
+
return undefined;
|
|
72985
|
+
}
|
|
72986
|
+
const local = next === 1 ? procedure.local(first) : undefined;
|
|
72987
|
+
let kind = SourceKind.Volatile;
|
|
72988
|
+
if (deref === false && isImmutable(first)) {
|
|
72989
|
+
kind = SourceKind.Immutable;
|
|
72990
|
+
}
|
|
72991
|
+
else if (deref === false && local !== undefined) {
|
|
72992
|
+
kind = SourceKind.Local;
|
|
72993
|
+
}
|
|
72994
|
+
return { text: nodeText(procedure.file, source), kind, base: local, type };
|
|
72995
|
+
}
|
|
72996
|
+
/** type of a plain target: variable, field symbol, attribute or component chain, not an inline declaration,
|
|
72997
|
+
* without offsets, table expressions or ->* */
|
|
72998
|
+
function targetType(procedure, target) {
|
|
72999
|
+
var _a;
|
|
73000
|
+
const children = target.getChildren();
|
|
73001
|
+
let identifier;
|
|
73002
|
+
let next;
|
|
73003
|
+
const first = children[0];
|
|
73004
|
+
if (first instanceof nodes_1.ExpressionNode
|
|
73005
|
+
&& (first.get() instanceof Expressions.TargetField || first.get() instanceof Expressions.TargetFieldSymbol)) {
|
|
73006
|
+
identifier = procedure.identifierAt(first.getFirstToken());
|
|
73007
|
+
next = 1;
|
|
73008
|
+
}
|
|
73009
|
+
else if (first instanceof nodes_1.ExpressionNode && first.get() instanceof Expressions.ClassName
|
|
73010
|
+
&& ((_a = children[1]) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr()) === "=>" && children[2] instanceof nodes_1.ExpressionNode
|
|
73011
|
+
&& children[2].get() instanceof Expressions.AttributeName) {
|
|
73012
|
+
identifier = procedure.identifierAt(children[2].getFirstToken());
|
|
73013
|
+
next = 3;
|
|
73014
|
+
}
|
|
73015
|
+
else {
|
|
73016
|
+
return undefined;
|
|
73017
|
+
}
|
|
73018
|
+
let type = identifier instanceof _typed_identifier_1.TypedIdentifier ? identifier.getType() : undefined;
|
|
73019
|
+
for (let i = next; i < children.length; i += 2) {
|
|
73020
|
+
const separator = children[i];
|
|
73021
|
+
const name = children[i + 1];
|
|
73022
|
+
if (!(separator instanceof nodes_1.TokenNode) || !(name instanceof nodes_1.ExpressionNode) || type === undefined) {
|
|
73023
|
+
return undefined;
|
|
73024
|
+
}
|
|
73025
|
+
if (separator.getFirstToken().getStr() === "->" && name.get() instanceof Expressions.AttributeName) {
|
|
73026
|
+
const attribute = procedure.identifierAt(name.getFirstToken());
|
|
73027
|
+
type = attribute instanceof _typed_identifier_1.TypedIdentifier ? attribute.getType() : undefined;
|
|
73028
|
+
}
|
|
73029
|
+
else if (separator.getFirstToken().getStr() === "-" && name.get() instanceof Expressions.ComponentName
|
|
73030
|
+
&& type instanceof basic_1.StructureType) {
|
|
73031
|
+
type = type.getComponentByName(name.getFirstToken().getStr());
|
|
73032
|
+
}
|
|
73033
|
+
else {
|
|
73034
|
+
return undefined;
|
|
73035
|
+
}
|
|
73036
|
+
}
|
|
73037
|
+
if (type === undefined || (type instanceof basic_1.TableType && type.isWithHeader())) {
|
|
73038
|
+
return undefined;
|
|
73039
|
+
}
|
|
73040
|
+
return type;
|
|
73041
|
+
}
|
|
73042
|
+
/**
|
|
73043
|
+
* The data source has the same value at the end of statement "to" as at the end of statement "from".
|
|
73044
|
+
* When "read" is given, it is the token in statement "to" that reads the value; writes of statement "to"
|
|
73045
|
+
* after its sources are evaluated, ie. the target of a MOVE or the call after evaluating its receiver, do not count.
|
|
73046
|
+
*/
|
|
73047
|
+
function unchangedBetween(procedure, source, from, to, read) {
|
|
73048
|
+
if (source.kind === SourceKind.Immutable) {
|
|
73049
|
+
return true;
|
|
73050
|
+
}
|
|
73051
|
+
const start = procedure.index(from);
|
|
73052
|
+
const end = procedure.index(to);
|
|
73053
|
+
if (start < 0 || end < start) {
|
|
73054
|
+
return false;
|
|
73055
|
+
}
|
|
73056
|
+
if (source.base !== undefined && (source.base.escapes()
|
|
73057
|
+
|| source.base.writes().some(w => w.index > start && w.index <= end))) {
|
|
73058
|
+
return false;
|
|
73059
|
+
}
|
|
73060
|
+
if (source.kind === SourceKind.Local) {
|
|
73061
|
+
return source.base !== undefined;
|
|
73062
|
+
}
|
|
73063
|
+
for (let index = start + 1; index <= end; index++) {
|
|
73064
|
+
const statement = procedure.statements[index];
|
|
73065
|
+
if (index === end && read !== undefined) {
|
|
73066
|
+
if (isReceiver(statement, read)
|
|
73067
|
+
|| (statement.get() instanceof Statements.Move && procedure.isCallFree(statement))) {
|
|
73068
|
+
continue;
|
|
73069
|
+
}
|
|
73070
|
+
}
|
|
73071
|
+
if (!procedure.isCallFree(statement) || !procedure.writesOnlyPrivate(statement)) {
|
|
73072
|
+
return false;
|
|
73073
|
+
}
|
|
73074
|
+
}
|
|
73075
|
+
return true;
|
|
73076
|
+
}
|
|
73077
|
+
/** the token is the receiver of the method call chain of the statement: a->m( ). or x = a->m( ).
|
|
73078
|
+
* The receiver is evaluated before the arguments and the call */
|
|
73079
|
+
function isReceiver(statement, token) {
|
|
73080
|
+
var _a, _b;
|
|
73081
|
+
let chain;
|
|
73082
|
+
if (statement.get() instanceof Statements.Call) {
|
|
73083
|
+
chain = statement.findDirectExpression(Expressions.MethodCallChain);
|
|
73084
|
+
}
|
|
73085
|
+
else if (((_a = plainMove(statement)) === null || _a === void 0 ? void 0 : _a.source.getChildren().length) === 1) {
|
|
73086
|
+
chain = plainMove(statement).source.findDirectExpression(Expressions.MethodCallChain);
|
|
73087
|
+
}
|
|
73088
|
+
const receiver = chain === null || chain === void 0 ? void 0 : chain.getChildren()[0];
|
|
73089
|
+
return receiver instanceof nodes_1.ExpressionNode && receiver.get() instanceof Expressions.FieldChain
|
|
73090
|
+
&& receiver.countTokens() === 1 && receiver.getFirstToken().getStart().equals(token.getStart())
|
|
73091
|
+
&& ((_b = chain === null || chain === void 0 ? void 0 : chain.getChildren()[1]) === null || _b === void 0 ? void 0 : _b.getFirstToken().getStr()) === "->";
|
|
73092
|
+
}
|
|
73093
|
+
////////////////////////////////////////
|
|
73094
|
+
// edits
|
|
73095
|
+
const rowCache = new WeakMap();
|
|
73096
|
+
/** getRawRows() splits the source on every call; a file is never changed, edits create a new one */
|
|
73097
|
+
function rowsOf(file) {
|
|
73098
|
+
let rows = rowCache.get(file);
|
|
73099
|
+
if (rows === undefined) {
|
|
73100
|
+
rows = file.getRawRows();
|
|
73101
|
+
rowCache.set(file, rows);
|
|
73102
|
+
}
|
|
73103
|
+
return rows;
|
|
73104
|
+
}
|
|
73105
|
+
/** edits of one fix, sorted so that applying them one after the other keeps the positions valid */
|
|
73106
|
+
function mergeEdits(file, edits) {
|
|
73107
|
+
const list = [];
|
|
73108
|
+
for (const edit of edits) {
|
|
73109
|
+
list.push(...edit[file.getFilename()] || []);
|
|
73110
|
+
}
|
|
73111
|
+
list.sort((a, b) => {
|
|
73112
|
+
if (a.range.start.equals(b.range.start)) {
|
|
73113
|
+
return 0;
|
|
73114
|
+
}
|
|
73115
|
+
return a.range.start.isAfter(b.range.start) ? -1 : 1;
|
|
73116
|
+
});
|
|
73117
|
+
return { [file.getFilename()]: list };
|
|
73118
|
+
}
|
|
73119
|
+
/** deletes the statements from first to last, the full lines if nothing else is on them */
|
|
73120
|
+
function deleteRegion(file, first, last) {
|
|
73121
|
+
if (first === last && first.getColon() !== undefined) {
|
|
73122
|
+
return edit_helper_1.EditHelper.deleteStatement(file, first);
|
|
73123
|
+
}
|
|
73124
|
+
const rows = rowsOf(file);
|
|
73125
|
+
const start = first.getStart();
|
|
73126
|
+
const end = last.getEnd();
|
|
73127
|
+
const before = rows[start.getRow() - 1].substring(0, start.getCol() - 1);
|
|
73128
|
+
const after = rows[end.getRow() - 1].substring(end.getCol() - 1);
|
|
73129
|
+
if (before.trim() === "" && after.trim() === "" && end.getRow() < rows.length) {
|
|
73130
|
+
return edit_helper_1.EditHelper.deleteRange(file, new position_1.Position(start.getRow(), 1), new position_1.Position(end.getRow() + 1, 1));
|
|
73131
|
+
}
|
|
73132
|
+
return edit_helper_1.EditHelper.deleteRange(file, start, end);
|
|
73133
|
+
}
|
|
73134
|
+
function deleteStatement(file, statement) {
|
|
73135
|
+
return deleteRegion(file, statement, statement);
|
|
73136
|
+
}
|
|
73137
|
+
/** the source code between two positions, as written */
|
|
73138
|
+
function rawText(file, start, end) {
|
|
73139
|
+
const rows = rowsOf(file);
|
|
73140
|
+
if (start.getRow() === end.getRow()) {
|
|
73141
|
+
return rows[start.getRow() - 1].substring(start.getCol() - 1, end.getCol() - 1);
|
|
73142
|
+
}
|
|
73143
|
+
const ret = [rows[start.getRow() - 1].substring(start.getCol() - 1)];
|
|
73144
|
+
for (let row = start.getRow() + 1; row < end.getRow(); row++) {
|
|
73145
|
+
ret.push(rows[row - 1]);
|
|
73146
|
+
}
|
|
73147
|
+
ret.push(rows[end.getRow() - 1].substring(0, end.getCol() - 1));
|
|
73148
|
+
return ret.join("\n");
|
|
73149
|
+
}
|
|
73150
|
+
function nodeText(file, node) {
|
|
73151
|
+
return rawText(file, node.getFirstToken().getStart(), node.getLastToken().getEnd());
|
|
73152
|
+
}
|
|
73153
|
+
/** the IF, ELSEIF and ELSE branches of an IF structure */
|
|
73154
|
+
function ifBranches(structure) {
|
|
73155
|
+
const branches = [];
|
|
73156
|
+
for (const child of structure.getChildren()) {
|
|
73157
|
+
if (child instanceof nodes_1.StatementNode) {
|
|
73158
|
+
if (child.get() instanceof Statements.If) {
|
|
73159
|
+
branches.push({ statement: child, body: undefined });
|
|
73160
|
+
}
|
|
73161
|
+
}
|
|
73162
|
+
else if (child.get() instanceof Structures.Body) {
|
|
73163
|
+
if (branches.length !== 1) {
|
|
73164
|
+
return undefined;
|
|
73165
|
+
}
|
|
73166
|
+
branches[0].body = child;
|
|
73167
|
+
}
|
|
73168
|
+
else if (child.get() instanceof Structures.ElseIf || child.get() instanceof Structures.Else) {
|
|
73169
|
+
const statement = child.getFirstStatement();
|
|
73170
|
+
if (statement === undefined) {
|
|
73171
|
+
return undefined;
|
|
73172
|
+
}
|
|
73173
|
+
branches.push({ statement, body: child.findDirectStructure(Structures.Body) });
|
|
73174
|
+
}
|
|
73175
|
+
}
|
|
73176
|
+
return branches.length > 0 ? branches : undefined;
|
|
73177
|
+
}
|
|
73178
|
+
/** a region of statements can be deleted if nothing declared in it is used outside of it */
|
|
73179
|
+
function selfContained(procedure, first, last) {
|
|
73180
|
+
const filename = procedure.file.getFilename();
|
|
73181
|
+
const start = first.getStart();
|
|
73182
|
+
const end = last.getEnd();
|
|
73183
|
+
const inside = (identifier) => identifier.getFilename() === filename
|
|
73184
|
+
&& !identifier.getStart().isBefore(start) && !identifier.getStart().isAfter(end);
|
|
73185
|
+
for (const [resolved, references] of procedure.ownReferences()) {
|
|
73186
|
+
if (inside(resolved) && references.some(r => !inside(r.position))) {
|
|
73187
|
+
return false;
|
|
73188
|
+
}
|
|
73189
|
+
}
|
|
73190
|
+
return true;
|
|
73191
|
+
}
|
|
73192
|
+
/**
|
|
73193
|
+
* Removes an IF branch whose condition is known.
|
|
73194
|
+
* decided: the IF or ELSEIF statement whose condition always has the given value.
|
|
73195
|
+
* Returns undefined if a removed branch declares something used outside of it.
|
|
73196
|
+
*/
|
|
73197
|
+
function foldIf(procedure, structure, decided, value) {
|
|
73198
|
+
var _a;
|
|
73199
|
+
const file = procedure.file;
|
|
73200
|
+
const branches = ifBranches(structure);
|
|
73201
|
+
const endIf = structure.findDirectStatement(Statements.EndIf);
|
|
73202
|
+
const k = (_a = branches === null || branches === void 0 ? void 0 : branches.findIndex(b => b.statement === decided)) !== null && _a !== void 0 ? _a : -1;
|
|
73203
|
+
if (branches === undefined || endIf === undefined || k < 0
|
|
73204
|
+
|| branches[k].statement.get() instanceof Statements.Else
|
|
73205
|
+
|| structure.getChildren().some(c => c instanceof nodes_1.StatementNode && c.getColon() !== undefined)
|
|
73206
|
+
|| branches.some(b => b.statement.getColon() !== undefined)) {
|
|
73207
|
+
return undefined;
|
|
73208
|
+
}
|
|
73209
|
+
const lastOf = (index) => {
|
|
73210
|
+
var _a;
|
|
73211
|
+
const statements = ((_a = branches[index].body) === null || _a === void 0 ? void 0 : _a.findAllStatementNodes()) || [];
|
|
73212
|
+
return statements.length > 0 ? statements[statements.length - 1] : branches[index].statement;
|
|
73213
|
+
};
|
|
73214
|
+
const dead = (from, to) => {
|
|
73215
|
+
// branches from..to are removed, including their statements
|
|
73216
|
+
return selfContained(procedure, branches[from].statement, lastOf(to));
|
|
73217
|
+
};
|
|
73218
|
+
const last = branches.length - 1;
|
|
73219
|
+
const edits = [];
|
|
73220
|
+
if (value === true) {
|
|
73221
|
+
if (k < last && !dead(k + 1, last)) {
|
|
73222
|
+
return undefined;
|
|
73223
|
+
}
|
|
73224
|
+
if (k === 0) {
|
|
73225
|
+
edits.push(deleteStatement(file, branches[0].statement));
|
|
73226
|
+
edits.push(k < last ? deleteRegion(file, branches[k + 1].statement, endIf) : deleteStatement(file, endIf));
|
|
73227
|
+
}
|
|
73228
|
+
else {
|
|
73229
|
+
edits.push(edit_helper_1.EditHelper.replaceRange(file, decided.getStart(), decided.getEnd(), "ELSE."));
|
|
73230
|
+
if (k < last) {
|
|
73231
|
+
edits.push(deleteRegion(file, branches[k + 1].statement, lastOf(last)));
|
|
73232
|
+
}
|
|
73233
|
+
}
|
|
73234
|
+
}
|
|
73235
|
+
else {
|
|
73236
|
+
if (!dead(k, k)) {
|
|
73237
|
+
return undefined;
|
|
73238
|
+
}
|
|
73239
|
+
if (k === 0) {
|
|
73240
|
+
if (last === 0) {
|
|
73241
|
+
edits.push(deleteRegion(file, branches[0].statement, endIf));
|
|
73242
|
+
}
|
|
73243
|
+
else {
|
|
73244
|
+
edits.push(deleteRegion(file, branches[0].statement, lastOf(0)));
|
|
73245
|
+
const next = branches[1].statement;
|
|
73246
|
+
if (next.get() instanceof Statements.ElseIf) {
|
|
73247
|
+
edits.push(edit_helper_1.EditHelper.replaceToken(file, next.getFirstToken(), "IF"));
|
|
73248
|
+
}
|
|
73249
|
+
else {
|
|
73250
|
+
edits.push(deleteStatement(file, next));
|
|
73251
|
+
edits.push(deleteStatement(file, endIf));
|
|
73252
|
+
}
|
|
73253
|
+
}
|
|
73254
|
+
}
|
|
73255
|
+
else {
|
|
73256
|
+
edits.push(deleteRegion(file, branches[k].statement, lastOf(k)));
|
|
73257
|
+
}
|
|
73258
|
+
}
|
|
73259
|
+
return mergeEdits(file, edits);
|
|
73260
|
+
}
|
|
73261
|
+
/**
|
|
73262
|
+
* Issues for folds of IF structures. The edits of a fold inside a removed branch of another fold can not be
|
|
73263
|
+
* applied in the same round, and abaplint --fix only checks if the rows of a new fix cover the first or last row
|
|
73264
|
+
* of an accepted one. So only the outermost fold, and the first fold of an IF, keeps its quick fix; the others
|
|
73265
|
+
* are reported without, and get their fix in the next round.
|
|
73266
|
+
*/
|
|
73267
|
+
function foldIssues(file, candidates, key, severity) {
|
|
73268
|
+
const contains = (outer, inner) => !inner.getFirstToken().getStart().isBefore(outer.getFirstToken().getStart())
|
|
73269
|
+
&& !outer.getLastToken().getEnd().isBefore(inner.getLastToken().getEnd());
|
|
73270
|
+
return candidates.map((candidate, index) => {
|
|
73271
|
+
const nested = candidates.some((other, otherIndex) => other.structure === candidate.structure
|
|
73272
|
+
? otherIndex < index
|
|
73273
|
+
: contains(other.structure, candidate.structure));
|
|
73274
|
+
return issue_1.Issue.atStatement(file, candidate.statement, candidate.message, key, severity, nested ? undefined : candidate.fix);
|
|
73275
|
+
});
|
|
73276
|
+
}
|
|
73277
|
+
//# sourceMappingURL=_procedure_analysis.js.map
|
|
73278
|
+
|
|
73279
|
+
/***/ },
|
|
73280
|
+
|
|
72026
73281
|
/***/ "../core/build/src/rules/abapdoc.js"
|
|
72027
73282
|
/*!******************************************!*\
|
|
72028
73283
|
!*** ../core/build/src/rules/abapdoc.js ***!
|
|
@@ -72795,6 +74050,148 @@ exports.AFFAndXML = AFFAndXML;
|
|
|
72795
74050
|
|
|
72796
74051
|
/***/ },
|
|
72797
74052
|
|
|
74053
|
+
/***/ "../core/build/src/rules/alias_never_reassigned.js"
|
|
74054
|
+
/*!*********************************************************!*\
|
|
74055
|
+
!*** ../core/build/src/rules/alias_never_reassigned.js ***!
|
|
74056
|
+
\*********************************************************/
|
|
74057
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
74058
|
+
|
|
74059
|
+
"use strict";
|
|
74060
|
+
|
|
74061
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
74062
|
+
if (k2 === undefined) k2 = k;
|
|
74063
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
74064
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
74065
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
74066
|
+
}
|
|
74067
|
+
Object.defineProperty(o, k2, desc);
|
|
74068
|
+
}) : (function(o, m, k, k2) {
|
|
74069
|
+
if (k2 === undefined) k2 = k;
|
|
74070
|
+
o[k2] = m[k];
|
|
74071
|
+
}));
|
|
74072
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
74073
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
74074
|
+
}) : function(o, v) {
|
|
74075
|
+
o["default"] = v;
|
|
74076
|
+
});
|
|
74077
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
74078
|
+
var ownKeys = function(o) {
|
|
74079
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
74080
|
+
var ar = [];
|
|
74081
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
74082
|
+
return ar;
|
|
74083
|
+
};
|
|
74084
|
+
return ownKeys(o);
|
|
74085
|
+
};
|
|
74086
|
+
return function (mod) {
|
|
74087
|
+
if (mod && mod.__esModule) return mod;
|
|
74088
|
+
var result = {};
|
|
74089
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
74090
|
+
__setModuleDefault(result, mod);
|
|
74091
|
+
return result;
|
|
74092
|
+
};
|
|
74093
|
+
})();
|
|
74094
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
74095
|
+
exports.AliasNeverReassigned = exports.AliasNeverReassignedConf = void 0;
|
|
74096
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
74097
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
74098
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
74099
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
74100
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
74101
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
74102
|
+
class AliasNeverReassignedConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
74103
|
+
}
|
|
74104
|
+
exports.AliasNeverReassignedConf = AliasNeverReassignedConf;
|
|
74105
|
+
class AliasNeverReassigned {
|
|
74106
|
+
constructor() {
|
|
74107
|
+
this.conf = new AliasNeverReassignedConf();
|
|
74108
|
+
}
|
|
74109
|
+
getMetadata() {
|
|
74110
|
+
return {
|
|
74111
|
+
key: "alias_never_reassigned",
|
|
74112
|
+
title: "Alias never reassigned",
|
|
74113
|
+
shortDescription: `Finds DATA(a) = b. where neither a nor b changes afterwards, so b can be read instead of a`,
|
|
74114
|
+
extendedInformation: `Reports DATA(a) = b. when all of the following hold:
|
|
74115
|
+
|
|
74116
|
+
* a is a local variable of a METHOD, FORM or FUNCTION, and has at least two more references, all of them reads,
|
|
74117
|
+
which do not take its address, bind a field symbol to it, or pass it to USING, CHANGING or EXPORTING
|
|
74118
|
+
* b is a local variable, or a component of one, whose address is never taken and which is not written
|
|
74119
|
+
after the declaration of a; or b is a constant or me
|
|
74120
|
+
* the declaration is executed before every read on every path: each read is in the block of the declaration
|
|
74121
|
+
or a nested block
|
|
74122
|
+
|
|
74123
|
+
a has the type of b, so reading b instead does not change any conversion.
|
|
74124
|
+
A constant b read in IF, ELSEIF, WHILE, CHECK, CASE or WHEN is not reported, see constant_condition.
|
|
74125
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
74126
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
74127
|
+
|
|
74128
|
+
The quick fix deletes the declaration and replaces every read of a with b. No release requirement.
|
|
74129
|
+
|
|
74130
|
+
See also unnecessary_copy for copies that are read once, also of attributes and parameters.`,
|
|
74131
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
74132
|
+
badExample: `DATA(lo_file) = lo_input.
|
|
74133
|
+
lo_file->read( ).
|
|
74134
|
+
rv_name = lo_file->get_name( ).`,
|
|
74135
|
+
goodExample: `lo_input->read( ).
|
|
74136
|
+
rv_name = lo_input->get_name( ).`,
|
|
74137
|
+
};
|
|
74138
|
+
}
|
|
74139
|
+
getConfig() {
|
|
74140
|
+
return this.conf;
|
|
74141
|
+
}
|
|
74142
|
+
setConfig(conf) {
|
|
74143
|
+
this.conf = conf;
|
|
74144
|
+
}
|
|
74145
|
+
initialize(reg) {
|
|
74146
|
+
this.reg = reg;
|
|
74147
|
+
return this;
|
|
74148
|
+
}
|
|
74149
|
+
run(obj) {
|
|
74150
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
74151
|
+
if (analysis === undefined) {
|
|
74152
|
+
return [];
|
|
74153
|
+
}
|
|
74154
|
+
const issues = [];
|
|
74155
|
+
for (const procedure of analysis.procedures) {
|
|
74156
|
+
if (procedure.supported === false) {
|
|
74157
|
+
continue;
|
|
74158
|
+
}
|
|
74159
|
+
for (const variable of procedure.locals()) {
|
|
74160
|
+
const declaration = variable.declaration;
|
|
74161
|
+
const move = variable.inline ? (0, _procedure_analysis_1.plainMove)(declaration) : undefined;
|
|
74162
|
+
const reads = variable.occurrences;
|
|
74163
|
+
if (move === undefined || move.operator !== "="
|
|
74164
|
+
|| move.target.getChildren().length !== 1
|
|
74165
|
+
|| move.target.findDirectExpression(Expressions.InlineData) === undefined
|
|
74166
|
+
|| reads.length < 2 || reads.some(r => r.kind !== _procedure_analysis_1.OccurrenceKind.Read)
|
|
74167
|
+
|| reads.some(r => !procedure.dominates(declaration, r.statement))) {
|
|
74168
|
+
continue;
|
|
74169
|
+
}
|
|
74170
|
+
const source = (0, _procedure_analysis_1.dataSource)(procedure, move.source);
|
|
74171
|
+
if (source === undefined || source.base === variable
|
|
74172
|
+
|| (source.kind === _procedure_analysis_1.SourceKind.Immutable && reads.some(r => (0, _procedure_analysis_1.isCondition)(r.statement)))
|
|
74173
|
+
|| (source.kind === _procedure_analysis_1.SourceKind.Local
|
|
74174
|
+
&& (source.base.escapes() || source.base.writes().some(w => w.index >= procedure.index(declaration))))
|
|
74175
|
+
|| source.kind === _procedure_analysis_1.SourceKind.Volatile) {
|
|
74176
|
+
continue;
|
|
74177
|
+
}
|
|
74178
|
+
const edits = [(0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)];
|
|
74179
|
+
for (const read of reads) {
|
|
74180
|
+
edits.push(edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, source.text));
|
|
74181
|
+
}
|
|
74182
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
|
|
74183
|
+
const message = variable.identifier.getName() + " is a copy of " + source.text + ", and neither changes";
|
|
74184
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, declaration, message, this.getMetadata().key, this.conf.severity, fix));
|
|
74185
|
+
}
|
|
74186
|
+
}
|
|
74187
|
+
return issues;
|
|
74188
|
+
}
|
|
74189
|
+
}
|
|
74190
|
+
exports.AliasNeverReassigned = AliasNeverReassigned;
|
|
74191
|
+
//# sourceMappingURL=alias_never_reassigned.js.map
|
|
74192
|
+
|
|
74193
|
+
/***/ },
|
|
74194
|
+
|
|
72798
74195
|
/***/ "../core/build/src/rules/align_parameters.js"
|
|
72799
74196
|
/*!***************************************************!*\
|
|
72800
74197
|
!*** ../core/build/src/rules/align_parameters.js ***!
|
|
@@ -74278,10 +75675,10 @@ exports.BeginSingleInclude = BeginSingleInclude;
|
|
|
74278
75675
|
|
|
74279
75676
|
/***/ },
|
|
74280
75677
|
|
|
74281
|
-
/***/ "../core/build/src/rules/
|
|
74282
|
-
|
|
74283
|
-
!*** ../core/build/src/rules/
|
|
74284
|
-
|
|
75678
|
+
/***/ "../core/build/src/rules/boolean_flag_via_if.js"
|
|
75679
|
+
/*!******************************************************!*\
|
|
75680
|
+
!*** ../core/build/src/rules/boolean_flag_via_if.js ***!
|
|
75681
|
+
\******************************************************/
|
|
74285
75682
|
(__unused_webpack_module, exports, __webpack_require__) {
|
|
74286
75683
|
|
|
74287
75684
|
"use strict";
|
|
@@ -74320,73 +75717,530 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
74320
75717
|
};
|
|
74321
75718
|
})();
|
|
74322
75719
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
74323
|
-
exports.
|
|
74324
|
-
const
|
|
74325
|
-
const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
|
|
74326
|
-
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
75720
|
+
exports.BooleanFlagViaIf = exports.BooleanFlagViaIfConf = void 0;
|
|
75721
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
74327
75722
|
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
75723
|
+
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
75724
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
74328
75725
|
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
74329
75726
|
const version_1 = __webpack_require__(/*! ../version */ "../core/build/src/version.js");
|
|
74330
|
-
|
|
75727
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
75728
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
75729
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
75730
|
+
class BooleanFlagViaIfConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
74331
75731
|
}
|
|
74332
|
-
exports.
|
|
74333
|
-
class
|
|
75732
|
+
exports.BooleanFlagViaIfConf = BooleanFlagViaIfConf;
|
|
75733
|
+
class BooleanFlagViaIf {
|
|
74334
75734
|
constructor() {
|
|
74335
|
-
|
|
74336
|
-
this.conf = new CallTransactionAuthorityCheckConf();
|
|
74337
|
-
this.MINIMUM_VERSION = version_1.Release.v740sp02;
|
|
75735
|
+
this.conf = new BooleanFlagViaIfConf();
|
|
74338
75736
|
}
|
|
74339
75737
|
getMetadata() {
|
|
74340
75738
|
return {
|
|
74341
|
-
key: "
|
|
74342
|
-
title: "
|
|
74343
|
-
shortDescription: `
|
|
74344
|
-
extendedInformation: `
|
|
74345
|
-
|
|
74346
|
-
|
|
74347
|
-
|
|
74348
|
-
|
|
74349
|
-
|
|
74350
|
-
|
|
75739
|
+
key: "boolean_flag_via_if",
|
|
75740
|
+
title: "Boolean flag via IF",
|
|
75741
|
+
shortDescription: `Finds a flag that is initialized to false and set to true in a single IF, use xsdbool`,
|
|
75742
|
+
extendedInformation: `Reports DATA(f) = VALUE abap_bool( )., DATA(f) = abap_false. or DATA f TYPE abap_bool.,
|
|
75743
|
+
later followed by IF cond. f = abap_true. ENDIF., when all of the following hold:
|
|
75744
|
+
|
|
75745
|
+
* f is a local variable of a METHOD, FORM or FUNCTION, of type c LENGTH 1, its address is never taken
|
|
75746
|
+
* the IF has no ELSEIF and no ELSE, its only statement is f = abap_true. and it contains no comments
|
|
75747
|
+
* f has no other write, and is not read before the IF
|
|
75748
|
+
* the IF is in the same block and the same loop as the declaration; DATA f TYPE abap_bool. is not
|
|
75749
|
+
executed per loop iteration, so neither it nor the IF may be in a loop
|
|
75750
|
+
|
|
75751
|
+
Requires xsdbool, ie. 7.40 SP08 or above, ABAP Cloud or open-abap.
|
|
75752
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
75753
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
75754
|
+
|
|
75755
|
+
The quick fix deletes an inline declaration and replaces the IF with DATA(f) = xsdbool( cond ).,
|
|
75756
|
+
or keeps DATA f TYPE abap_bool. and replaces the IF with f = xsdbool( cond ).
|
|
75757
|
+
|
|
75758
|
+
use_bool_expression covers IF with an ELSE branch, without looking at the declaration and the other uses.`,
|
|
75759
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
75760
|
+
badExample: `DATA(lv_found) = abap_false.
|
|
75761
|
+
IF line_exists( lt_rows[ id = lv_id ] ).
|
|
75762
|
+
lv_found = abap_true.
|
|
75763
|
+
ENDIF.`,
|
|
75764
|
+
goodExample: `DATA(lv_found) = xsdbool( line_exists( lt_rows[ id = lv_id ] ) ).`,
|
|
74351
75765
|
};
|
|
74352
75766
|
}
|
|
74353
|
-
getMessage() {
|
|
74354
|
-
return "Add an authority check to CALL TRANSACTION";
|
|
74355
|
-
}
|
|
74356
75767
|
getConfig() {
|
|
74357
75768
|
return this.conf;
|
|
74358
75769
|
}
|
|
74359
75770
|
setConfig(conf) {
|
|
74360
75771
|
this.conf = conf;
|
|
74361
75772
|
}
|
|
74362
|
-
|
|
74363
|
-
|
|
74364
|
-
|
|
74365
|
-
|
|
75773
|
+
initialize(reg) {
|
|
75774
|
+
this.reg = reg;
|
|
75775
|
+
return this;
|
|
75776
|
+
}
|
|
75777
|
+
run(obj) {
|
|
75778
|
+
var _a, _b;
|
|
75779
|
+
const config = this.reg.getConfig();
|
|
75780
|
+
if (!(0, version_1.releaseAtLeast)(config.getRelease(), version_1.Release.v740sp08)
|
|
75781
|
+
&& config.getLanguageVersion() !== version_1.LanguageVersion.Cloud
|
|
75782
|
+
&& !config.isOpenABAP()) {
|
|
75783
|
+
return [];
|
|
75784
|
+
}
|
|
75785
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
75786
|
+
if (analysis === undefined) {
|
|
74366
75787
|
return [];
|
|
74367
75788
|
}
|
|
74368
75789
|
const issues = [];
|
|
74369
|
-
|
|
75790
|
+
for (const procedure of analysis.procedures) {
|
|
75791
|
+
if (procedure.supported === false) {
|
|
75792
|
+
continue;
|
|
75793
|
+
}
|
|
75794
|
+
for (const variable of procedure.locals()) {
|
|
75795
|
+
const declaration = variable.declaration;
|
|
75796
|
+
const type = variable.identifier.getType();
|
|
75797
|
+
const writes = variable.writes();
|
|
75798
|
+
if (!(type instanceof basic_1.CharacterType) || type.getLength() !== 1 || variable.escapes()
|
|
75799
|
+
|| writes.length !== 1 || !this.initiallyFalse(procedure, variable.inline, declaration)) {
|
|
75800
|
+
continue;
|
|
75801
|
+
}
|
|
75802
|
+
const write = writes[0];
|
|
75803
|
+
const move = (0, _procedure_analysis_1.plainMove)(write.statement);
|
|
75804
|
+
const value = move === undefined ? undefined : (0, _procedure_analysis_1.characterConstant)(procedure, move.source);
|
|
75805
|
+
const check = procedure.statements[write.index - 1];
|
|
75806
|
+
const structure = procedure.ifStructure(check);
|
|
75807
|
+
const branches = structure === undefined ? undefined : (0, _procedure_analysis_1.ifBranches)(structure);
|
|
75808
|
+
const endIf = structure === null || structure === void 0 ? void 0 : structure.findDirectStatement(Statements.EndIf);
|
|
75809
|
+
if (move === undefined || move.operator !== "=" || value === undefined || !(0, _procedure_analysis_1.sameCharacters)(value, "X")
|
|
75810
|
+
|| ((_a = (0, _procedure_analysis_1.singleTarget)(move.target)) === null || _a === void 0 ? void 0 : _a.getStart().equals(write.token.getStart())) !== true
|
|
75811
|
+
|| !((check === null || check === void 0 ? void 0 : check.get()) instanceof Statements.If) || check.getColon() !== undefined
|
|
75812
|
+
|| structure === undefined || endIf === undefined || (branches === null || branches === void 0 ? void 0 : branches.length) !== 1
|
|
75813
|
+
|| ((_b = branches[0].body) === null || _b === void 0 ? void 0 : _b.findAllStatementNodes().length) !== 1
|
|
75814
|
+
|| procedure.block(check) !== procedure.block(declaration)
|
|
75815
|
+
|| !procedure.sameLoop(check, declaration)
|
|
75816
|
+
|| (!variable.inline && (procedure.loop(check) !== undefined || procedure.loop(declaration) !== undefined))
|
|
75817
|
+
|| variable.occurrences.some(o => o.kind === _procedure_analysis_1.OccurrenceKind.Read && o.index <= procedure.index(endIf))
|
|
75818
|
+
|| procedure.hasComment(check.getStart(), endIf.getEnd())) {
|
|
75819
|
+
continue;
|
|
75820
|
+
}
|
|
75821
|
+
const cond = check.findDirectExpression(Expressions.Cond);
|
|
75822
|
+
if (cond === undefined) {
|
|
75823
|
+
continue;
|
|
75824
|
+
}
|
|
75825
|
+
const name = write.token.getStr();
|
|
75826
|
+
const assignment = (variable.inline ? "DATA(" + name + ")" : name) + " = xsdbool( " + (0, _procedure_analysis_1.nodeText)(procedure.file, cond) + " ).";
|
|
75827
|
+
const edits = [edit_helper_1.EditHelper.replaceRange(procedure.file, check.getStart(), endIf.getEnd(), assignment)];
|
|
75828
|
+
if (variable.inline) {
|
|
75829
|
+
edits.push((0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration));
|
|
75830
|
+
}
|
|
75831
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
|
|
75832
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, check, "Use xsdbool to set " + name, this.getMetadata().key, this.conf.severity, fix));
|
|
75833
|
+
}
|
|
75834
|
+
}
|
|
75835
|
+
return issues;
|
|
75836
|
+
}
|
|
75837
|
+
/** DATA(f) = VALUE abap_bool( ). DATA(f) = abap_false. or DATA f TYPE abap_bool. */
|
|
75838
|
+
initiallyFalse(procedure, inline, declaration) {
|
|
75839
|
+
if (inline === false) {
|
|
75840
|
+
return (0, _procedure_analysis_1.plainData)(declaration) && declaration.getColon() === undefined;
|
|
75841
|
+
}
|
|
75842
|
+
const move = (0, _procedure_analysis_1.plainMove)(declaration);
|
|
75843
|
+
if (move === undefined || move.operator !== "=" || move.target.getChildren().length !== 1
|
|
75844
|
+
|| move.target.findDirectExpression(Expressions.InlineData) === undefined) {
|
|
75845
|
+
return false;
|
|
75846
|
+
}
|
|
75847
|
+
const constant = (0, _procedure_analysis_1.characterConstant)(procedure, move.source);
|
|
75848
|
+
return (constant !== undefined && (0, _procedure_analysis_1.sameCharacters)(constant, "")) || this.initialValue(move.source);
|
|
75849
|
+
}
|
|
75850
|
+
/** VALUE type( ) */
|
|
75851
|
+
initialValue(source) {
|
|
75852
|
+
const tokens = source.getTokens();
|
|
75853
|
+
return tokens.length === 4 && tokens[0].getStr().toUpperCase() === "VALUE"
|
|
75854
|
+
&& source.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined
|
|
75855
|
+
&& tokens[1].getStr() !== "#" && tokens[2].getStr() === "(" && tokens[3].getStr() === ")";
|
|
75856
|
+
}
|
|
75857
|
+
}
|
|
75858
|
+
exports.BooleanFlagViaIf = BooleanFlagViaIf;
|
|
75859
|
+
//# sourceMappingURL=boolean_flag_via_if.js.map
|
|
75860
|
+
|
|
75861
|
+
/***/ },
|
|
75862
|
+
|
|
75863
|
+
/***/ "../core/build/src/rules/bound_check_after_create.js"
|
|
75864
|
+
/*!***********************************************************!*\
|
|
75865
|
+
!*** ../core/build/src/rules/bound_check_after_create.js ***!
|
|
75866
|
+
\***********************************************************/
|
|
75867
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
75868
|
+
|
|
75869
|
+
"use strict";
|
|
75870
|
+
|
|
75871
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
75872
|
+
if (k2 === undefined) k2 = k;
|
|
75873
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
75874
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
75875
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
75876
|
+
}
|
|
75877
|
+
Object.defineProperty(o, k2, desc);
|
|
75878
|
+
}) : (function(o, m, k, k2) {
|
|
75879
|
+
if (k2 === undefined) k2 = k;
|
|
75880
|
+
o[k2] = m[k];
|
|
75881
|
+
}));
|
|
75882
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
75883
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
75884
|
+
}) : function(o, v) {
|
|
75885
|
+
o["default"] = v;
|
|
75886
|
+
});
|
|
75887
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
75888
|
+
var ownKeys = function(o) {
|
|
75889
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
75890
|
+
var ar = [];
|
|
75891
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
75892
|
+
return ar;
|
|
75893
|
+
};
|
|
75894
|
+
return ownKeys(o);
|
|
75895
|
+
};
|
|
75896
|
+
return function (mod) {
|
|
75897
|
+
if (mod && mod.__esModule) return mod;
|
|
75898
|
+
var result = {};
|
|
75899
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
75900
|
+
__setModuleDefault(result, mod);
|
|
75901
|
+
return result;
|
|
75902
|
+
};
|
|
75903
|
+
})();
|
|
75904
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
75905
|
+
exports.BoundCheckAfterCreate = exports.BoundCheckAfterCreateConf = void 0;
|
|
75906
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
75907
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
75908
|
+
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
|
|
75909
|
+
const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
|
|
75910
|
+
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
75911
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
75912
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
75913
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
75914
|
+
class BoundCheckAfterCreateConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
75915
|
+
}
|
|
75916
|
+
exports.BoundCheckAfterCreateConf = BoundCheckAfterCreateConf;
|
|
75917
|
+
class BoundCheckAfterCreate {
|
|
75918
|
+
constructor() {
|
|
75919
|
+
this.conf = new BoundCheckAfterCreateConf();
|
|
75920
|
+
}
|
|
75921
|
+
getMetadata() {
|
|
75922
|
+
return {
|
|
75923
|
+
key: "bound_check_after_create",
|
|
75924
|
+
title: "Bound check after create",
|
|
75925
|
+
shortDescription: `Finds IF r IS BOUND / IS NOT BOUND directly after r was created`,
|
|
75926
|
+
extendedInformation: `Reports IF r IS BOUND. and IF r IS NOT BOUND. after CREATE OBJECT r., r = NEW ...( ). or
|
|
75927
|
+
DATA(r) = NEW ...( ). in the same block, when all of the following hold:
|
|
75928
|
+
|
|
75929
|
+
* r is a local variable whose address is never taken, or an attribute: attr, me->attr or local->attr
|
|
75930
|
+
* CREATE OBJECT has no EXCEPTIONS addition and no dynamic type, NEW is not followed by a method call
|
|
75931
|
+
* every statement in between is a direct statement of the same block, not a nested structure
|
|
75932
|
+
* a local r is not written in between
|
|
75933
|
+
* for an attribute: no method, function or form call and no constructor in between, the local before ->
|
|
75934
|
+
is not written, and no write in between can change the attribute: no write to an attribute with the
|
|
75935
|
+
same name, to a field symbol, via ->*, or to a parameter passed by reference
|
|
75936
|
+
|
|
75937
|
+
The quick fix keeps the IS BOUND branch and removes the rest, or removes the IS NOT BOUND branch;
|
|
75938
|
+
nothing is reported if a removed branch declares data that is used outside of it.
|
|
75939
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
75940
|
+
INCLUDE, test seams, enhancements or native SQL. No release requirement.`,
|
|
75941
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
75942
|
+
badExample: `CREATE OBJECT lo_log.
|
|
75943
|
+
IF lo_log IS BOUND.
|
|
75944
|
+
lo_log->add( 'started' ).
|
|
75945
|
+
ENDIF.`,
|
|
75946
|
+
goodExample: `CREATE OBJECT lo_log.
|
|
75947
|
+
lo_log->add( 'started' ).`,
|
|
75948
|
+
};
|
|
75949
|
+
}
|
|
75950
|
+
getConfig() {
|
|
75951
|
+
return this.conf;
|
|
75952
|
+
}
|
|
75953
|
+
setConfig(conf) {
|
|
75954
|
+
this.conf = conf;
|
|
75955
|
+
}
|
|
75956
|
+
initialize(reg) {
|
|
75957
|
+
this.reg = reg;
|
|
75958
|
+
return this;
|
|
75959
|
+
}
|
|
75960
|
+
run(obj) {
|
|
75961
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
75962
|
+
if (analysis === undefined) {
|
|
74370
75963
|
return [];
|
|
74371
75964
|
}
|
|
74372
|
-
|
|
74373
|
-
|
|
74374
|
-
if (
|
|
74375
|
-
|
|
75965
|
+
const issues = [];
|
|
75966
|
+
for (const procedure of analysis.procedures) {
|
|
75967
|
+
if (procedure.supported === false) {
|
|
75968
|
+
continue;
|
|
74376
75969
|
}
|
|
75970
|
+
const candidates = [];
|
|
75971
|
+
for (const statement of procedure.statements) {
|
|
75972
|
+
const predicate = (0, _procedure_analysis_1.simplePredicate)(statement);
|
|
75973
|
+
if (!(statement.get() instanceof Statements.If) || (predicate === null || predicate === void 0 ? void 0 : predicate.kind) !== _procedure_analysis_1.PredicateKind.Bound) {
|
|
75974
|
+
continue;
|
|
75975
|
+
}
|
|
75976
|
+
const checked = this.path(procedure, predicate.left);
|
|
75977
|
+
const create = checked === undefined ? undefined : this.findCreate(procedure, statement, checked);
|
|
75978
|
+
const structure = procedure.ifStructure(statement);
|
|
75979
|
+
if (create === undefined || structure === undefined) {
|
|
75980
|
+
continue;
|
|
75981
|
+
}
|
|
75982
|
+
const bound = predicate.negated === false;
|
|
75983
|
+
const fix = (0, _procedure_analysis_1.foldIf)(procedure, structure, statement, bound);
|
|
75984
|
+
if (fix === undefined) {
|
|
75985
|
+
continue;
|
|
75986
|
+
}
|
|
75987
|
+
const message = predicate.left.concatTokens() + " is always bound, it is created in line " + create.getStart().getRow();
|
|
75988
|
+
candidates.push({ structure, statement, message, fix });
|
|
75989
|
+
}
|
|
75990
|
+
issues.push(...(0, _procedure_analysis_1.foldIssues)(procedure.file, candidates, this.getMetadata().key, this.conf.severity));
|
|
74377
75991
|
}
|
|
74378
75992
|
return issues;
|
|
74379
75993
|
}
|
|
75994
|
+
/** the CREATE OBJECT or NEW before the IF in the same block, with only straight statements in between
|
|
75995
|
+
* that cannot change the reference */
|
|
75996
|
+
findCreate(procedure, check, path) {
|
|
75997
|
+
const index = procedure.index(check);
|
|
75998
|
+
const block = procedure.block(check);
|
|
75999
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
76000
|
+
const statement = procedure.statements[i];
|
|
76001
|
+
if (procedure.block(statement) !== block || !procedure.isSimple(statement)) {
|
|
76002
|
+
return undefined;
|
|
76003
|
+
}
|
|
76004
|
+
const target = this.createdTarget(statement);
|
|
76005
|
+
const created = target === undefined ? undefined : this.path(procedure, target);
|
|
76006
|
+
if (created !== undefined && this.samePath(created, path)) {
|
|
76007
|
+
const between = procedure.straightBetween(statement, check);
|
|
76008
|
+
return between !== undefined && between.every(s => this.keeps(procedure, s, path)) ? statement : undefined;
|
|
76009
|
+
}
|
|
76010
|
+
}
|
|
76011
|
+
return undefined;
|
|
76012
|
+
}
|
|
76013
|
+
/** the target of CREATE OBJECT r. or r = NEW ...( ). */
|
|
76014
|
+
createdTarget(statement) {
|
|
76015
|
+
if (statement.get() instanceof Statements.CreateObject) {
|
|
76016
|
+
if (statement.findDirectTokenByText("EXCEPTIONS") !== undefined
|
|
76017
|
+
|| statement.findFirstExpression(Expressions.Dynamic) !== undefined
|
|
76018
|
+
|| statement.getColon() !== undefined) {
|
|
76019
|
+
return undefined;
|
|
76020
|
+
}
|
|
76021
|
+
return statement.findDirectExpression(Expressions.Target);
|
|
76022
|
+
}
|
|
76023
|
+
const move = (0, _procedure_analysis_1.plainMove)(statement);
|
|
76024
|
+
const chain = move === null || move === void 0 ? void 0 : move.source.findDirectExpression(Expressions.MethodCallChain);
|
|
76025
|
+
if (move === undefined || move.operator !== "=" || move.source.getChildren().length !== 1
|
|
76026
|
+
|| (chain === null || chain === void 0 ? void 0 : chain.getChildren().length) !== 1 || chain.findDirectExpression(Expressions.NewObject) === undefined) {
|
|
76027
|
+
return undefined;
|
|
76028
|
+
}
|
|
76029
|
+
return move.target;
|
|
76030
|
+
}
|
|
76031
|
+
/** r, DATA(r), attr, me->attr or local->attr, as target or source */
|
|
76032
|
+
path(procedure, node) {
|
|
76033
|
+
var _a;
|
|
76034
|
+
let children = node.getChildren();
|
|
76035
|
+
if (node.get() instanceof Expressions.Source) {
|
|
76036
|
+
const chain = node.findDirectExpression(Expressions.FieldChain);
|
|
76037
|
+
if (children.length !== 1 || chain === undefined) {
|
|
76038
|
+
return undefined;
|
|
76039
|
+
}
|
|
76040
|
+
children = chain.getChildren();
|
|
76041
|
+
}
|
|
76042
|
+
else if (children.length === 1 && node.findDirectExpression(Expressions.InlineData) !== undefined) {
|
|
76043
|
+
const name = node.findDirectExpression(Expressions.InlineData).findDirectExpression(Expressions.TargetField);
|
|
76044
|
+
const local = name === undefined ? undefined : procedure.local(procedure.identifierAt(name.getFirstToken()));
|
|
76045
|
+
return local === undefined || local.escapes() ? undefined : { local, attribute: undefined };
|
|
76046
|
+
}
|
|
76047
|
+
const first = procedure.identifierAt((_a = children[0]) === null || _a === void 0 ? void 0 : _a.getFirstToken());
|
|
76048
|
+
if (!(children[0] instanceof nodes_1.ExpressionNode) || !(first instanceof _typed_identifier_1.TypedIdentifier)) {
|
|
76049
|
+
return undefined;
|
|
76050
|
+
}
|
|
76051
|
+
const local = procedure.local(first);
|
|
76052
|
+
if (children.length === 1) {
|
|
76053
|
+
if (local !== undefined) {
|
|
76054
|
+
return local.escapes() ? undefined : { local, attribute: undefined };
|
|
76055
|
+
}
|
|
76056
|
+
return this.isAttribute(procedure, first) ? { local: undefined, attribute: first } : undefined;
|
|
76057
|
+
}
|
|
76058
|
+
const attribute = children[2] instanceof nodes_1.ExpressionNode && children[2].get() instanceof Expressions.AttributeName
|
|
76059
|
+
? procedure.identifierAt(children[2].getFirstToken()) : undefined;
|
|
76060
|
+
if (children.length !== 3 || !(children[1] instanceof nodes_1.TokenNode) || children[1].getFirstToken().getStr() !== "->"
|
|
76061
|
+
|| attribute === undefined || !this.isAttribute(procedure, attribute)) {
|
|
76062
|
+
return undefined;
|
|
76063
|
+
}
|
|
76064
|
+
if ((0, _procedure_analysis_1.isImmutable)(first) && first.getType() instanceof basic_1.ObjectReferenceType) {
|
|
76065
|
+
return { local: undefined, attribute };
|
|
76066
|
+
}
|
|
76067
|
+
else if (local !== undefined && !local.escapes()) {
|
|
76068
|
+
return { local, attribute };
|
|
76069
|
+
}
|
|
76070
|
+
return undefined;
|
|
76071
|
+
}
|
|
76072
|
+
isAttribute(procedure, identifier) {
|
|
76073
|
+
if (!(identifier instanceof _typed_identifier_1.TypedIdentifier) || identifier.getMeta().includes("static" /* IdentifierMeta.Static */)
|
|
76074
|
+
|| procedure.contains(identifier)) {
|
|
76075
|
+
return false;
|
|
76076
|
+
}
|
|
76077
|
+
const meta = identifier.getMeta();
|
|
76078
|
+
return !meta.some(m => m === "importing" /* IdentifierMeta.MethodImporting */ || m === "exporting" /* IdentifierMeta.MethodExporting */
|
|
76079
|
+
|| m === "changing" /* IdentifierMeta.MethodChanging */ || m === "returning" /* IdentifierMeta.MethodReturning */
|
|
76080
|
+
|| m === "form_parameter" /* IdentifierMeta.FormParameter */ || m === "event_parameter" /* IdentifierMeta.EventParameter */
|
|
76081
|
+
|| m === "function_module_importing" /* IdentifierMeta.FunctionModuleImporting */ || m === "function_module_exporting" /* IdentifierMeta.FunctionModuleExporting */
|
|
76082
|
+
|| m === "function_module_changing" /* IdentifierMeta.FunctionModuleChanging */ || m === "function_module_tables" /* IdentifierMeta.FunctionModuleTables */
|
|
76083
|
+
|| m === "built-in" /* IdentifierMeta.BuiltIn */ || m === "inline" /* IdentifierMeta.InlineDefinition */);
|
|
76084
|
+
}
|
|
76085
|
+
samePath(a, b) {
|
|
76086
|
+
const key = (i) => i === undefined ? "" : _procedure_analysis_1.ObjectAnalysis.key(i);
|
|
76087
|
+
return a.local === b.local && key(a.attribute) === key(b.attribute);
|
|
76088
|
+
}
|
|
76089
|
+
/** the statement between the create and the check cannot change the reference */
|
|
76090
|
+
keeps(procedure, statement, path) {
|
|
76091
|
+
const index = procedure.index(statement);
|
|
76092
|
+
if (path.local !== undefined && path.local.writes().some(w => w.index === index)) {
|
|
76093
|
+
return false;
|
|
76094
|
+
}
|
|
76095
|
+
if (path.attribute === undefined) {
|
|
76096
|
+
return true;
|
|
76097
|
+
}
|
|
76098
|
+
if (!procedure.isCallFree(statement)) {
|
|
76099
|
+
return false;
|
|
76100
|
+
}
|
|
76101
|
+
const attribute = _procedure_analysis_1.ObjectAnalysis.key(path.attribute);
|
|
76102
|
+
for (const target of statement.findAllExpressionsRecursive(Expressions.Target)) {
|
|
76103
|
+
if (target.findFirstExpression(Expressions.TargetFieldSymbol) !== undefined
|
|
76104
|
+
|| target.findFirstExpression(Expressions.Dereference) !== undefined) {
|
|
76105
|
+
return false;
|
|
76106
|
+
}
|
|
76107
|
+
if (target.findDirectExpression(Expressions.InlineData) !== undefined) {
|
|
76108
|
+
continue;
|
|
76109
|
+
}
|
|
76110
|
+
// the storage changed is inside the last attribute of the chain, or inside the first field
|
|
76111
|
+
const attributes = target.findDirectExpressions(Expressions.AttributeName);
|
|
76112
|
+
const field = attributes.length > 0 ? attributes[attributes.length - 1] : target.findDirectExpression(Expressions.TargetField);
|
|
76113
|
+
const changed = field === undefined ? undefined : procedure.identifierAt(field.getFirstToken());
|
|
76114
|
+
if (!(changed instanceof _typed_identifier_1.TypedIdentifier) || _procedure_analysis_1.ObjectAnalysis.key(changed) === attribute) {
|
|
76115
|
+
return false;
|
|
76116
|
+
}
|
|
76117
|
+
const meta = changed.getMeta();
|
|
76118
|
+
const variable = procedure.variable(changed);
|
|
76119
|
+
const parameter = !procedure.contains(changed) && !this.isAttribute(procedure, changed);
|
|
76120
|
+
if (parameter && !meta.includes("pass_by_value" /* IdentifierMeta.PassByValue */) && !meta.includes("returning" /* IdentifierMeta.MethodReturning */)) {
|
|
76121
|
+
return false;
|
|
76122
|
+
}
|
|
76123
|
+
else if ((variable === null || variable === void 0 ? void 0 : variable.isLocal()) === true && variable.escapes()) {
|
|
76124
|
+
return false;
|
|
76125
|
+
}
|
|
76126
|
+
}
|
|
76127
|
+
return true;
|
|
76128
|
+
}
|
|
74380
76129
|
}
|
|
74381
|
-
exports.
|
|
74382
|
-
//# sourceMappingURL=
|
|
76130
|
+
exports.BoundCheckAfterCreate = BoundCheckAfterCreate;
|
|
76131
|
+
//# sourceMappingURL=bound_check_after_create.js.map
|
|
74383
76132
|
|
|
74384
76133
|
/***/ },
|
|
74385
76134
|
|
|
74386
|
-
/***/ "../core/build/src/rules/
|
|
74387
|
-
|
|
74388
|
-
!*** ../core/build/src/rules/
|
|
74389
|
-
|
|
76135
|
+
/***/ "../core/build/src/rules/call_transaction_authority_check.js"
|
|
76136
|
+
/*!*******************************************************************!*\
|
|
76137
|
+
!*** ../core/build/src/rules/call_transaction_authority_check.js ***!
|
|
76138
|
+
\*******************************************************************/
|
|
76139
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
76140
|
+
|
|
76141
|
+
"use strict";
|
|
76142
|
+
|
|
76143
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
76144
|
+
if (k2 === undefined) k2 = k;
|
|
76145
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
76146
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
76147
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
76148
|
+
}
|
|
76149
|
+
Object.defineProperty(o, k2, desc);
|
|
76150
|
+
}) : (function(o, m, k, k2) {
|
|
76151
|
+
if (k2 === undefined) k2 = k;
|
|
76152
|
+
o[k2] = m[k];
|
|
76153
|
+
}));
|
|
76154
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
76155
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
76156
|
+
}) : function(o, v) {
|
|
76157
|
+
o["default"] = v;
|
|
76158
|
+
});
|
|
76159
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
76160
|
+
var ownKeys = function(o) {
|
|
76161
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
76162
|
+
var ar = [];
|
|
76163
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
76164
|
+
return ar;
|
|
76165
|
+
};
|
|
76166
|
+
return ownKeys(o);
|
|
76167
|
+
};
|
|
76168
|
+
return function (mod) {
|
|
76169
|
+
if (mod && mod.__esModule) return mod;
|
|
76170
|
+
var result = {};
|
|
76171
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
76172
|
+
__setModuleDefault(result, mod);
|
|
76173
|
+
return result;
|
|
76174
|
+
};
|
|
76175
|
+
})();
|
|
76176
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
76177
|
+
exports.CallTransactionAuthorityCheck = exports.CallTransactionAuthorityCheckConf = void 0;
|
|
76178
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
76179
|
+
const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
|
|
76180
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
76181
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
76182
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
76183
|
+
const version_1 = __webpack_require__(/*! ../version */ "../core/build/src/version.js");
|
|
76184
|
+
class CallTransactionAuthorityCheckConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
76185
|
+
}
|
|
76186
|
+
exports.CallTransactionAuthorityCheckConf = CallTransactionAuthorityCheckConf;
|
|
76187
|
+
class CallTransactionAuthorityCheck extends _abap_rule_1.ABAPRule {
|
|
76188
|
+
constructor() {
|
|
76189
|
+
super(...arguments);
|
|
76190
|
+
this.conf = new CallTransactionAuthorityCheckConf();
|
|
76191
|
+
this.MINIMUM_VERSION = version_1.Release.v740sp02;
|
|
76192
|
+
}
|
|
76193
|
+
getMetadata() {
|
|
76194
|
+
return {
|
|
76195
|
+
key: "call_transaction_authority_check",
|
|
76196
|
+
title: "Call Transaction Authority-Check",
|
|
76197
|
+
shortDescription: `Checks that usages of CALL TRANSACTION contain an authority-check.`,
|
|
76198
|
+
extendedInformation: `https://docs.abapopenchecks.org/checks/54/`,
|
|
76199
|
+
tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Security],
|
|
76200
|
+
badExample: `CALL TRANSACTION 'FOO'.`,
|
|
76201
|
+
goodExample: `TRY.
|
|
76202
|
+
CALL TRANSACTION 'FOO' WITH AUTHORITY-CHECK.
|
|
76203
|
+
CATCH cx_sy_authorization_error.
|
|
76204
|
+
ENDTRY.`,
|
|
76205
|
+
};
|
|
76206
|
+
}
|
|
76207
|
+
getMessage() {
|
|
76208
|
+
return "Add an authority check to CALL TRANSACTION";
|
|
76209
|
+
}
|
|
76210
|
+
getConfig() {
|
|
76211
|
+
return this.conf;
|
|
76212
|
+
}
|
|
76213
|
+
setConfig(conf) {
|
|
76214
|
+
this.conf = conf;
|
|
76215
|
+
}
|
|
76216
|
+
runParsed(file, obj) {
|
|
76217
|
+
// Cloud version does not support CALL TRANSACTION
|
|
76218
|
+
if (!(0, version_1.releaseAtLeast)(this.reg.getConfig().getRelease(), this.MINIMUM_VERSION)
|
|
76219
|
+
|| this.reg.getConfig().getLanguageVersion() === version_1.LanguageVersion.Cloud) {
|
|
76220
|
+
return [];
|
|
76221
|
+
}
|
|
76222
|
+
const issues = [];
|
|
76223
|
+
if (obj.getType() === "INTF") {
|
|
76224
|
+
return [];
|
|
76225
|
+
}
|
|
76226
|
+
for (const statNode of file.getStatements()) {
|
|
76227
|
+
const statement = statNode.get();
|
|
76228
|
+
if (statement instanceof Statements.CallTransaction && !statNode.concatTokensWithoutStringsAndComments().toUpperCase().includes("WITH AUTHORITY-CHECK")) {
|
|
76229
|
+
issues.push(issue_1.Issue.atStatement(file, statNode, this.getMessage(), this.getMetadata().key, this.getConfig().severity));
|
|
76230
|
+
}
|
|
76231
|
+
}
|
|
76232
|
+
return issues;
|
|
76233
|
+
}
|
|
76234
|
+
}
|
|
76235
|
+
exports.CallTransactionAuthorityCheck = CallTransactionAuthorityCheck;
|
|
76236
|
+
//# sourceMappingURL=call_transaction_authority_check.js.map
|
|
76237
|
+
|
|
76238
|
+
/***/ },
|
|
76239
|
+
|
|
76240
|
+
/***/ "../core/build/src/rules/catch_and_raise.js"
|
|
76241
|
+
/*!**************************************************!*\
|
|
76242
|
+
!*** ../core/build/src/rules/catch_and_raise.js ***!
|
|
76243
|
+
\**************************************************/
|
|
74390
76244
|
(__unused_webpack_module, exports, __webpack_require__) {
|
|
74391
76245
|
|
|
74392
76246
|
"use strict";
|
|
@@ -77276,6 +79130,93 @@ exports.ClassicExceptionsOverlap = ClassicExceptionsOverlap;
|
|
|
77276
79130
|
|
|
77277
79131
|
/***/ },
|
|
77278
79132
|
|
|
79133
|
+
/***/ "../core/build/src/rules/clear_after_declaration.js"
|
|
79134
|
+
/*!**********************************************************!*\
|
|
79135
|
+
!*** ../core/build/src/rules/clear_after_declaration.js ***!
|
|
79136
|
+
\**********************************************************/
|
|
79137
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
79138
|
+
|
|
79139
|
+
"use strict";
|
|
79140
|
+
|
|
79141
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
79142
|
+
exports.ClearAfterDeclaration = exports.ClearAfterDeclarationConf = void 0;
|
|
79143
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
79144
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
79145
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
79146
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
79147
|
+
class ClearAfterDeclarationConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
79148
|
+
}
|
|
79149
|
+
exports.ClearAfterDeclarationConf = ClearAfterDeclarationConf;
|
|
79150
|
+
class ClearAfterDeclaration {
|
|
79151
|
+
constructor() {
|
|
79152
|
+
this.conf = new ClearAfterDeclarationConf();
|
|
79153
|
+
}
|
|
79154
|
+
getMetadata() {
|
|
79155
|
+
return {
|
|
79156
|
+
key: "clear_after_declaration",
|
|
79157
|
+
title: "CLEAR after declaration",
|
|
79158
|
+
shortDescription: `Finds CLEAR of a local variable that is still initial since its declaration`,
|
|
79159
|
+
extendedInformation: `Reports CLEAR x. when all of the following hold:
|
|
79160
|
+
|
|
79161
|
+
* x is a local variable of a METHOD, FORM or FUNCTION, declared with DATA x TYPE/LIKE ... without VALUE
|
|
79162
|
+
* the CLEAR is the first reference to x after the declaration, it has no WITH addition
|
|
79163
|
+
* neither the DATA nor the CLEAR is inside a LOOP, DO, WHILE, SELECT loop, PROVIDE, or a TRY block with
|
|
79164
|
+
RETRY, RESUME or CATCH BEFORE UNWIND. DATA is not executed per iteration, so a CLEAR in a loop can be needed
|
|
79165
|
+
|
|
79166
|
+
Any later use of x does not matter, the CLEAR can only be reached with x still initial.
|
|
79167
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
79168
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
79169
|
+
|
|
79170
|
+
The quick fix deletes the CLEAR. No release requirement.`,
|
|
79171
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
79172
|
+
badExample: `DATA lv_count TYPE i.
|
|
79173
|
+
CLEAR lv_count.`,
|
|
79174
|
+
goodExample: `DATA lv_count TYPE i.`,
|
|
79175
|
+
};
|
|
79176
|
+
}
|
|
79177
|
+
getConfig() {
|
|
79178
|
+
return this.conf;
|
|
79179
|
+
}
|
|
79180
|
+
setConfig(conf) {
|
|
79181
|
+
this.conf = conf;
|
|
79182
|
+
}
|
|
79183
|
+
initialize(reg) {
|
|
79184
|
+
this.reg = reg;
|
|
79185
|
+
return this;
|
|
79186
|
+
}
|
|
79187
|
+
run(obj) {
|
|
79188
|
+
var _a;
|
|
79189
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
79190
|
+
if (analysis === undefined) {
|
|
79191
|
+
return [];
|
|
79192
|
+
}
|
|
79193
|
+
const issues = [];
|
|
79194
|
+
for (const procedure of analysis.procedures) {
|
|
79195
|
+
if (procedure.supported === false) {
|
|
79196
|
+
continue;
|
|
79197
|
+
}
|
|
79198
|
+
for (const variable of procedure.locals()) {
|
|
79199
|
+
const declaration = variable.declaration;
|
|
79200
|
+
const first = variable.occurrences[0];
|
|
79201
|
+
if (variable.inline || !(0, _procedure_analysis_1.plainData)(declaration) || first === undefined
|
|
79202
|
+
|| first.kind !== _procedure_analysis_1.OccurrenceKind.Write
|
|
79203
|
+
|| ((_a = (0, _procedure_analysis_1.plainClear)(first.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(first.token.getStart())) !== true
|
|
79204
|
+
|| procedure.loop(declaration) !== undefined
|
|
79205
|
+
|| procedure.loop(first.statement) !== undefined) {
|
|
79206
|
+
continue;
|
|
79207
|
+
}
|
|
79208
|
+
const fix = (0, _procedure_analysis_1.deleteStatement)(procedure.file, first.statement);
|
|
79209
|
+
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));
|
|
79210
|
+
}
|
|
79211
|
+
}
|
|
79212
|
+
return issues;
|
|
79213
|
+
}
|
|
79214
|
+
}
|
|
79215
|
+
exports.ClearAfterDeclaration = ClearAfterDeclaration;
|
|
79216
|
+
//# sourceMappingURL=clear_after_declaration.js.map
|
|
79217
|
+
|
|
79218
|
+
/***/ },
|
|
79219
|
+
|
|
77279
79220
|
/***/ "../core/build/src/rules/clear_exporting_parameters.js"
|
|
77280
79221
|
/*!*************************************************************!*\
|
|
77281
79222
|
!*** ../core/build/src/rules/clear_exporting_parameters.js ***!
|
|
@@ -77931,279 +79872,808 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
77931
79872
|
};
|
|
77932
79873
|
})();
|
|
77933
79874
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
77934
|
-
exports.ConstantClasses = exports.ConstantClassesConf = void 0;
|
|
79875
|
+
exports.ConstantClasses = exports.ConstantClassesConf = void 0;
|
|
79876
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
79877
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
79878
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
79879
|
+
const Objects = __importStar(__webpack_require__(/*! ../objects */ "../core/build/src/objects/index.js"));
|
|
79880
|
+
const visibility_1 = __webpack_require__(/*! ../abap/4_file_information/visibility */ "../core/build/src/abap/4_file_information/visibility.js");
|
|
79881
|
+
/** Checks that constants classes are in sync with domain fixed values */
|
|
79882
|
+
class ConstantClassesConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
79883
|
+
constructor() {
|
|
79884
|
+
super(...arguments);
|
|
79885
|
+
/** Specify a list of domain-class pairs which will be validated */
|
|
79886
|
+
this.mapping = [];
|
|
79887
|
+
}
|
|
79888
|
+
}
|
|
79889
|
+
exports.ConstantClassesConf = ConstantClassesConf;
|
|
79890
|
+
class ConstantClasses {
|
|
79891
|
+
constructor() {
|
|
79892
|
+
this.conf = new ConstantClassesConf();
|
|
79893
|
+
}
|
|
79894
|
+
getMetadata() {
|
|
79895
|
+
return {
|
|
79896
|
+
key: "constant_classes",
|
|
79897
|
+
title: "Validate constant classes",
|
|
79898
|
+
shortDescription: `Checks that a class contains exactly the constants corresponding to a domain's fixed values.`,
|
|
79899
|
+
extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#prefer-enum-to-constants-interfaces`,
|
|
79900
|
+
tags: [_irule_1.RuleTag.Styleguide],
|
|
79901
|
+
};
|
|
79902
|
+
}
|
|
79903
|
+
initialize(reg) {
|
|
79904
|
+
this.reg = reg;
|
|
79905
|
+
return this;
|
|
79906
|
+
}
|
|
79907
|
+
getConfig() {
|
|
79908
|
+
return this.conf;
|
|
79909
|
+
}
|
|
79910
|
+
setConfig(conf) {
|
|
79911
|
+
this.conf = conf;
|
|
79912
|
+
}
|
|
79913
|
+
run(obj) {
|
|
79914
|
+
if (this.conf
|
|
79915
|
+
&& this.conf.mapping
|
|
79916
|
+
&& obj instanceof Objects.Domain) {
|
|
79917
|
+
const configEntry = this.conf.mapping.find(x => x.domain.toUpperCase() === obj.getName().toUpperCase());
|
|
79918
|
+
if (!configEntry) {
|
|
79919
|
+
return [];
|
|
79920
|
+
}
|
|
79921
|
+
const classWithConstants = this.reg.getObject("CLAS", configEntry === null || configEntry === void 0 ? void 0 : configEntry.class.toUpperCase());
|
|
79922
|
+
if (!classWithConstants) {
|
|
79923
|
+
return [issue_1.Issue.atIdentifier(obj.getIdentifier(), `Constant class pattern implementation ${configEntry.class} missing for domain ${configEntry.domain}`, this.getMetadata().key, this.conf.severity)];
|
|
79924
|
+
// quickfix will implement the whole class
|
|
79925
|
+
}
|
|
79926
|
+
const classContents = classWithConstants.getMainABAPFile();
|
|
79927
|
+
if (classContents === undefined) {
|
|
79928
|
+
return [];
|
|
79929
|
+
}
|
|
79930
|
+
const def = classWithConstants.getClassDefinition();
|
|
79931
|
+
if (!def) {
|
|
79932
|
+
// this issue is checked by rule implement_methods.
|
|
79933
|
+
// we will not issue errors that all constants are missing until there is a class implementation
|
|
79934
|
+
return [];
|
|
79935
|
+
}
|
|
79936
|
+
const domainValueInfo = obj.getFixedValues();
|
|
79937
|
+
const domainValues = domainValueInfo.map(x => x.low);
|
|
79938
|
+
const issues = [];
|
|
79939
|
+
if (obj.getFixedValues().length === 0) {
|
|
79940
|
+
// possibly this is not even a domain with fixed values
|
|
79941
|
+
issues.push(issue_1.Issue.atStatement(classContents, classContents.getStatements()[0], `Domain ${configEntry.domain} does not contain any fixed values. Either add some values or disable this check`, this.getMetadata().key, this.conf.severity));
|
|
79942
|
+
}
|
|
79943
|
+
// later we will raise an issue if we did not find it
|
|
79944
|
+
let domainNameConstantFound = false;
|
|
79945
|
+
for (const constant of def.constants) {
|
|
79946
|
+
if (configEntry.constantForDomainName
|
|
79947
|
+
&& constant.name === configEntry.constantForDomainName) {
|
|
79948
|
+
// we require the constant value to be uppercase just in case
|
|
79949
|
+
// in the config it does not matter
|
|
79950
|
+
if (constant.value !== configEntry.domain.toLocaleUpperCase()) {
|
|
79951
|
+
issues.push(this.issueAtConstant(constant, `Constant value ${constant.value} must match domain name ${configEntry.domain} `));
|
|
79952
|
+
}
|
|
79953
|
+
domainNameConstantFound = true;
|
|
79954
|
+
continue;
|
|
79955
|
+
}
|
|
79956
|
+
if (configEntry.useExactType && constant.typeName.toLowerCase() !== configEntry.domain.toLowerCase()) {
|
|
79957
|
+
issues.push(this.issueAtConstant(constant, `Use exact type ${configEntry.domain} instead of ${constant.typeName}`));
|
|
79958
|
+
// quickfix will change the type
|
|
79959
|
+
}
|
|
79960
|
+
if (constant.visibility !== visibility_1.Visibility.Public) {
|
|
79961
|
+
issues.push(this.issueAtConstant(constant, `Constant ${constant.name} should be public`));
|
|
79962
|
+
// quickfix will move constant
|
|
79963
|
+
}
|
|
79964
|
+
if (!domainValues.includes(constant.value)) {
|
|
79965
|
+
issues.push(this.issueAtConstant(constant, `Extra constant ${constant.name} found which is not present in domain ${configEntry.domain}`));
|
|
79966
|
+
// quickfix will remove constant
|
|
79967
|
+
}
|
|
79968
|
+
}
|
|
79969
|
+
for (const d of domainValueInfo) {
|
|
79970
|
+
if (!def.constants.find(c => c.value === d.low)) {
|
|
79971
|
+
issues.push(issue_1.Issue.atStatement(classContents, classContents.getStatements()[0], `Missing constant for ${d.low} (domain ${configEntry.domain})`, this.getMetadata().key, this.conf.severity));
|
|
79972
|
+
// quickfix will add constant
|
|
79973
|
+
}
|
|
79974
|
+
}
|
|
79975
|
+
if (configEntry.constantForDomainName && !domainNameConstantFound) {
|
|
79976
|
+
issues.push(issue_1.Issue.atStatement(classContents, classContents.getStatements()[0], `Missing constant ${configEntry.constantForDomainName} for name of domain ${configEntry.domain}`, this.getMetadata().key, this.conf.severity));
|
|
79977
|
+
}
|
|
79978
|
+
return issues;
|
|
79979
|
+
}
|
|
79980
|
+
return [];
|
|
79981
|
+
}
|
|
79982
|
+
issueAtConstant(constant, message) {
|
|
79983
|
+
return issue_1.Issue.atIdentifier(constant.identifier, message, this.getMetadata().key, this.conf.severity);
|
|
79984
|
+
}
|
|
79985
|
+
}
|
|
79986
|
+
exports.ConstantClasses = ConstantClasses;
|
|
79987
|
+
//# sourceMappingURL=constant_classes.js.map
|
|
79988
|
+
|
|
79989
|
+
/***/ },
|
|
79990
|
+
|
|
79991
|
+
/***/ "../core/build/src/rules/constant_condition.js"
|
|
79992
|
+
/*!*****************************************************!*\
|
|
79993
|
+
!*** ../core/build/src/rules/constant_condition.js ***!
|
|
79994
|
+
\*****************************************************/
|
|
79995
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
79996
|
+
|
|
79997
|
+
"use strict";
|
|
79998
|
+
|
|
79999
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
80000
|
+
if (k2 === undefined) k2 = k;
|
|
80001
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
80002
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
80003
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
80004
|
+
}
|
|
80005
|
+
Object.defineProperty(o, k2, desc);
|
|
80006
|
+
}) : (function(o, m, k, k2) {
|
|
80007
|
+
if (k2 === undefined) k2 = k;
|
|
80008
|
+
o[k2] = m[k];
|
|
80009
|
+
}));
|
|
80010
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
80011
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
80012
|
+
}) : function(o, v) {
|
|
80013
|
+
o["default"] = v;
|
|
80014
|
+
});
|
|
80015
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
80016
|
+
var ownKeys = function(o) {
|
|
80017
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
80018
|
+
var ar = [];
|
|
80019
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
80020
|
+
return ar;
|
|
80021
|
+
};
|
|
80022
|
+
return ownKeys(o);
|
|
80023
|
+
};
|
|
80024
|
+
return function (mod) {
|
|
80025
|
+
if (mod && mod.__esModule) return mod;
|
|
80026
|
+
var result = {};
|
|
80027
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
80028
|
+
__setModuleDefault(result, mod);
|
|
80029
|
+
return result;
|
|
80030
|
+
};
|
|
80031
|
+
})();
|
|
80032
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80033
|
+
exports.ConstantCondition = exports.ConstantConditionConf = void 0;
|
|
80034
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
80035
|
+
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
80036
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
80037
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
80038
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
80039
|
+
class ConstantConditionConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
80040
|
+
}
|
|
80041
|
+
exports.ConstantConditionConf = ConstantConditionConf;
|
|
80042
|
+
class ConstantCondition {
|
|
80043
|
+
constructor() {
|
|
80044
|
+
this.conf = new ConstantConditionConf();
|
|
80045
|
+
}
|
|
80046
|
+
getMetadata() {
|
|
80047
|
+
return {
|
|
80048
|
+
key: "constant_condition",
|
|
80049
|
+
title: "Constant condition",
|
|
80050
|
+
shortDescription: `Finds IF and ELSEIF conditions on local variables whose value is known`,
|
|
80051
|
+
extendedInformation: `Reports two cases, for local variables of a METHOD, FORM or FUNCTION.
|
|
80052
|
+
|
|
80053
|
+
1. DATA(c) = <constant>. where the constant is a character literal like 'X', or a character constant like
|
|
80054
|
+
abap_true, abap_false or space, and the only other reference to c is the condition of an IF or ELSEIF:
|
|
80055
|
+
c = <constant>, c <> <constant>, EQ, NE, c IS INITIAL, c IS NOT INITIAL, optionally with NOT.
|
|
80056
|
+
The declaration must be executed before the condition on every path: the IF is in the block of the
|
|
80057
|
+
declaration or a nested block. The quick fix deletes the declaration.
|
|
80058
|
+
|
|
80059
|
+
2. DATA v TYPE ... without VALUE, where v is never changed, except by CLEAR v., and its address is never taken,
|
|
80060
|
+
in a condition v IS [NOT] INITIAL or v IS [NOT] BOUND. The declaration is kept.
|
|
80061
|
+
|
|
80062
|
+
The quick fix removes the IF branch that is never taken, or keeps the branch that is always taken and
|
|
80063
|
+
removes the rest, also in ELSEIF chains: a first IF branch that is never taken turns the next ELSEIF into IF,
|
|
80064
|
+
an ELSEIF branch that is always taken turns into ELSE. Nothing is reported if a removed branch declares
|
|
80065
|
+
data that is used outside of it.
|
|
80066
|
+
|
|
80067
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
80068
|
+
INCLUDE, test seams, enhancements or native SQL. No release requirement.`,
|
|
80069
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
80070
|
+
badExample: `DATA(lv_active) = abap_true.
|
|
80071
|
+
IF lv_active = abap_true.
|
|
80072
|
+
run( ).
|
|
80073
|
+
ELSE.
|
|
80074
|
+
skip( ).
|
|
80075
|
+
ENDIF.`,
|
|
80076
|
+
goodExample: `run( ).`,
|
|
80077
|
+
};
|
|
80078
|
+
}
|
|
80079
|
+
getConfig() {
|
|
80080
|
+
return this.conf;
|
|
80081
|
+
}
|
|
80082
|
+
setConfig(conf) {
|
|
80083
|
+
this.conf = conf;
|
|
80084
|
+
}
|
|
80085
|
+
initialize(reg) {
|
|
80086
|
+
this.reg = reg;
|
|
80087
|
+
return this;
|
|
80088
|
+
}
|
|
80089
|
+
run(obj) {
|
|
80090
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
80091
|
+
if (analysis === undefined) {
|
|
80092
|
+
return [];
|
|
80093
|
+
}
|
|
80094
|
+
const issues = [];
|
|
80095
|
+
for (const procedure of analysis.procedures) {
|
|
80096
|
+
if (procedure.supported === false) {
|
|
80097
|
+
continue;
|
|
80098
|
+
}
|
|
80099
|
+
const candidates = [];
|
|
80100
|
+
for (const variable of procedure.locals()) {
|
|
80101
|
+
if (variable.inline) {
|
|
80102
|
+
this.constantVariable(procedure, variable, candidates);
|
|
80103
|
+
}
|
|
80104
|
+
else {
|
|
80105
|
+
this.initialVariable(procedure, variable, candidates);
|
|
80106
|
+
}
|
|
80107
|
+
}
|
|
80108
|
+
issues.push(...(0, _procedure_analysis_1.foldIssues)(procedure.file, candidates, this.getMetadata().key, this.conf.severity));
|
|
80109
|
+
}
|
|
80110
|
+
return issues;
|
|
80111
|
+
}
|
|
80112
|
+
/** DATA(c) = abap_true. IF c = abap_true. */
|
|
80113
|
+
constantVariable(procedure, variable, candidates) {
|
|
80114
|
+
const declaration = variable.declaration;
|
|
80115
|
+
const move = (0, _procedure_analysis_1.plainMove)(declaration);
|
|
80116
|
+
const read = variable.occurrences[0];
|
|
80117
|
+
if (move === undefined || move.operator !== "="
|
|
80118
|
+
|| move.target.getChildren().length !== 1
|
|
80119
|
+
|| move.target.findDirectExpression(Expressions.InlineData) === undefined
|
|
80120
|
+
|| !(variable.identifier.getType() instanceof basic_1.CharacterType)
|
|
80121
|
+
|| variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
|
|
80122
|
+
|| !procedure.dominates(declaration, read.statement)) {
|
|
80123
|
+
return;
|
|
80124
|
+
}
|
|
80125
|
+
const value = (0, _procedure_analysis_1.characterConstant)(procedure, move.source);
|
|
80126
|
+
const result = value === undefined ? undefined : this.evaluate(procedure, read, value);
|
|
80127
|
+
if (result === undefined) {
|
|
80128
|
+
return;
|
|
80129
|
+
}
|
|
80130
|
+
const structure = procedure.ifStructure(read.statement);
|
|
80131
|
+
const fold = structure === undefined ? undefined : (0, _procedure_analysis_1.foldIf)(procedure, structure, read.statement, result);
|
|
80132
|
+
if (structure === undefined || fold === undefined) {
|
|
80133
|
+
return;
|
|
80134
|
+
}
|
|
80135
|
+
candidates.push({
|
|
80136
|
+
structure,
|
|
80137
|
+
statement: read.statement,
|
|
80138
|
+
message: "Condition is always " + (result ? "true" : "false") + ", " + variable.identifier.getName() + " is constant",
|
|
80139
|
+
fix: (0, _procedure_analysis_1.mergeEdits)(procedure.file, [fold, (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)]),
|
|
80140
|
+
});
|
|
80141
|
+
}
|
|
80142
|
+
/** DATA v TYPE ... never changed: IF v IS INITIAL / IS BOUND */
|
|
80143
|
+
initialVariable(procedure, variable, candidates) {
|
|
80144
|
+
if (!(0, _procedure_analysis_1.plainData)(variable.declaration) || variable.escapes()
|
|
80145
|
+
|| 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; })) {
|
|
80146
|
+
return;
|
|
80147
|
+
}
|
|
80148
|
+
for (const read of variable.reads()) {
|
|
80149
|
+
const predicate = (0, _procedure_analysis_1.simplePredicate)(read.statement);
|
|
80150
|
+
if (predicate === undefined || !this.isOperand(predicate.left, read)
|
|
80151
|
+
|| (predicate.kind !== _procedure_analysis_1.PredicateKind.Initial && predicate.kind !== _procedure_analysis_1.PredicateKind.Bound)) {
|
|
80152
|
+
continue;
|
|
80153
|
+
}
|
|
80154
|
+
// initial: IS INITIAL is true, IS BOUND is false
|
|
80155
|
+
const result = (predicate.kind === _procedure_analysis_1.PredicateKind.Initial) !== predicate.negated;
|
|
80156
|
+
const structure = procedure.ifStructure(read.statement);
|
|
80157
|
+
const fix = structure === undefined ? undefined : (0, _procedure_analysis_1.foldIf)(procedure, structure, read.statement, result);
|
|
80158
|
+
if (structure === undefined || fix === undefined) {
|
|
80159
|
+
continue;
|
|
80160
|
+
}
|
|
80161
|
+
candidates.push({
|
|
80162
|
+
structure,
|
|
80163
|
+
statement: read.statement,
|
|
80164
|
+
message: "Condition is always " + (result ? "true" : "false") + ", " + variable.identifier.getName() + " is never changed",
|
|
80165
|
+
fix,
|
|
80166
|
+
});
|
|
80167
|
+
}
|
|
80168
|
+
}
|
|
80169
|
+
evaluate(procedure, read, value) {
|
|
80170
|
+
const predicate = (0, _procedure_analysis_1.simplePredicate)(read.statement);
|
|
80171
|
+
if (predicate === undefined) {
|
|
80172
|
+
return undefined;
|
|
80173
|
+
}
|
|
80174
|
+
if (predicate.kind === _procedure_analysis_1.PredicateKind.Initial && this.isOperand(predicate.left, read)) {
|
|
80175
|
+
return (0, _procedure_analysis_1.sameCharacters)(value, "") !== predicate.negated;
|
|
80176
|
+
}
|
|
80177
|
+
else if (predicate.kind === _procedure_analysis_1.PredicateKind.Equal) {
|
|
80178
|
+
let other = predicate.right;
|
|
80179
|
+
if (!this.isOperand(predicate.left, read)) {
|
|
80180
|
+
if (!this.isOperand(predicate.right, read)) {
|
|
80181
|
+
return undefined;
|
|
80182
|
+
}
|
|
80183
|
+
other = predicate.left;
|
|
80184
|
+
}
|
|
80185
|
+
const compared = (0, _procedure_analysis_1.characterConstant)(procedure, other);
|
|
80186
|
+
if (compared === undefined) {
|
|
80187
|
+
return undefined;
|
|
80188
|
+
}
|
|
80189
|
+
return (0, _procedure_analysis_1.sameCharacters)(value, compared) !== predicate.negated;
|
|
80190
|
+
}
|
|
80191
|
+
return undefined;
|
|
80192
|
+
}
|
|
80193
|
+
isOperand(source, read) {
|
|
80194
|
+
return source.countTokens() === 1 && source.findDirectExpression(Expressions.FieldChain) !== undefined
|
|
80195
|
+
&& source.getFirstToken().getStart().equals(read.token.getStart());
|
|
80196
|
+
}
|
|
80197
|
+
}
|
|
80198
|
+
exports.ConstantCondition = ConstantCondition;
|
|
80199
|
+
//# sourceMappingURL=constant_condition.js.map
|
|
80200
|
+
|
|
80201
|
+
/***/ },
|
|
80202
|
+
|
|
80203
|
+
/***/ "../core/build/src/rules/constructor_visibility_public.js"
|
|
80204
|
+
/*!****************************************************************!*\
|
|
80205
|
+
!*** ../core/build/src/rules/constructor_visibility_public.js ***!
|
|
80206
|
+
\****************************************************************/
|
|
80207
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
80208
|
+
|
|
80209
|
+
"use strict";
|
|
80210
|
+
|
|
80211
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80212
|
+
exports.ConstructorVisibilityPublic = exports.ConstructorVisibilityPublicConf = void 0;
|
|
80213
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
80214
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
80215
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
80216
|
+
const objects_1 = __webpack_require__(/*! ../objects */ "../core/build/src/objects/index.js");
|
|
80217
|
+
const visibility_1 = __webpack_require__(/*! ../abap/4_file_information/visibility */ "../core/build/src/abap/4_file_information/visibility.js");
|
|
80218
|
+
class ConstructorVisibilityPublicConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
80219
|
+
}
|
|
80220
|
+
exports.ConstructorVisibilityPublicConf = ConstructorVisibilityPublicConf;
|
|
80221
|
+
class ConstructorVisibilityPublic {
|
|
80222
|
+
constructor() {
|
|
80223
|
+
this.conf = new ConstructorVisibilityPublicConf();
|
|
80224
|
+
}
|
|
80225
|
+
getMetadata() {
|
|
80226
|
+
return {
|
|
80227
|
+
key: "constructor_visibility_public",
|
|
80228
|
+
title: "Check constructor visibility is public",
|
|
80229
|
+
shortDescription: `Constructor must be placed in the public section, even if the class is not CREATE PUBLIC.`,
|
|
80230
|
+
extendedInformation: `
|
|
80231
|
+
This only applies to global classes.
|
|
80232
|
+
|
|
80233
|
+
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#if-your-global-class-is-create-private-leave-the-constructor-public
|
|
80234
|
+
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abeninstance_constructor_guidl.html`,
|
|
80235
|
+
tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
|
|
80236
|
+
badExample: `CLASS zcl_foo DEFINITION PUBLIC CREATE PRIVATE.
|
|
80237
|
+
PRIVATE SECTION.
|
|
80238
|
+
METHODS constructor.
|
|
80239
|
+
ENDCLASS.`,
|
|
80240
|
+
goodExample: `CLASS zcl_foo DEFINITION PUBLIC CREATE PRIVATE.
|
|
80241
|
+
PUBLIC SECTION.
|
|
80242
|
+
METHODS constructor.
|
|
80243
|
+
ENDCLASS.`,
|
|
80244
|
+
};
|
|
80245
|
+
}
|
|
80246
|
+
getMessage() {
|
|
80247
|
+
return "Constructor visibility should be public";
|
|
80248
|
+
}
|
|
80249
|
+
getConfig() {
|
|
80250
|
+
return this.conf;
|
|
80251
|
+
}
|
|
80252
|
+
initialize(_reg) {
|
|
80253
|
+
return this;
|
|
80254
|
+
}
|
|
80255
|
+
setConfig(conf) {
|
|
80256
|
+
this.conf = conf;
|
|
80257
|
+
}
|
|
80258
|
+
run(obj) {
|
|
80259
|
+
const issues = [];
|
|
80260
|
+
if (!(obj instanceof objects_1.Class)) {
|
|
80261
|
+
return [];
|
|
80262
|
+
}
|
|
80263
|
+
const def = obj.getClassDefinition();
|
|
80264
|
+
if (def === undefined) {
|
|
80265
|
+
return [];
|
|
80266
|
+
}
|
|
80267
|
+
for (const method of def.methods) {
|
|
80268
|
+
if (method.name.toUpperCase() === "CONSTRUCTOR"
|
|
80269
|
+
&& method.visibility !== visibility_1.Visibility.Public) {
|
|
80270
|
+
const issue = issue_1.Issue.atIdentifier(method.identifier, this.getMessage(), this.getMetadata().key, this.conf.severity);
|
|
80271
|
+
issues.push(issue);
|
|
80272
|
+
}
|
|
80273
|
+
}
|
|
80274
|
+
return issues;
|
|
80275
|
+
}
|
|
80276
|
+
}
|
|
80277
|
+
exports.ConstructorVisibilityPublic = ConstructorVisibilityPublic;
|
|
80278
|
+
//# sourceMappingURL=constructor_visibility_public.js.map
|
|
80279
|
+
|
|
80280
|
+
/***/ },
|
|
80281
|
+
|
|
80282
|
+
/***/ "../core/build/src/rules/contains_tab.js"
|
|
80283
|
+
/*!***********************************************!*\
|
|
80284
|
+
!*** ../core/build/src/rules/contains_tab.js ***!
|
|
80285
|
+
\***********************************************/
|
|
80286
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
80287
|
+
|
|
80288
|
+
"use strict";
|
|
80289
|
+
|
|
80290
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80291
|
+
exports.ContainsTab = exports.ContainsTabConf = void 0;
|
|
80292
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
80293
|
+
const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
|
|
80294
|
+
const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
|
|
80295
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
80296
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
80297
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
80298
|
+
class ContainsTabConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
80299
|
+
constructor() {
|
|
80300
|
+
super(...arguments);
|
|
80301
|
+
/** quick fix replace with number of spaces */
|
|
80302
|
+
this.spaces = 1;
|
|
80303
|
+
}
|
|
80304
|
+
}
|
|
80305
|
+
exports.ContainsTabConf = ContainsTabConf;
|
|
80306
|
+
class ContainsTab extends _abap_rule_1.ABAPRule {
|
|
80307
|
+
constructor() {
|
|
80308
|
+
super(...arguments);
|
|
80309
|
+
this.conf = new ContainsTabConf();
|
|
80310
|
+
}
|
|
80311
|
+
getMetadata() {
|
|
80312
|
+
return {
|
|
80313
|
+
key: "contains_tab",
|
|
80314
|
+
title: "Code contains tab",
|
|
80315
|
+
shortDescription: `Checks for usage of tabs (enable to enforce spaces)`,
|
|
80316
|
+
extendedInformation: `
|
|
80317
|
+
https://docs.abapopenchecks.org/checks/09/
|
|
80318
|
+
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#indent-and-snap-to-tab`,
|
|
80319
|
+
tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
|
|
80320
|
+
badExample: `\tWRITE 'hello world'.`,
|
|
80321
|
+
goodExample: ` WRITE 'hello world'.`,
|
|
80322
|
+
};
|
|
80323
|
+
}
|
|
80324
|
+
getMessage() {
|
|
80325
|
+
return "Code should not contain tabs";
|
|
80326
|
+
}
|
|
80327
|
+
getConfig() {
|
|
80328
|
+
if (this.conf.spaces === undefined) {
|
|
80329
|
+
this.conf.spaces = 1;
|
|
80330
|
+
}
|
|
80331
|
+
return this.conf;
|
|
80332
|
+
}
|
|
80333
|
+
setConfig(conf) {
|
|
80334
|
+
this.conf = conf;
|
|
80335
|
+
}
|
|
80336
|
+
runParsed(file) {
|
|
80337
|
+
const issues = [];
|
|
80338
|
+
const lines = file.getRaw().split("\n");
|
|
80339
|
+
lines.forEach((_, i) => {
|
|
80340
|
+
const tabCol = lines[i].indexOf("\t");
|
|
80341
|
+
if (tabCol >= 0) {
|
|
80342
|
+
let tabAmount = 1;
|
|
80343
|
+
while (lines[i].indexOf("\t", tabCol + tabAmount - 1) >= 0) {
|
|
80344
|
+
tabAmount++;
|
|
80345
|
+
}
|
|
80346
|
+
issues.push(this.createIssue(i, tabCol, tabAmount, file));
|
|
80347
|
+
}
|
|
80348
|
+
});
|
|
80349
|
+
return issues;
|
|
80350
|
+
}
|
|
80351
|
+
createIssue(line, tabCol, tabAmount, file) {
|
|
80352
|
+
const tabStartPos = new position_1.Position(line + 1, tabCol + 1);
|
|
80353
|
+
const tabEndPos = new position_1.Position(line + 1, tabCol + tabAmount);
|
|
80354
|
+
const fix = edit_helper_1.EditHelper.replaceRange(file, tabStartPos, tabEndPos, " ".repeat(this.getConfig().spaces));
|
|
80355
|
+
return issue_1.Issue.atRange(file, tabStartPos, tabEndPos, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
|
|
80356
|
+
}
|
|
80357
|
+
}
|
|
80358
|
+
exports.ContainsTab = ContainsTab;
|
|
80359
|
+
//# sourceMappingURL=contains_tab.js.map
|
|
80360
|
+
|
|
80361
|
+
/***/ },
|
|
80362
|
+
|
|
80363
|
+
/***/ "../core/build/src/rules/copy_chain.js"
|
|
80364
|
+
/*!*********************************************!*\
|
|
80365
|
+
!*** ../core/build/src/rules/copy_chain.js ***!
|
|
80366
|
+
\*********************************************/
|
|
80367
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
80368
|
+
|
|
80369
|
+
"use strict";
|
|
80370
|
+
|
|
80371
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
80372
|
+
if (k2 === undefined) k2 = k;
|
|
80373
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
80374
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
80375
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
80376
|
+
}
|
|
80377
|
+
Object.defineProperty(o, k2, desc);
|
|
80378
|
+
}) : (function(o, m, k, k2) {
|
|
80379
|
+
if (k2 === undefined) k2 = k;
|
|
80380
|
+
o[k2] = m[k];
|
|
80381
|
+
}));
|
|
80382
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
80383
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
80384
|
+
}) : function(o, v) {
|
|
80385
|
+
o["default"] = v;
|
|
80386
|
+
});
|
|
80387
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
80388
|
+
var ownKeys = function(o) {
|
|
80389
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
80390
|
+
var ar = [];
|
|
80391
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
80392
|
+
return ar;
|
|
80393
|
+
};
|
|
80394
|
+
return ownKeys(o);
|
|
80395
|
+
};
|
|
80396
|
+
return function (mod) {
|
|
80397
|
+
if (mod && mod.__esModule) return mod;
|
|
80398
|
+
var result = {};
|
|
80399
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
80400
|
+
__setModuleDefault(result, mod);
|
|
80401
|
+
return result;
|
|
80402
|
+
};
|
|
80403
|
+
})();
|
|
80404
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80405
|
+
exports.CopyChain = exports.CopyChainConf = void 0;
|
|
80406
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
80407
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
80408
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
80409
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
80410
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
80411
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
80412
|
+
class CopyChainConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
80413
|
+
}
|
|
80414
|
+
exports.CopyChainConf = CopyChainConf;
|
|
80415
|
+
class CopyChain {
|
|
80416
|
+
constructor() {
|
|
80417
|
+
this.conf = new CopyChainConf();
|
|
80418
|
+
}
|
|
80419
|
+
getMetadata() {
|
|
80420
|
+
return {
|
|
80421
|
+
key: "copy_chain",
|
|
80422
|
+
title: "Copy chain",
|
|
80423
|
+
shortDescription: `Finds a local variable that only passes a value on from one variable to another`,
|
|
80424
|
+
extendedInformation: `Reports DATA v TYPE ... [CLEAR v.] v = src. ... y = v. when all of the following hold:
|
|
80425
|
+
|
|
80426
|
+
* v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE
|
|
80427
|
+
* v has exactly one write besides CLEAR: v = src., and all CLEARs are before it
|
|
80428
|
+
* v has exactly one read, the complete source of y = v.
|
|
80429
|
+
* src is a local variable, its address is never taken, and it is not written from v = src. until y = v.
|
|
80430
|
+
* v = src. is executed before y = v. on every path: y = v. is in the same block or a nested block,
|
|
80431
|
+
and both are in the same loop
|
|
80432
|
+
* v and src are both reference types, or have identical types; for other types the copy into v can convert,
|
|
80433
|
+
e.g. truncate a string into a c field. For DATA(y) = v. the types must be identical, else y changes its type
|
|
80434
|
+
* the declaration, the CLEARs and v = src. are not chained
|
|
80435
|
+
|
|
80436
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
80437
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
80438
|
+
|
|
80439
|
+
The quick fix deletes the declaration, the CLEARs and v = src., and changes the read to y = src.
|
|
80440
|
+
No release requirement.`,
|
|
80441
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
80442
|
+
badExample: `DATA lo_copy TYPE REF TO zcl_node.
|
|
80443
|
+
lo_copy = lo_node.
|
|
80444
|
+
ro_result = lo_copy.`,
|
|
80445
|
+
goodExample: `ro_result = lo_node.`,
|
|
80446
|
+
};
|
|
80447
|
+
}
|
|
80448
|
+
getConfig() {
|
|
80449
|
+
return this.conf;
|
|
80450
|
+
}
|
|
80451
|
+
setConfig(conf) {
|
|
80452
|
+
this.conf = conf;
|
|
80453
|
+
}
|
|
80454
|
+
initialize(reg) {
|
|
80455
|
+
this.reg = reg;
|
|
80456
|
+
return this;
|
|
80457
|
+
}
|
|
80458
|
+
run(obj) {
|
|
80459
|
+
var _a, _b, _c;
|
|
80460
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
80461
|
+
if (analysis === undefined) {
|
|
80462
|
+
return [];
|
|
80463
|
+
}
|
|
80464
|
+
const issues = [];
|
|
80465
|
+
for (const procedure of analysis.procedures) {
|
|
80466
|
+
if (procedure.supported === false) {
|
|
80467
|
+
continue;
|
|
80468
|
+
}
|
|
80469
|
+
for (const variable of procedure.locals()) {
|
|
80470
|
+
const declaration = variable.declaration;
|
|
80471
|
+
if (variable.inline || !(0, _procedure_analysis_1.plainData)(declaration) || declaration.getColon() !== undefined
|
|
80472
|
+
|| variable.escapes()) {
|
|
80473
|
+
continue;
|
|
80474
|
+
}
|
|
80475
|
+
const clears = [];
|
|
80476
|
+
const writes = [];
|
|
80477
|
+
for (const write of variable.writes()) {
|
|
80478
|
+
if (((_a = (0, _procedure_analysis_1.plainClear)(write.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(write.token.getStart())) === true
|
|
80479
|
+
&& write.statement.getColon() === undefined) {
|
|
80480
|
+
clears.push(write);
|
|
80481
|
+
}
|
|
80482
|
+
else {
|
|
80483
|
+
writes.push(write);
|
|
80484
|
+
}
|
|
80485
|
+
}
|
|
80486
|
+
const reads = variable.reads();
|
|
80487
|
+
if (writes.length !== 1 || reads.length !== 1) {
|
|
80488
|
+
continue;
|
|
80489
|
+
}
|
|
80490
|
+
const write = writes[0];
|
|
80491
|
+
const read = reads[0];
|
|
80492
|
+
const assign = (0, _procedure_analysis_1.plainMove)(write.statement);
|
|
80493
|
+
const use = (0, _procedure_analysis_1.plainMove)(read.statement);
|
|
80494
|
+
if (assign === undefined || use === undefined || assign.operator !== "=" || use.operator !== "="
|
|
80495
|
+
|| ((_b = (0, _procedure_analysis_1.singleTarget)(assign.target)) === null || _b === void 0 ? void 0 : _b.getStart().equals(write.token.getStart())) !== true
|
|
80496
|
+
|| ((_c = (0, _procedure_analysis_1.singleField)(use.source)) === null || _c === void 0 ? void 0 : _c.getStart().equals(read.token.getStart())) !== true
|
|
80497
|
+
|| clears.some(c => c.index > write.index)
|
|
80498
|
+
|| !procedure.dominates(write.statement, read.statement)
|
|
80499
|
+
|| !procedure.sameLoop(write.statement, read.statement)) {
|
|
80500
|
+
continue;
|
|
80501
|
+
}
|
|
80502
|
+
const source = (0, _procedure_analysis_1.dataSource)(procedure, assign.source);
|
|
80503
|
+
if (source === undefined || source.kind !== _procedure_analysis_1.SourceKind.Local || source.base === variable
|
|
80504
|
+
|| (0, _procedure_analysis_1.singleField)(assign.source) === undefined
|
|
80505
|
+
|| !(0, _procedure_analysis_1.unchangedBetween)(procedure, source, write.statement, read.statement)) {
|
|
80506
|
+
continue;
|
|
80507
|
+
}
|
|
80508
|
+
// an inline declaration DATA(y) = v. would get the type of src instead of the type of v
|
|
80509
|
+
const type = variable.identifier.getType();
|
|
80510
|
+
const inline = use.target.findFirstExpression(Expressions.InlineData) !== undefined;
|
|
80511
|
+
if (!(0, _procedure_analysis_1.identicalTypes)(type, source.type) && (inline || !(0, _procedure_analysis_1.isReferenceType)(type) || !(0, _procedure_analysis_1.isReferenceType)(source.type))) {
|
|
80512
|
+
continue;
|
|
80513
|
+
}
|
|
80514
|
+
const edits = [
|
|
80515
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration),
|
|
80516
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, write.statement),
|
|
80517
|
+
edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, source.text)
|
|
80518
|
+
];
|
|
80519
|
+
for (const clear of clears) {
|
|
80520
|
+
edits.push((0, _procedure_analysis_1.deleteStatement)(procedure.file, clear.statement));
|
|
80521
|
+
}
|
|
80522
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
|
|
80523
|
+
const message = "Copy chain via " + variable.identifier.getName() + ", assign " + source.text + " directly";
|
|
80524
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, read.statement, message, this.getMetadata().key, this.conf.severity, fix));
|
|
80525
|
+
}
|
|
80526
|
+
}
|
|
80527
|
+
return issues;
|
|
80528
|
+
}
|
|
80529
|
+
}
|
|
80530
|
+
exports.CopyChain = CopyChain;
|
|
80531
|
+
//# sourceMappingURL=copy_chain.js.map
|
|
80532
|
+
|
|
80533
|
+
/***/ },
|
|
80534
|
+
|
|
80535
|
+
/***/ "../core/build/src/rules/copy_of_initial_variable.js"
|
|
80536
|
+
/*!***********************************************************!*\
|
|
80537
|
+
!*** ../core/build/src/rules/copy_of_initial_variable.js ***!
|
|
80538
|
+
\***********************************************************/
|
|
80539
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
80540
|
+
|
|
80541
|
+
"use strict";
|
|
80542
|
+
|
|
80543
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
80544
|
+
if (k2 === undefined) k2 = k;
|
|
80545
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
80546
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
80547
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
80548
|
+
}
|
|
80549
|
+
Object.defineProperty(o, k2, desc);
|
|
80550
|
+
}) : (function(o, m, k, k2) {
|
|
80551
|
+
if (k2 === undefined) k2 = k;
|
|
80552
|
+
o[k2] = m[k];
|
|
80553
|
+
}));
|
|
80554
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
80555
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
80556
|
+
}) : function(o, v) {
|
|
80557
|
+
o["default"] = v;
|
|
80558
|
+
});
|
|
80559
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
80560
|
+
var ownKeys = function(o) {
|
|
80561
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
80562
|
+
var ar = [];
|
|
80563
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
80564
|
+
return ar;
|
|
80565
|
+
};
|
|
80566
|
+
return ownKeys(o);
|
|
80567
|
+
};
|
|
80568
|
+
return function (mod) {
|
|
80569
|
+
if (mod && mod.__esModule) return mod;
|
|
80570
|
+
var result = {};
|
|
80571
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
80572
|
+
__setModuleDefault(result, mod);
|
|
80573
|
+
return result;
|
|
80574
|
+
};
|
|
80575
|
+
})();
|
|
80576
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80577
|
+
exports.CopyOfInitialVariable = exports.CopyOfInitialVariableConf = void 0;
|
|
80578
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
80579
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
77935
80580
|
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
77936
80581
|
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
77937
80582
|
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
77938
|
-
const
|
|
77939
|
-
|
|
77940
|
-
/** Checks that constants classes are in sync with domain fixed values */
|
|
77941
|
-
class ConstantClassesConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
77942
|
-
constructor() {
|
|
77943
|
-
super(...arguments);
|
|
77944
|
-
/** Specify a list of domain-class pairs which will be validated */
|
|
77945
|
-
this.mapping = [];
|
|
77946
|
-
}
|
|
80583
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
80584
|
+
class CopyOfInitialVariableConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
77947
80585
|
}
|
|
77948
|
-
exports.
|
|
77949
|
-
class
|
|
80586
|
+
exports.CopyOfInitialVariableConf = CopyOfInitialVariableConf;
|
|
80587
|
+
class CopyOfInitialVariable {
|
|
77950
80588
|
constructor() {
|
|
77951
|
-
this.conf = new
|
|
80589
|
+
this.conf = new CopyOfInitialVariableConf();
|
|
77952
80590
|
}
|
|
77953
80591
|
getMetadata() {
|
|
77954
80592
|
return {
|
|
77955
|
-
key: "
|
|
77956
|
-
title: "
|
|
77957
|
-
shortDescription: `
|
|
77958
|
-
extendedInformation: `
|
|
77959
|
-
|
|
80593
|
+
key: "copy_of_initial_variable",
|
|
80594
|
+
title: "Copy of initial variable",
|
|
80595
|
+
shortDescription: `Finds assignments from a local variable that is always initial`,
|
|
80596
|
+
extendedInformation: `Reports DATA v TYPE ... [CLEAR v.] x = v. when all of the following hold:
|
|
80597
|
+
|
|
80598
|
+
* v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE
|
|
80599
|
+
* v is never changed, except by CLEAR v., and its address is never taken
|
|
80600
|
+
* v has exactly one read, the complete source of x = v., where x is not an inline declaration
|
|
80601
|
+
* x and v are both reference types, or have identical types. Initial values convert differently between
|
|
80602
|
+
types, e.g. an initial d becomes '00000000' in a string
|
|
80603
|
+
* the declaration and the CLEARs are not chained
|
|
80604
|
+
|
|
80605
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
80606
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
80607
|
+
|
|
80608
|
+
The quick fix deletes the declaration and the CLEARs, and replaces x = v. with CLEAR x.
|
|
80609
|
+
No release requirement.`,
|
|
80610
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
80611
|
+
badExample: `DATA lo_empty TYPE REF TO zcl_node.
|
|
80612
|
+
ro_result = lo_empty.`,
|
|
80613
|
+
goodExample: `CLEAR ro_result.`,
|
|
77960
80614
|
};
|
|
77961
80615
|
}
|
|
77962
|
-
initialize(reg) {
|
|
77963
|
-
this.reg = reg;
|
|
77964
|
-
return this;
|
|
77965
|
-
}
|
|
77966
80616
|
getConfig() {
|
|
77967
80617
|
return this.conf;
|
|
77968
80618
|
}
|
|
77969
80619
|
setConfig(conf) {
|
|
77970
80620
|
this.conf = conf;
|
|
77971
80621
|
}
|
|
77972
|
-
|
|
77973
|
-
|
|
77974
|
-
&& this.conf.mapping
|
|
77975
|
-
&& obj instanceof Objects.Domain) {
|
|
77976
|
-
const configEntry = this.conf.mapping.find(x => x.domain.toUpperCase() === obj.getName().toUpperCase());
|
|
77977
|
-
if (!configEntry) {
|
|
77978
|
-
return [];
|
|
77979
|
-
}
|
|
77980
|
-
const classWithConstants = this.reg.getObject("CLAS", configEntry === null || configEntry === void 0 ? void 0 : configEntry.class.toUpperCase());
|
|
77981
|
-
if (!classWithConstants) {
|
|
77982
|
-
return [issue_1.Issue.atIdentifier(obj.getIdentifier(), `Constant class pattern implementation ${configEntry.class} missing for domain ${configEntry.domain}`, this.getMetadata().key, this.conf.severity)];
|
|
77983
|
-
// quickfix will implement the whole class
|
|
77984
|
-
}
|
|
77985
|
-
const classContents = classWithConstants.getMainABAPFile();
|
|
77986
|
-
if (classContents === undefined) {
|
|
77987
|
-
return [];
|
|
77988
|
-
}
|
|
77989
|
-
const def = classWithConstants.getClassDefinition();
|
|
77990
|
-
if (!def) {
|
|
77991
|
-
// this issue is checked by rule implement_methods.
|
|
77992
|
-
// we will not issue errors that all constants are missing until there is a class implementation
|
|
77993
|
-
return [];
|
|
77994
|
-
}
|
|
77995
|
-
const domainValueInfo = obj.getFixedValues();
|
|
77996
|
-
const domainValues = domainValueInfo.map(x => x.low);
|
|
77997
|
-
const issues = [];
|
|
77998
|
-
if (obj.getFixedValues().length === 0) {
|
|
77999
|
-
// possibly this is not even a domain with fixed values
|
|
78000
|
-
issues.push(issue_1.Issue.atStatement(classContents, classContents.getStatements()[0], `Domain ${configEntry.domain} does not contain any fixed values. Either add some values or disable this check`, this.getMetadata().key, this.conf.severity));
|
|
78001
|
-
}
|
|
78002
|
-
// later we will raise an issue if we did not find it
|
|
78003
|
-
let domainNameConstantFound = false;
|
|
78004
|
-
for (const constant of def.constants) {
|
|
78005
|
-
if (configEntry.constantForDomainName
|
|
78006
|
-
&& constant.name === configEntry.constantForDomainName) {
|
|
78007
|
-
// we require the constant value to be uppercase just in case
|
|
78008
|
-
// in the config it does not matter
|
|
78009
|
-
if (constant.value !== configEntry.domain.toLocaleUpperCase()) {
|
|
78010
|
-
issues.push(this.issueAtConstant(constant, `Constant value ${constant.value} must match domain name ${configEntry.domain} `));
|
|
78011
|
-
}
|
|
78012
|
-
domainNameConstantFound = true;
|
|
78013
|
-
continue;
|
|
78014
|
-
}
|
|
78015
|
-
if (configEntry.useExactType && constant.typeName.toLowerCase() !== configEntry.domain.toLowerCase()) {
|
|
78016
|
-
issues.push(this.issueAtConstant(constant, `Use exact type ${configEntry.domain} instead of ${constant.typeName}`));
|
|
78017
|
-
// quickfix will change the type
|
|
78018
|
-
}
|
|
78019
|
-
if (constant.visibility !== visibility_1.Visibility.Public) {
|
|
78020
|
-
issues.push(this.issueAtConstant(constant, `Constant ${constant.name} should be public`));
|
|
78021
|
-
// quickfix will move constant
|
|
78022
|
-
}
|
|
78023
|
-
if (!domainValues.includes(constant.value)) {
|
|
78024
|
-
issues.push(this.issueAtConstant(constant, `Extra constant ${constant.name} found which is not present in domain ${configEntry.domain}`));
|
|
78025
|
-
// quickfix will remove constant
|
|
78026
|
-
}
|
|
78027
|
-
}
|
|
78028
|
-
for (const d of domainValueInfo) {
|
|
78029
|
-
if (!def.constants.find(c => c.value === d.low)) {
|
|
78030
|
-
issues.push(issue_1.Issue.atStatement(classContents, classContents.getStatements()[0], `Missing constant for ${d.low} (domain ${configEntry.domain})`, this.getMetadata().key, this.conf.severity));
|
|
78031
|
-
// quickfix will add constant
|
|
78032
|
-
}
|
|
78033
|
-
}
|
|
78034
|
-
if (configEntry.constantForDomainName && !domainNameConstantFound) {
|
|
78035
|
-
issues.push(issue_1.Issue.atStatement(classContents, classContents.getStatements()[0], `Missing constant ${configEntry.constantForDomainName} for name of domain ${configEntry.domain}`, this.getMetadata().key, this.conf.severity));
|
|
78036
|
-
}
|
|
78037
|
-
return issues;
|
|
78038
|
-
}
|
|
78039
|
-
return [];
|
|
78040
|
-
}
|
|
78041
|
-
issueAtConstant(constant, message) {
|
|
78042
|
-
return issue_1.Issue.atIdentifier(constant.identifier, message, this.getMetadata().key, this.conf.severity);
|
|
78043
|
-
}
|
|
78044
|
-
}
|
|
78045
|
-
exports.ConstantClasses = ConstantClasses;
|
|
78046
|
-
//# sourceMappingURL=constant_classes.js.map
|
|
78047
|
-
|
|
78048
|
-
/***/ },
|
|
78049
|
-
|
|
78050
|
-
/***/ "../core/build/src/rules/constructor_visibility_public.js"
|
|
78051
|
-
/*!****************************************************************!*\
|
|
78052
|
-
!*** ../core/build/src/rules/constructor_visibility_public.js ***!
|
|
78053
|
-
\****************************************************************/
|
|
78054
|
-
(__unused_webpack_module, exports, __webpack_require__) {
|
|
78055
|
-
|
|
78056
|
-
"use strict";
|
|
78057
|
-
|
|
78058
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
78059
|
-
exports.ConstructorVisibilityPublic = exports.ConstructorVisibilityPublicConf = void 0;
|
|
78060
|
-
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
78061
|
-
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
78062
|
-
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
78063
|
-
const objects_1 = __webpack_require__(/*! ../objects */ "../core/build/src/objects/index.js");
|
|
78064
|
-
const visibility_1 = __webpack_require__(/*! ../abap/4_file_information/visibility */ "../core/build/src/abap/4_file_information/visibility.js");
|
|
78065
|
-
class ConstructorVisibilityPublicConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
78066
|
-
}
|
|
78067
|
-
exports.ConstructorVisibilityPublicConf = ConstructorVisibilityPublicConf;
|
|
78068
|
-
class ConstructorVisibilityPublic {
|
|
78069
|
-
constructor() {
|
|
78070
|
-
this.conf = new ConstructorVisibilityPublicConf();
|
|
78071
|
-
}
|
|
78072
|
-
getMetadata() {
|
|
78073
|
-
return {
|
|
78074
|
-
key: "constructor_visibility_public",
|
|
78075
|
-
title: "Check constructor visibility is public",
|
|
78076
|
-
shortDescription: `Constructor must be placed in the public section, even if the class is not CREATE PUBLIC.`,
|
|
78077
|
-
extendedInformation: `
|
|
78078
|
-
This only applies to global classes.
|
|
78079
|
-
|
|
78080
|
-
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#if-your-global-class-is-create-private-leave-the-constructor-public
|
|
78081
|
-
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abeninstance_constructor_guidl.html`,
|
|
78082
|
-
tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
|
|
78083
|
-
badExample: `CLASS zcl_foo DEFINITION PUBLIC CREATE PRIVATE.
|
|
78084
|
-
PRIVATE SECTION.
|
|
78085
|
-
METHODS constructor.
|
|
78086
|
-
ENDCLASS.`,
|
|
78087
|
-
goodExample: `CLASS zcl_foo DEFINITION PUBLIC CREATE PRIVATE.
|
|
78088
|
-
PUBLIC SECTION.
|
|
78089
|
-
METHODS constructor.
|
|
78090
|
-
ENDCLASS.`,
|
|
78091
|
-
};
|
|
78092
|
-
}
|
|
78093
|
-
getMessage() {
|
|
78094
|
-
return "Constructor visibility should be public";
|
|
78095
|
-
}
|
|
78096
|
-
getConfig() {
|
|
78097
|
-
return this.conf;
|
|
78098
|
-
}
|
|
78099
|
-
initialize(_reg) {
|
|
80622
|
+
initialize(reg) {
|
|
80623
|
+
this.reg = reg;
|
|
78100
80624
|
return this;
|
|
78101
80625
|
}
|
|
78102
|
-
setConfig(conf) {
|
|
78103
|
-
this.conf = conf;
|
|
78104
|
-
}
|
|
78105
80626
|
run(obj) {
|
|
78106
|
-
|
|
78107
|
-
|
|
78108
|
-
|
|
78109
|
-
}
|
|
78110
|
-
const def = obj.getClassDefinition();
|
|
78111
|
-
if (def === undefined) {
|
|
80627
|
+
var _a;
|
|
80628
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
80629
|
+
if (analysis === undefined) {
|
|
78112
80630
|
return [];
|
|
78113
80631
|
}
|
|
78114
|
-
for (const method of def.methods) {
|
|
78115
|
-
if (method.name.toUpperCase() === "CONSTRUCTOR"
|
|
78116
|
-
&& method.visibility !== visibility_1.Visibility.Public) {
|
|
78117
|
-
const issue = issue_1.Issue.atIdentifier(method.identifier, this.getMessage(), this.getMetadata().key, this.conf.severity);
|
|
78118
|
-
issues.push(issue);
|
|
78119
|
-
}
|
|
78120
|
-
}
|
|
78121
|
-
return issues;
|
|
78122
|
-
}
|
|
78123
|
-
}
|
|
78124
|
-
exports.ConstructorVisibilityPublic = ConstructorVisibilityPublic;
|
|
78125
|
-
//# sourceMappingURL=constructor_visibility_public.js.map
|
|
78126
|
-
|
|
78127
|
-
/***/ },
|
|
78128
|
-
|
|
78129
|
-
/***/ "../core/build/src/rules/contains_tab.js"
|
|
78130
|
-
/*!***********************************************!*\
|
|
78131
|
-
!*** ../core/build/src/rules/contains_tab.js ***!
|
|
78132
|
-
\***********************************************/
|
|
78133
|
-
(__unused_webpack_module, exports, __webpack_require__) {
|
|
78134
|
-
|
|
78135
|
-
"use strict";
|
|
78136
|
-
|
|
78137
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
78138
|
-
exports.ContainsTab = exports.ContainsTabConf = void 0;
|
|
78139
|
-
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
78140
|
-
const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
|
|
78141
|
-
const _abap_rule_1 = __webpack_require__(/*! ./_abap_rule */ "../core/build/src/rules/_abap_rule.js");
|
|
78142
|
-
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
78143
|
-
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
78144
|
-
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
78145
|
-
class ContainsTabConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
78146
|
-
constructor() {
|
|
78147
|
-
super(...arguments);
|
|
78148
|
-
/** quick fix replace with number of spaces */
|
|
78149
|
-
this.spaces = 1;
|
|
78150
|
-
}
|
|
78151
|
-
}
|
|
78152
|
-
exports.ContainsTabConf = ContainsTabConf;
|
|
78153
|
-
class ContainsTab extends _abap_rule_1.ABAPRule {
|
|
78154
|
-
constructor() {
|
|
78155
|
-
super(...arguments);
|
|
78156
|
-
this.conf = new ContainsTabConf();
|
|
78157
|
-
}
|
|
78158
|
-
getMetadata() {
|
|
78159
|
-
return {
|
|
78160
|
-
key: "contains_tab",
|
|
78161
|
-
title: "Code contains tab",
|
|
78162
|
-
shortDescription: `Checks for usage of tabs (enable to enforce spaces)`,
|
|
78163
|
-
extendedInformation: `
|
|
78164
|
-
https://docs.abapopenchecks.org/checks/09/
|
|
78165
|
-
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#indent-and-snap-to-tab`,
|
|
78166
|
-
tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
|
|
78167
|
-
badExample: `\tWRITE 'hello world'.`,
|
|
78168
|
-
goodExample: ` WRITE 'hello world'.`,
|
|
78169
|
-
};
|
|
78170
|
-
}
|
|
78171
|
-
getMessage() {
|
|
78172
|
-
return "Code should not contain tabs";
|
|
78173
|
-
}
|
|
78174
|
-
getConfig() {
|
|
78175
|
-
if (this.conf.spaces === undefined) {
|
|
78176
|
-
this.conf.spaces = 1;
|
|
78177
|
-
}
|
|
78178
|
-
return this.conf;
|
|
78179
|
-
}
|
|
78180
|
-
setConfig(conf) {
|
|
78181
|
-
this.conf = conf;
|
|
78182
|
-
}
|
|
78183
|
-
runParsed(file) {
|
|
78184
80632
|
const issues = [];
|
|
78185
|
-
const
|
|
78186
|
-
|
|
78187
|
-
|
|
78188
|
-
|
|
78189
|
-
|
|
78190
|
-
|
|
78191
|
-
|
|
80633
|
+
for (const procedure of analysis.procedures) {
|
|
80634
|
+
if (procedure.supported === false) {
|
|
80635
|
+
continue;
|
|
80636
|
+
}
|
|
80637
|
+
for (const variable of procedure.locals()) {
|
|
80638
|
+
const declaration = variable.declaration;
|
|
80639
|
+
const reads = variable.reads();
|
|
80640
|
+
const writes = variable.writes();
|
|
80641
|
+
if (variable.inline || !(0, _procedure_analysis_1.plainData)(declaration) || declaration.getColon() !== undefined
|
|
80642
|
+
|| variable.escapes() || reads.length !== 1
|
|
80643
|
+
|| 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
|
|
80644
|
+
|| w.statement.getColon() !== undefined; })) {
|
|
80645
|
+
continue;
|
|
78192
80646
|
}
|
|
78193
|
-
|
|
80647
|
+
const read = reads[0];
|
|
80648
|
+
const move = (0, _procedure_analysis_1.plainMove)(read.statement);
|
|
80649
|
+
if (move === undefined || move.operator !== "="
|
|
80650
|
+
|| ((_a = (0, _procedure_analysis_1.singleField)(move.source)) === null || _a === void 0 ? void 0 : _a.getStart().equals(read.token.getStart())) !== true
|
|
80651
|
+
|| move.target.findFirstExpression(Expressions.InlineData) !== undefined) {
|
|
80652
|
+
continue;
|
|
80653
|
+
}
|
|
80654
|
+
const type = variable.identifier.getType();
|
|
80655
|
+
const target = (0, _procedure_analysis_1.targetType)(procedure, move.target);
|
|
80656
|
+
if (target === undefined
|
|
80657
|
+
|| (!((0, _procedure_analysis_1.isReferenceType)(type) && (0, _procedure_analysis_1.isReferenceType)(target)) && !(0, _procedure_analysis_1.identicalTypes)(type, target))) {
|
|
80658
|
+
continue;
|
|
80659
|
+
}
|
|
80660
|
+
const edits = [
|
|
80661
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration),
|
|
80662
|
+
edit_helper_1.EditHelper.replaceRange(procedure.file, read.statement.getStart(), read.statement.getEnd(), "CLEAR " + (0, _procedure_analysis_1.nodeText)(procedure.file, move.target) + ".")
|
|
80663
|
+
];
|
|
80664
|
+
for (const write of writes) {
|
|
80665
|
+
edits.push((0, _procedure_analysis_1.deleteStatement)(procedure.file, write.statement));
|
|
80666
|
+
}
|
|
80667
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
|
|
80668
|
+
const message = variable.identifier.getName() + " is always initial, use CLEAR";
|
|
80669
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, read.statement, message, this.getMetadata().key, this.conf.severity, fix));
|
|
78194
80670
|
}
|
|
78195
|
-
}
|
|
80671
|
+
}
|
|
78196
80672
|
return issues;
|
|
78197
80673
|
}
|
|
78198
|
-
createIssue(line, tabCol, tabAmount, file) {
|
|
78199
|
-
const tabStartPos = new position_1.Position(line + 1, tabCol + 1);
|
|
78200
|
-
const tabEndPos = new position_1.Position(line + 1, tabCol + tabAmount);
|
|
78201
|
-
const fix = edit_helper_1.EditHelper.replaceRange(file, tabStartPos, tabEndPos, " ".repeat(this.getConfig().spaces));
|
|
78202
|
-
return issue_1.Issue.atRange(file, tabStartPos, tabEndPos, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
|
|
78203
|
-
}
|
|
78204
80674
|
}
|
|
78205
|
-
exports.
|
|
78206
|
-
//# sourceMappingURL=
|
|
80675
|
+
exports.CopyOfInitialVariable = CopyOfInitialVariable;
|
|
80676
|
+
//# sourceMappingURL=copy_of_initial_variable.js.map
|
|
78207
80677
|
|
|
78208
80678
|
/***/ },
|
|
78209
80679
|
|
|
@@ -87174,6 +89644,7 @@ __exportStar(__webpack_require__(/*! ./abapdoc_leading_at */ "../core/build/src/
|
|
|
87174
89644
|
__exportStar(__webpack_require__(/*! ./abapdoc_parameter_names */ "../core/build/src/rules/abapdoc_parameter_names.js"), exports);
|
|
87175
89645
|
__exportStar(__webpack_require__(/*! ./add_test_attributes */ "../core/build/src/rules/add_test_attributes.js"), exports);
|
|
87176
89646
|
__exportStar(__webpack_require__(/*! ./aff_and_xml */ "../core/build/src/rules/aff_and_xml.js"), exports);
|
|
89647
|
+
__exportStar(__webpack_require__(/*! ./alias_never_reassigned */ "../core/build/src/rules/alias_never_reassigned.js"), exports);
|
|
87177
89648
|
__exportStar(__webpack_require__(/*! ./align_parameters */ "../core/build/src/rules/align_parameters.js"), exports);
|
|
87178
89649
|
__exportStar(__webpack_require__(/*! ./align_pseudo_comments */ "../core/build/src/rules/align_pseudo_comments.js"), exports);
|
|
87179
89650
|
__exportStar(__webpack_require__(/*! ./align_type_expressions */ "../core/build/src/rules/align_type_expressions.js"), exports);
|
|
@@ -87183,6 +89654,8 @@ __exportStar(__webpack_require__(/*! ./ambiguous_statement */ "../core/build/src
|
|
|
87183
89654
|
__exportStar(__webpack_require__(/*! ./avoid_use */ "../core/build/src/rules/avoid_use.js"), exports);
|
|
87184
89655
|
__exportStar(__webpack_require__(/*! ./begin_end_names */ "../core/build/src/rules/begin_end_names.js"), exports);
|
|
87185
89656
|
__exportStar(__webpack_require__(/*! ./begin_single_include */ "../core/build/src/rules/begin_single_include.js"), exports);
|
|
89657
|
+
__exportStar(__webpack_require__(/*! ./boolean_flag_via_if */ "../core/build/src/rules/boolean_flag_via_if.js"), exports);
|
|
89658
|
+
__exportStar(__webpack_require__(/*! ./bound_check_after_create */ "../core/build/src/rules/bound_check_after_create.js"), exports);
|
|
87186
89659
|
__exportStar(__webpack_require__(/*! ./call_transaction_authority_check */ "../core/build/src/rules/call_transaction_authority_check.js"), exports);
|
|
87187
89660
|
__exportStar(__webpack_require__(/*! ./catch_and_raise */ "../core/build/src/rules/catch_and_raise.js"), exports);
|
|
87188
89661
|
__exportStar(__webpack_require__(/*! ./cds_association_name */ "../core/build/src/rules/cds_association_name.js"), exports);
|
|
@@ -87203,6 +89676,7 @@ __exportStar(__webpack_require__(/*! ./check_subrc */ "../core/build/src/rules/c
|
|
|
87203
89676
|
__exportStar(__webpack_require__(/*! ./check_syntax */ "../core/build/src/rules/check_syntax.js"), exports);
|
|
87204
89677
|
__exportStar(__webpack_require__(/*! ./check_text_elements */ "../core/build/src/rules/check_text_elements.js"), exports);
|
|
87205
89678
|
__exportStar(__webpack_require__(/*! ./check_transformation_exists */ "../core/build/src/rules/check_transformation_exists.js"), exports);
|
|
89679
|
+
__exportStar(__webpack_require__(/*! ./clear_after_declaration */ "../core/build/src/rules/clear_after_declaration.js"), exports);
|
|
87206
89680
|
__exportStar(__webpack_require__(/*! ./clear_exporting_parameters */ "../core/build/src/rules/clear_exporting_parameters.js"), exports);
|
|
87207
89681
|
__exportStar(__webpack_require__(/*! ./class_attribute_names */ "../core/build/src/rules/class_attribute_names.js"), exports);
|
|
87208
89682
|
__exportStar(__webpack_require__(/*! ./classic_exceptions_overlap */ "../core/build/src/rules/classic_exceptions_overlap.js"), exports);
|
|
@@ -87210,8 +89684,11 @@ __exportStar(__webpack_require__(/*! ./cloud_types */ "../core/build/src/rules/c
|
|
|
87210
89684
|
__exportStar(__webpack_require__(/*! ./colon_missing_space */ "../core/build/src/rules/colon_missing_space.js"), exports);
|
|
87211
89685
|
__exportStar(__webpack_require__(/*! ./commented_code */ "../core/build/src/rules/commented_code.js"), exports);
|
|
87212
89686
|
__exportStar(__webpack_require__(/*! ./constant_classes */ "../core/build/src/rules/constant_classes.js"), exports);
|
|
89687
|
+
__exportStar(__webpack_require__(/*! ./constant_condition */ "../core/build/src/rules/constant_condition.js"), exports);
|
|
87213
89688
|
__exportStar(__webpack_require__(/*! ./constructor_visibility_public */ "../core/build/src/rules/constructor_visibility_public.js"), exports);
|
|
87214
89689
|
__exportStar(__webpack_require__(/*! ./contains_tab */ "../core/build/src/rules/contains_tab.js"), exports);
|
|
89690
|
+
__exportStar(__webpack_require__(/*! ./copy_chain */ "../core/build/src/rules/copy_chain.js"), exports);
|
|
89691
|
+
__exportStar(__webpack_require__(/*! ./copy_of_initial_variable */ "../core/build/src/rules/copy_of_initial_variable.js"), exports);
|
|
87215
89692
|
__exportStar(__webpack_require__(/*! ./cyclic_oo */ "../core/build/src/rules/cyclic_oo.js"), exports);
|
|
87216
89693
|
__exportStar(__webpack_require__(/*! ./cyclomatic_complexity */ "../core/build/src/rules/cyclomatic_complexity.js"), exports);
|
|
87217
89694
|
__exportStar(__webpack_require__(/*! ./dangerous_statement */ "../core/build/src/rules/dangerous_statement.js"), exports);
|
|
@@ -87337,6 +89814,7 @@ __exportStar(__webpack_require__(/*! ./selection_screen_texts_missing */ "../cor
|
|
|
87337
89814
|
__exportStar(__webpack_require__(/*! ./sequential_blank */ "../core/build/src/rules/sequential_blank.js"), exports);
|
|
87338
89815
|
__exportStar(__webpack_require__(/*! ./short_case */ "../core/build/src/rules/short_case.js"), exports);
|
|
87339
89816
|
__exportStar(__webpack_require__(/*! ./sicf_consistency */ "../core/build/src/rules/sicf_consistency.js"), exports);
|
|
89817
|
+
__exportStar(__webpack_require__(/*! ./single_use_expression_temp */ "../core/build/src/rules/single_use_expression_temp.js"), exports);
|
|
87340
89818
|
__exportStar(__webpack_require__(/*! ./slow_parameter_passing */ "../core/build/src/rules/slow_parameter_passing.js"), exports);
|
|
87341
89819
|
__exportStar(__webpack_require__(/*! ./smim_consistency */ "../core/build/src/rules/smim_consistency.js"), exports);
|
|
87342
89820
|
__exportStar(__webpack_require__(/*! ./sort_empty_key */ "../core/build/src/rules/sort_empty_key.js"), exports);
|
|
@@ -87354,12 +89832,14 @@ __exportStar(__webpack_require__(/*! ./sy_modification */ "../core/build/src/rul
|
|
|
87354
89832
|
__exportStar(__webpack_require__(/*! ./sy_read_restriction */ "../core/build/src/rules/sy_read_restriction.js"), exports);
|
|
87355
89833
|
__exportStar(__webpack_require__(/*! ./tabl_enhancement_category */ "../core/build/src/rules/tabl_enhancement_category.js"), exports);
|
|
87356
89834
|
__exportStar(__webpack_require__(/*! ./tables_declared_locally */ "../core/build/src/rules/tables_declared_locally.js"), exports);
|
|
89835
|
+
__exportStar(__webpack_require__(/*! ./try_cast_empty_catch */ "../core/build/src/rules/try_cast_empty_catch.js"), exports);
|
|
87357
89836
|
__exportStar(__webpack_require__(/*! ./try_without_catch */ "../core/build/src/rules/try_without_catch.js"), exports);
|
|
87358
89837
|
__exportStar(__webpack_require__(/*! ./type_form_parameters */ "../core/build/src/rules/type_form_parameters.js"), exports);
|
|
87359
89838
|
__exportStar(__webpack_require__(/*! ./types_naming */ "../core/build/src/rules/types_naming.js"), exports);
|
|
87360
89839
|
__exportStar(__webpack_require__(/*! ./uncaught_exception */ "../core/build/src/rules/uncaught_exception.js"), exports);
|
|
87361
89840
|
__exportStar(__webpack_require__(/*! ./unknown_types */ "../core/build/src/rules/unknown_types.js"), exports);
|
|
87362
89841
|
__exportStar(__webpack_require__(/*! ./unnecessary_chaining */ "../core/build/src/rules/unnecessary_chaining.js"), exports);
|
|
89842
|
+
__exportStar(__webpack_require__(/*! ./unnecessary_copy */ "../core/build/src/rules/unnecessary_copy.js"), exports);
|
|
87363
89843
|
__exportStar(__webpack_require__(/*! ./unnecessary_loop_guard */ "../core/build/src/rules/unnecessary_loop_guard.js"), exports);
|
|
87364
89844
|
__exportStar(__webpack_require__(/*! ./unnecessary_pragma */ "../core/build/src/rules/unnecessary_pragma.js"), exports);
|
|
87365
89845
|
__exportStar(__webpack_require__(/*! ./unnecessary_return */ "../core/build/src/rules/unnecessary_return.js"), exports);
|
|
@@ -99419,10 +101899,14 @@ If the statement contains a JOIN it is not checked`,
|
|
|
99419
101899
|
setConfig(conf) {
|
|
99420
101900
|
this.conf = conf;
|
|
99421
101901
|
}
|
|
99422
|
-
buildFix(file, statement) {
|
|
101902
|
+
buildFix(file, statement, rows) {
|
|
101903
|
+
const end = statement.getLastToken().getEnd();
|
|
101904
|
+
const suffix = rows[end.getRow() - 1].slice(end.getCol() - 1).trimStart();
|
|
101905
|
+
// Keep chained '*' continuations out of the full-line comment column.
|
|
101906
|
+
const newline = suffix !== "" && suffix.startsWith('"') === false ? "\n " : "";
|
|
99423
101907
|
return {
|
|
99424
101908
|
description: `Add "#EC CI_NOORDER`,
|
|
99425
|
-
edit: edit_helper_1.EditHelper.insertAt(file,
|
|
101909
|
+
edit: edit_helper_1.EditHelper.insertAt(file, end, ` "#EC CI_NOORDER${newline}`),
|
|
99426
101910
|
};
|
|
99427
101911
|
}
|
|
99428
101912
|
run(obj) {
|
|
@@ -99438,6 +101922,7 @@ If the statement contains a JOIN it is not checked`,
|
|
|
99438
101922
|
const message = "SELECT SINGLE possibily not unique";
|
|
99439
101923
|
for (const file of obj.getABAPFiles()) {
|
|
99440
101924
|
const statements = file.getStatements();
|
|
101925
|
+
const rows = file.getRawRows();
|
|
99441
101926
|
for (let i = 0; i < statements.length; i++) {
|
|
99442
101927
|
const s = statements[i];
|
|
99443
101928
|
if (!(s.get() instanceof Statements.Select)) {
|
|
@@ -99484,7 +101969,7 @@ If the statement contains a JOIN it is not checked`,
|
|
|
99484
101969
|
}
|
|
99485
101970
|
}
|
|
99486
101971
|
if (set.size > 0) {
|
|
99487
|
-
const fix = this.buildFix(file, s);
|
|
101972
|
+
const fix = this.buildFix(file, s, rows);
|
|
99488
101973
|
issues.push(issue_1.Issue.atStatement(file, s, message, this.getMetadata().key, this.getConfig().severity, undefined, [fix]));
|
|
99489
101974
|
}
|
|
99490
101975
|
}
|
|
@@ -100066,6 +102551,218 @@ exports.SICFConsistency = SICFConsistency;
|
|
|
100066
102551
|
|
|
100067
102552
|
/***/ },
|
|
100068
102553
|
|
|
102554
|
+
/***/ "../core/build/src/rules/single_use_expression_temp.js"
|
|
102555
|
+
/*!*************************************************************!*\
|
|
102556
|
+
!*** ../core/build/src/rules/single_use_expression_temp.js ***!
|
|
102557
|
+
\*************************************************************/
|
|
102558
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
102559
|
+
|
|
102560
|
+
"use strict";
|
|
102561
|
+
|
|
102562
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
102563
|
+
if (k2 === undefined) k2 = k;
|
|
102564
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
102565
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
102566
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
102567
|
+
}
|
|
102568
|
+
Object.defineProperty(o, k2, desc);
|
|
102569
|
+
}) : (function(o, m, k, k2) {
|
|
102570
|
+
if (k2 === undefined) k2 = k;
|
|
102571
|
+
o[k2] = m[k];
|
|
102572
|
+
}));
|
|
102573
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
102574
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
102575
|
+
}) : function(o, v) {
|
|
102576
|
+
o["default"] = v;
|
|
102577
|
+
});
|
|
102578
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
102579
|
+
var ownKeys = function(o) {
|
|
102580
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
102581
|
+
var ar = [];
|
|
102582
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
102583
|
+
return ar;
|
|
102584
|
+
};
|
|
102585
|
+
return ownKeys(o);
|
|
102586
|
+
};
|
|
102587
|
+
return function (mod) {
|
|
102588
|
+
if (mod && mod.__esModule) return mod;
|
|
102589
|
+
var result = {};
|
|
102590
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
102591
|
+
__setModuleDefault(result, mod);
|
|
102592
|
+
return result;
|
|
102593
|
+
};
|
|
102594
|
+
})();
|
|
102595
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
102596
|
+
exports.SingleUseExpressionTemp = exports.SingleUseExpressionTempConf = void 0;
|
|
102597
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
102598
|
+
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
|
|
102599
|
+
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
|
|
102600
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
102601
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
102602
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
102603
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
102604
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
102605
|
+
class SingleUseExpressionTempConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
102606
|
+
}
|
|
102607
|
+
exports.SingleUseExpressionTempConf = SingleUseExpressionTempConf;
|
|
102608
|
+
/** builtin functions whose result type follows the type of the argument */
|
|
102609
|
+
const NUMERIC_FUNCTIONS = new Set(["abs", "sign", "ceil", "floor", "trunc", "frac", "ipow", "nmax", "nmin",
|
|
102610
|
+
"round", "rescale"]);
|
|
102611
|
+
/** constructor expressions that can build the result directly in the target */
|
|
102612
|
+
const IN_PLACE = new Set(["VALUE", "CORRESPONDING", "COND", "SWITCH", "REDUCE", "FILTER"]);
|
|
102613
|
+
class SingleUseExpressionTemp {
|
|
102614
|
+
constructor() {
|
|
102615
|
+
this.conf = new SingleUseExpressionTempConf();
|
|
102616
|
+
}
|
|
102617
|
+
getMetadata() {
|
|
102618
|
+
return {
|
|
102619
|
+
key: "single_use_expression_temp",
|
|
102620
|
+
title: "Single use expression temporary",
|
|
102621
|
+
shortDescription: `Finds DATA(a) = <expression>. directly followed by x = a., assign the expression to x`,
|
|
102622
|
+
extendedInformation: `Reports DATA(a) = <expression>. when all of the following hold:
|
|
102623
|
+
|
|
102624
|
+
* a is a local variable of a METHOD, FORM or FUNCTION, with no other reference than the next statement,
|
|
102625
|
+
which is x = a., in the same block
|
|
102626
|
+
* the result type of the expression does not depend on the target: no arithmetic or bit operators, no unary
|
|
102627
|
+
minus, no numeric functions like abs( ) or trunc( ) whose type follows the argument, no CONV or EXACT,
|
|
102628
|
+
no # type inference at the top. String templates, && concatenations, literals, method calls, NEW, CAST,
|
|
102629
|
+
constructor expressions with explicit type and table expressions are fine
|
|
102630
|
+
* VALUE, CORRESPONDING, COND, SWITCH, REDUCE and FILTER can build their result directly in the target,
|
|
102631
|
+
they are only inlined into a new variable, or a local variable that they do not read and whose address
|
|
102632
|
+
is never taken
|
|
102633
|
+
* plain data objects are left for unnecessary_copy
|
|
102634
|
+
|
|
102635
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
102636
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
102637
|
+
|
|
102638
|
+
The quick fix deletes the declaration and writes x = <expression>. No release requirement.`,
|
|
102639
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
102640
|
+
badExample: `DATA(lo_conf) = NEW zcl_conf( ).
|
|
102641
|
+
mo_conf = lo_conf.`,
|
|
102642
|
+
goodExample: `mo_conf = NEW zcl_conf( ).`,
|
|
102643
|
+
};
|
|
102644
|
+
}
|
|
102645
|
+
getConfig() {
|
|
102646
|
+
return this.conf;
|
|
102647
|
+
}
|
|
102648
|
+
setConfig(conf) {
|
|
102649
|
+
this.conf = conf;
|
|
102650
|
+
}
|
|
102651
|
+
initialize(reg) {
|
|
102652
|
+
this.reg = reg;
|
|
102653
|
+
return this;
|
|
102654
|
+
}
|
|
102655
|
+
run(obj) {
|
|
102656
|
+
var _a;
|
|
102657
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
102658
|
+
if (analysis === undefined) {
|
|
102659
|
+
return [];
|
|
102660
|
+
}
|
|
102661
|
+
const issues = [];
|
|
102662
|
+
for (const procedure of analysis.procedures) {
|
|
102663
|
+
if (procedure.supported === false) {
|
|
102664
|
+
continue;
|
|
102665
|
+
}
|
|
102666
|
+
for (const variable of procedure.locals()) {
|
|
102667
|
+
const declaration = variable.declaration;
|
|
102668
|
+
const move = variable.inline ? (0, _procedure_analysis_1.plainMove)(declaration) : undefined;
|
|
102669
|
+
const read = variable.occurrences[0];
|
|
102670
|
+
if (move === undefined || move.operator !== "="
|
|
102671
|
+
|| move.target.getChildren().length !== 1
|
|
102672
|
+
|| move.target.findDirectExpression(Expressions.InlineData) === undefined
|
|
102673
|
+
|| variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
|
|
102674
|
+
|| read.statement !== procedure.statements[procedure.index(declaration) + 1]
|
|
102675
|
+
|| procedure.block(read.statement) !== procedure.block(declaration)
|
|
102676
|
+
|| !procedure.isSimple(read.statement)) {
|
|
102677
|
+
continue;
|
|
102678
|
+
}
|
|
102679
|
+
const use = (0, _procedure_analysis_1.plainMove)(read.statement);
|
|
102680
|
+
if (use === undefined || use.operator !== "="
|
|
102681
|
+
|| ((_a = (0, _procedure_analysis_1.singleField)(use.source)) === null || _a === void 0 ? void 0 : _a.getStart().equals(read.token.getStart())) !== true
|
|
102682
|
+
|| (0, _procedure_analysis_1.dataSource)(procedure, move.source) !== undefined
|
|
102683
|
+
|| !this.targetIndependent(procedure, move.source)
|
|
102684
|
+
|| !this.noAliasing(procedure, move.source, use.target)) {
|
|
102685
|
+
continue;
|
|
102686
|
+
}
|
|
102687
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
|
|
102688
|
+
edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, (0, _procedure_analysis_1.nodeText)(procedure.file, move.source)),
|
|
102689
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)
|
|
102690
|
+
]);
|
|
102691
|
+
const message = "Assign the expression directly instead of via " + variable.identifier.getName();
|
|
102692
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, declaration, message, this.getMetadata().key, this.conf.severity, fix));
|
|
102693
|
+
}
|
|
102694
|
+
}
|
|
102695
|
+
return issues;
|
|
102696
|
+
}
|
|
102697
|
+
/** the type of the expression does not depend on where it is assigned to */
|
|
102698
|
+
targetIndependent(procedure, source) {
|
|
102699
|
+
var _a, _b;
|
|
102700
|
+
const first = source.getFirstToken().getStr().toUpperCase();
|
|
102701
|
+
if (first === "CONV" || first === "EXACT"
|
|
102702
|
+
|| ((_a = source.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _a === void 0 ? void 0 : _a.concatTokens()) === "#"
|
|
102703
|
+
|| source.findFirstExpression(Expressions.ArithOperator) !== undefined
|
|
102704
|
+
|| source.getTokens().some(t => t.getStr().toUpperCase().startsWith("BIT-"))
|
|
102705
|
+
|| !this.concatenationOnly(source)) {
|
|
102706
|
+
return false;
|
|
102707
|
+
}
|
|
102708
|
+
for (const call of source.findAllExpressionsRecursive(Expressions.MethodCall)) {
|
|
102709
|
+
const name = (_b = call.findDirectExpression(Expressions.MethodName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
|
|
102710
|
+
if (name === undefined) {
|
|
102711
|
+
return false;
|
|
102712
|
+
}
|
|
102713
|
+
const builtin = procedure.analysis.referencesAt(procedure.file.getFilename(), name)
|
|
102714
|
+
.some(r => r.referenceType === _reference_1.ReferenceType.BuiltinMethodReference);
|
|
102715
|
+
if (builtin && NUMERIC_FUNCTIONS.has(name.getStr().toLowerCase())) {
|
|
102716
|
+
return false;
|
|
102717
|
+
}
|
|
102718
|
+
}
|
|
102719
|
+
return true;
|
|
102720
|
+
}
|
|
102721
|
+
/** one operand, or operands joined by && */
|
|
102722
|
+
concatenationOnly(source) {
|
|
102723
|
+
const children = source.getChildren();
|
|
102724
|
+
if (children.length === 1) {
|
|
102725
|
+
return true;
|
|
102726
|
+
}
|
|
102727
|
+
if (children.length === 3 && children[1] instanceof nodes_1.TokenNode && children[1].getFirstToken().getStr() === "&&"
|
|
102728
|
+
&& children[0] instanceof nodes_1.ExpressionNode && children[2] instanceof nodes_1.ExpressionNode
|
|
102729
|
+
&& children[2].get() instanceof Expressions.Source) {
|
|
102730
|
+
return !(children[0].get() instanceof Expressions.Source) && this.concatenationOnly(children[2]);
|
|
102731
|
+
}
|
|
102732
|
+
const first = children[0] instanceof nodes_1.TokenNode ? children[0].getFirstToken().getStr().toUpperCase() : "";
|
|
102733
|
+
if ((first === "XSDBOOL" || first === "BOOLC") && source.findDirectExpression(Expressions.Cond) !== undefined) {
|
|
102734
|
+
return true;
|
|
102735
|
+
}
|
|
102736
|
+
// constructor expressions: KEYWORD type( ... )
|
|
102737
|
+
return first !== "" && first !== "-"
|
|
102738
|
+
&& children[1] instanceof nodes_1.ExpressionNode && children[1].get() instanceof Expressions.TypeNameOrInfer;
|
|
102739
|
+
}
|
|
102740
|
+
/** constructor expressions that build their result directly in the target are only inlined into a new
|
|
102741
|
+
* variable, or into a local variable which the expression does not read and which nothing else can reach */
|
|
102742
|
+
noAliasing(procedure, source, target) {
|
|
102743
|
+
if (!IN_PLACE.has(source.getFirstToken().getStr().toUpperCase())
|
|
102744
|
+
|| target.findDirectExpression(Expressions.InlineData) !== undefined) {
|
|
102745
|
+
return true;
|
|
102746
|
+
}
|
|
102747
|
+
const field = target.getChildren()[0];
|
|
102748
|
+
const local = target.getChildren().length === 1 && field instanceof nodes_1.ExpressionNode
|
|
102749
|
+
&& field.get() instanceof Expressions.TargetField
|
|
102750
|
+
? procedure.local(procedure.identifierAt(field.getFirstToken())) : undefined;
|
|
102751
|
+
if (local === undefined || local.escapes()) {
|
|
102752
|
+
return false;
|
|
102753
|
+
}
|
|
102754
|
+
const key = _procedure_analysis_1.ObjectAnalysis.key(local.identifier);
|
|
102755
|
+
return source.getTokens().every(t => {
|
|
102756
|
+
const identifier = procedure.identifierAt(t);
|
|
102757
|
+
return identifier === undefined || _procedure_analysis_1.ObjectAnalysis.key(identifier) !== key;
|
|
102758
|
+
});
|
|
102759
|
+
}
|
|
102760
|
+
}
|
|
102761
|
+
exports.SingleUseExpressionTemp = SingleUseExpressionTemp;
|
|
102762
|
+
//# sourceMappingURL=single_use_expression_temp.js.map
|
|
102763
|
+
|
|
102764
|
+
/***/ },
|
|
102765
|
+
|
|
100069
102766
|
/***/ "../core/build/src/rules/slow_parameter_passing.js"
|
|
100070
102767
|
/*!*********************************************************!*\
|
|
100071
102768
|
!*** ../core/build/src/rules/slow_parameter_passing.js ***!
|
|
@@ -102140,6 +104837,175 @@ exports.TablesDeclaredLocally = TablesDeclaredLocally;
|
|
|
102140
104837
|
|
|
102141
104838
|
/***/ },
|
|
102142
104839
|
|
|
104840
|
+
/***/ "../core/build/src/rules/try_cast_empty_catch.js"
|
|
104841
|
+
/*!*******************************************************!*\
|
|
104842
|
+
!*** ../core/build/src/rules/try_cast_empty_catch.js ***!
|
|
104843
|
+
\*******************************************************/
|
|
104844
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
104845
|
+
|
|
104846
|
+
"use strict";
|
|
104847
|
+
|
|
104848
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
104849
|
+
if (k2 === undefined) k2 = k;
|
|
104850
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
104851
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
104852
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
104853
|
+
}
|
|
104854
|
+
Object.defineProperty(o, k2, desc);
|
|
104855
|
+
}) : (function(o, m, k, k2) {
|
|
104856
|
+
if (k2 === undefined) k2 = k;
|
|
104857
|
+
o[k2] = m[k];
|
|
104858
|
+
}));
|
|
104859
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
104860
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
104861
|
+
}) : function(o, v) {
|
|
104862
|
+
o["default"] = v;
|
|
104863
|
+
});
|
|
104864
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
104865
|
+
var ownKeys = function(o) {
|
|
104866
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
104867
|
+
var ar = [];
|
|
104868
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
104869
|
+
return ar;
|
|
104870
|
+
};
|
|
104871
|
+
return ownKeys(o);
|
|
104872
|
+
};
|
|
104873
|
+
return function (mod) {
|
|
104874
|
+
if (mod && mod.__esModule) return mod;
|
|
104875
|
+
var result = {};
|
|
104876
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
104877
|
+
__setModuleDefault(result, mod);
|
|
104878
|
+
return result;
|
|
104879
|
+
};
|
|
104880
|
+
})();
|
|
104881
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
104882
|
+
exports.TryCastEmptyCatch = exports.TryCastEmptyCatchConf = void 0;
|
|
104883
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
104884
|
+
const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
|
|
104885
|
+
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
|
|
104886
|
+
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
104887
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
104888
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
104889
|
+
const version_1 = __webpack_require__(/*! ../version */ "../core/build/src/version.js");
|
|
104890
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
104891
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
104892
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
104893
|
+
class TryCastEmptyCatchConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
104894
|
+
}
|
|
104895
|
+
exports.TryCastEmptyCatchConf = TryCastEmptyCatchConf;
|
|
104896
|
+
class TryCastEmptyCatch {
|
|
104897
|
+
constructor() {
|
|
104898
|
+
this.conf = new TryCastEmptyCatchConf();
|
|
104899
|
+
}
|
|
104900
|
+
getMetadata() {
|
|
104901
|
+
return {
|
|
104902
|
+
key: "try_cast_empty_catch",
|
|
104903
|
+
title: "TRY around cast with empty CATCH",
|
|
104904
|
+
shortDescription: `Finds a down cast in TRY with an empty CATCH cx_sy_move_cast_error, use IS INSTANCE OF`,
|
|
104905
|
+
extendedInformation: `Reports TRY. a ?= b. CATCH cx_sy_move_cast_error. ENDTRY. when all of the following hold:
|
|
104906
|
+
|
|
104907
|
+
* the cast is the only statement of the TRY block, there is exactly one CATCH, for cx_sy_move_cast_error only,
|
|
104908
|
+
without INTO or BEFORE UNWIND, its block is empty, and there is no CLEANUP
|
|
104909
|
+
* the static type of a is a class or interface, not a generic REF TO object
|
|
104910
|
+
* b is a plain data object: variable, attribute or a chain of components and attributes, without calls,
|
|
104911
|
+
so evaluating it again has no side effects
|
|
104912
|
+
|
|
104913
|
+
a ?= b. also succeeds when b is initial, and then clears a, while b IS INSTANCE OF is false for an initial b,
|
|
104914
|
+
so the quick fix replaces the TRY with IF b IS INSTANCE OF <type of a> OR b IS INITIAL. a ?= b. ENDIF.
|
|
104915
|
+
|
|
104916
|
+
Requires IS INSTANCE OF, ie. 7.50 or above, ABAP Cloud or open-abap.
|
|
104917
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
104918
|
+
INCLUDE, test seams, enhancements or native SQL.`,
|
|
104919
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
104920
|
+
badExample: `TRY.
|
|
104921
|
+
lo_node ?= io_object.
|
|
104922
|
+
CATCH cx_sy_move_cast_error.
|
|
104923
|
+
ENDTRY.`,
|
|
104924
|
+
goodExample: `IF io_object IS INSTANCE OF zcl_node OR io_object IS INITIAL.
|
|
104925
|
+
lo_node ?= io_object.
|
|
104926
|
+
ENDIF.`,
|
|
104927
|
+
};
|
|
104928
|
+
}
|
|
104929
|
+
getConfig() {
|
|
104930
|
+
return this.conf;
|
|
104931
|
+
}
|
|
104932
|
+
setConfig(conf) {
|
|
104933
|
+
this.conf = conf;
|
|
104934
|
+
}
|
|
104935
|
+
initialize(reg) {
|
|
104936
|
+
this.reg = reg;
|
|
104937
|
+
return this;
|
|
104938
|
+
}
|
|
104939
|
+
run(obj) {
|
|
104940
|
+
const config = this.reg.getConfig();
|
|
104941
|
+
if (!(0, version_1.releaseAtLeast)(config.getRelease(), version_1.Release.v750)
|
|
104942
|
+
&& config.getLanguageVersion() !== version_1.LanguageVersion.Cloud
|
|
104943
|
+
&& !config.isOpenABAP()) {
|
|
104944
|
+
return [];
|
|
104945
|
+
}
|
|
104946
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
104947
|
+
if (analysis === undefined) {
|
|
104948
|
+
return [];
|
|
104949
|
+
}
|
|
104950
|
+
const issues = [];
|
|
104951
|
+
for (const procedure of analysis.procedures) {
|
|
104952
|
+
if (procedure.supported === false) {
|
|
104953
|
+
continue;
|
|
104954
|
+
}
|
|
104955
|
+
for (const structure of procedure.structure.findAllStructuresRecursive(Structures.Try)) {
|
|
104956
|
+
this.check(procedure, structure, issues);
|
|
104957
|
+
}
|
|
104958
|
+
}
|
|
104959
|
+
return issues;
|
|
104960
|
+
}
|
|
104961
|
+
check(procedure, structure, issues) {
|
|
104962
|
+
const children = structure.getChildren();
|
|
104963
|
+
const tryStatement = children[0];
|
|
104964
|
+
const body = children[1];
|
|
104965
|
+
const catchStructure = children[2];
|
|
104966
|
+
const endTry = children[3];
|
|
104967
|
+
if (children.length !== 4
|
|
104968
|
+
|| !(tryStatement instanceof nodes_1.StatementNode) || tryStatement.getColon() !== undefined
|
|
104969
|
+
|| !(body instanceof nodes_1.StructureNode) || !(body.get() instanceof Structures.Body)
|
|
104970
|
+
|| !(catchStructure instanceof nodes_1.StructureNode) || !(catchStructure.get() instanceof Structures.Catch)
|
|
104971
|
+
|| !(endTry instanceof nodes_1.StatementNode) || !(endTry.get() instanceof Statements.EndTry)
|
|
104972
|
+
|| endTry.getColon() !== undefined) {
|
|
104973
|
+
return;
|
|
104974
|
+
}
|
|
104975
|
+
const statements = body.findAllStatementNodes();
|
|
104976
|
+
const catchStatements = catchStructure.findAllStatementNodes();
|
|
104977
|
+
const catchStatement = catchStatements[0];
|
|
104978
|
+
const tokens = catchStatement === null || catchStatement === void 0 ? void 0 : catchStatement.getTokens().map(t => t.getStr().toUpperCase());
|
|
104979
|
+
if (statements.length !== 1 || catchStatements.length !== 1 || catchStatement.getColon() !== undefined
|
|
104980
|
+
|| (tokens === null || tokens === void 0 ? void 0 : tokens.join(" ")) !== "CATCH CX_SY_MOVE_CAST_ERROR .") {
|
|
104981
|
+
return;
|
|
104982
|
+
}
|
|
104983
|
+
const cast = statements[0];
|
|
104984
|
+
const move = (0, _procedure_analysis_1.plainMove)(cast);
|
|
104985
|
+
const target = move === undefined ? undefined : (0, _procedure_analysis_1.targetType)(procedure, move.target);
|
|
104986
|
+
const source = move === undefined ? undefined : (0, _procedure_analysis_1.dataSource)(procedure, move.source);
|
|
104987
|
+
if (move === undefined || move.operator !== "?=" || source === undefined
|
|
104988
|
+
|| !(target instanceof basic_1.ObjectReferenceType)
|
|
104989
|
+
|| target.getIdentifierName().toUpperCase() === "OBJECT"
|
|
104990
|
+
|| procedure.hasComment(tryStatement.getStart(), endTry.getEnd())) {
|
|
104991
|
+
return;
|
|
104992
|
+
}
|
|
104993
|
+
const condition = "IF " + source.text + " IS INSTANCE OF " + target.getIdentifierName()
|
|
104994
|
+
+ " OR " + source.text + " IS INITIAL.";
|
|
104995
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
|
|
104996
|
+
edit_helper_1.EditHelper.replaceRange(procedure.file, tryStatement.getStart(), tryStatement.getEnd(), condition),
|
|
104997
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, catchStatement),
|
|
104998
|
+
edit_helper_1.EditHelper.replaceToken(procedure.file, endTry.getFirstToken(), "ENDIF")
|
|
104999
|
+
]);
|
|
105000
|
+
const message = "Check with IS INSTANCE OF instead of catching cx_sy_move_cast_error";
|
|
105001
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, tryStatement, message, this.getMetadata().key, this.conf.severity, fix));
|
|
105002
|
+
}
|
|
105003
|
+
}
|
|
105004
|
+
exports.TryCastEmptyCatch = TryCastEmptyCatch;
|
|
105005
|
+
//# sourceMappingURL=try_cast_empty_catch.js.map
|
|
105006
|
+
|
|
105007
|
+
/***/ },
|
|
105008
|
+
|
|
102143
105009
|
/***/ "../core/build/src/rules/try_without_catch.js"
|
|
102144
105010
|
/*!****************************************************!*\
|
|
102145
105011
|
!*** ../core/build/src/rules/try_without_catch.js ***!
|
|
@@ -103050,6 +105916,149 @@ exports.UnnecessaryChaining = UnnecessaryChaining;
|
|
|
103050
105916
|
|
|
103051
105917
|
/***/ },
|
|
103052
105918
|
|
|
105919
|
+
/***/ "../core/build/src/rules/unnecessary_copy.js"
|
|
105920
|
+
/*!***************************************************!*\
|
|
105921
|
+
!*** ../core/build/src/rules/unnecessary_copy.js ***!
|
|
105922
|
+
\***************************************************/
|
|
105923
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
105924
|
+
|
|
105925
|
+
"use strict";
|
|
105926
|
+
|
|
105927
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
105928
|
+
if (k2 === undefined) k2 = k;
|
|
105929
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
105930
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
105931
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
105932
|
+
}
|
|
105933
|
+
Object.defineProperty(o, k2, desc);
|
|
105934
|
+
}) : (function(o, m, k, k2) {
|
|
105935
|
+
if (k2 === undefined) k2 = k;
|
|
105936
|
+
o[k2] = m[k];
|
|
105937
|
+
}));
|
|
105938
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
105939
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
105940
|
+
}) : function(o, v) {
|
|
105941
|
+
o["default"] = v;
|
|
105942
|
+
});
|
|
105943
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
105944
|
+
var ownKeys = function(o) {
|
|
105945
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
105946
|
+
var ar = [];
|
|
105947
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
105948
|
+
return ar;
|
|
105949
|
+
};
|
|
105950
|
+
return ownKeys(o);
|
|
105951
|
+
};
|
|
105952
|
+
return function (mod) {
|
|
105953
|
+
if (mod && mod.__esModule) return mod;
|
|
105954
|
+
var result = {};
|
|
105955
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
105956
|
+
__setModuleDefault(result, mod);
|
|
105957
|
+
return result;
|
|
105958
|
+
};
|
|
105959
|
+
})();
|
|
105960
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
105961
|
+
exports.UnnecessaryCopy = exports.UnnecessaryCopyConf = void 0;
|
|
105962
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
105963
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
105964
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
105965
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
105966
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
105967
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
105968
|
+
class UnnecessaryCopyConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
105969
|
+
}
|
|
105970
|
+
exports.UnnecessaryCopyConf = UnnecessaryCopyConf;
|
|
105971
|
+
class UnnecessaryCopy {
|
|
105972
|
+
constructor() {
|
|
105973
|
+
this.conf = new UnnecessaryCopyConf();
|
|
105974
|
+
}
|
|
105975
|
+
getMetadata() {
|
|
105976
|
+
return {
|
|
105977
|
+
key: "unnecessary_copy",
|
|
105978
|
+
title: "Unnecessary copy",
|
|
105979
|
+
shortDescription: `Finds DATA(a) = b. where a is read exactly once, and b can be read instead`,
|
|
105980
|
+
extendedInformation: `Reports DATA(a) = b. when all of the following hold:
|
|
105981
|
+
|
|
105982
|
+
* a is a local variable of a METHOD, FORM or FUNCTION, and has exactly one more reference: a read,
|
|
105983
|
+
which does not take its address, bind a field symbol to it, or pass it to USING, CHANGING or EXPORTING
|
|
105984
|
+
* b is a plain data object: variable, constant, attribute, or a chain of components and attributes,
|
|
105985
|
+
without calls, offsets, table expressions, field symbols or ->*
|
|
105986
|
+
* the declaration is executed before the read on every path: the read is in the block of the declaration
|
|
105987
|
+
or a nested block, and both are in the same loop
|
|
105988
|
+
* b keeps its value from the declaration until the read: for a local b, no write to it and its address is
|
|
105989
|
+
never taken; for other b, in addition no method, function or form call and no write except to local
|
|
105990
|
+
variables, by value parameters and RETURNING in between
|
|
105991
|
+
|
|
105992
|
+
a has the type of b, so reading b instead does not change any conversion.
|
|
105993
|
+
A constant b read in IF, ELSEIF, WHILE, CHECK, CASE or WHEN is not reported, see constant_condition.
|
|
105994
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
105995
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
105996
|
+
|
|
105997
|
+
The quick fix deletes the declaration and replaces the read of a with b. No release requirement,
|
|
105998
|
+
inline declarations need 7.40 SP02 already.
|
|
105999
|
+
|
|
106000
|
+
See also alias_never_reassigned for copies that are read several times.`,
|
|
106001
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
106002
|
+
badExample: `DATA(lv_name) = iv_name.
|
|
106003
|
+
rv_text = |Hello { lv_name }|.`,
|
|
106004
|
+
goodExample: `rv_text = |Hello { iv_name }|.`,
|
|
106005
|
+
};
|
|
106006
|
+
}
|
|
106007
|
+
getConfig() {
|
|
106008
|
+
return this.conf;
|
|
106009
|
+
}
|
|
106010
|
+
setConfig(conf) {
|
|
106011
|
+
this.conf = conf;
|
|
106012
|
+
}
|
|
106013
|
+
initialize(reg) {
|
|
106014
|
+
this.reg = reg;
|
|
106015
|
+
return this;
|
|
106016
|
+
}
|
|
106017
|
+
run(obj) {
|
|
106018
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
106019
|
+
if (analysis === undefined) {
|
|
106020
|
+
return [];
|
|
106021
|
+
}
|
|
106022
|
+
const issues = [];
|
|
106023
|
+
for (const procedure of analysis.procedures) {
|
|
106024
|
+
if (procedure.supported === false) {
|
|
106025
|
+
continue;
|
|
106026
|
+
}
|
|
106027
|
+
for (const variable of procedure.locals()) {
|
|
106028
|
+
const declaration = variable.declaration;
|
|
106029
|
+
const move = variable.inline ? (0, _procedure_analysis_1.plainMove)(declaration) : undefined;
|
|
106030
|
+
const read = variable.occurrences[0];
|
|
106031
|
+
if (move === undefined || move.operator !== "="
|
|
106032
|
+
|| move.target.getChildren().length !== 1
|
|
106033
|
+
|| move.target.findDirectExpression(Expressions.InlineData) === undefined
|
|
106034
|
+
|| variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
|
|
106035
|
+
|| variable.identifier.getType().isGeneric()
|
|
106036
|
+
|| !procedure.dominates(declaration, read.statement)
|
|
106037
|
+
|| !procedure.sameLoop(declaration, read.statement)) {
|
|
106038
|
+
continue;
|
|
106039
|
+
}
|
|
106040
|
+
const source = (0, _procedure_analysis_1.dataSource)(procedure, move.source);
|
|
106041
|
+
if (source === undefined || source.base === variable
|
|
106042
|
+
|| (source.kind === _procedure_analysis_1.SourceKind.Immutable && (0, _procedure_analysis_1.isCondition)(read.statement))
|
|
106043
|
+
|| !(0, _procedure_analysis_1.unchangedBetween)(procedure, source, declaration, read.statement, read.token)) {
|
|
106044
|
+
continue;
|
|
106045
|
+
}
|
|
106046
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
|
|
106047
|
+
edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, source.text),
|
|
106048
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)
|
|
106049
|
+
]);
|
|
106050
|
+
const message = "Unnecessary copy " + variable.identifier.getName() + ", read " + source.text + " instead";
|
|
106051
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, declaration, message, this.getMetadata().key, this.conf.severity, fix));
|
|
106052
|
+
}
|
|
106053
|
+
}
|
|
106054
|
+
return issues;
|
|
106055
|
+
}
|
|
106056
|
+
}
|
|
106057
|
+
exports.UnnecessaryCopy = UnnecessaryCopy;
|
|
106058
|
+
//# sourceMappingURL=unnecessary_copy.js.map
|
|
106059
|
+
|
|
106060
|
+
/***/ },
|
|
106061
|
+
|
|
103053
106062
|
/***/ "../core/build/src/rules/unnecessary_loop_guard.js"
|
|
103054
106063
|
/*!*********************************************************!*\
|
|
103055
106064
|
!*** ../core/build/src/rules/unnecessary_loop_guard.js ***!
|