@abaplint/cli 2.120.103 → 2.120.105
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 +223 -92
- package/package.json +2 -2
package/build/cli.js
CHANGED
|
@@ -45190,6 +45190,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
45190
45190
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
45191
45191
|
exports.ModifyInternal = void 0;
|
|
45192
45192
|
const Expressions = __importStar(__webpack_require__(/*! ../../2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
45193
|
+
const nodes_1 = __webpack_require__(/*! ../../nodes */ "../core/build/src/abap/nodes/index.js");
|
|
45193
45194
|
const source_1 = __webpack_require__(/*! ../expressions/source */ "../core/build/src/abap/5_syntax/expressions/source.js");
|
|
45194
45195
|
const target_1 = __webpack_require__(/*! ../expressions/target */ "../core/build/src/abap/5_syntax/expressions/target.js");
|
|
45195
45196
|
const fstarget_1 = __webpack_require__(/*! ../expressions/fstarget */ "../core/build/src/abap/5_syntax/expressions/fstarget.js");
|
|
@@ -45198,15 +45199,22 @@ const basic_1 = __webpack_require__(/*! ../../types/basic */ "../core/build/src/
|
|
|
45198
45199
|
const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "../core/build/src/abap/5_syntax/_syntax_input.js");
|
|
45199
45200
|
class ModifyInternal {
|
|
45200
45201
|
runSyntax(node, input) {
|
|
45201
|
-
|
|
45202
|
-
source_1.Source.runSyntax(s, input);
|
|
45203
|
-
}
|
|
45202
|
+
var _a;
|
|
45204
45203
|
// there is only one
|
|
45205
45204
|
const target = node.findFirstExpression(Expressions.Target);
|
|
45206
|
-
|
|
45207
|
-
|
|
45208
|
-
|
|
45209
|
-
|
|
45205
|
+
// it might be a dynamic target
|
|
45206
|
+
const targetType = target ? target_1.Target.runSyntax(target, input) : undefined;
|
|
45207
|
+
// the FROM work area has the row type of the table, used for inferring "#"
|
|
45208
|
+
const rowType = targetType instanceof basic_1.TableType ? targetType.getRowType() : undefined;
|
|
45209
|
+
const children = node.getChildren();
|
|
45210
|
+
for (let i = 0; i < children.length; i++) {
|
|
45211
|
+
const s = children[i];
|
|
45212
|
+
if (s instanceof nodes_1.ExpressionNode && s.get() instanceof Expressions.Source) {
|
|
45213
|
+
const isFrom = ((_a = children[i - 1]) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === "FROM";
|
|
45214
|
+
source_1.Source.runSyntax(s, input, isFrom ? rowType : undefined);
|
|
45215
|
+
}
|
|
45216
|
+
}
|
|
45217
|
+
if (target) {
|
|
45210
45218
|
if (targetType instanceof basic_1.VoidType
|
|
45211
45219
|
|| targetType instanceof basic_1.AnyType
|
|
45212
45220
|
|| targetType instanceof basic_1.UnknownType) {
|
|
@@ -51069,7 +51077,8 @@ class SyntaxLogic {
|
|
|
51069
51077
|
}
|
|
51070
51078
|
}
|
|
51071
51079
|
}
|
|
51072
|
-
|
|
51080
|
+
// statements only have expressions and tokens as children, nothing to traverse
|
|
51081
|
+
if (isStructure) {
|
|
51073
51082
|
this.traverse(child);
|
|
51074
51083
|
}
|
|
51075
51084
|
}
|
|
@@ -61179,6 +61188,31 @@ exports.MemoryFile = MemoryFile;
|
|
|
61179
61188
|
|
|
61180
61189
|
/***/ },
|
|
61181
61190
|
|
|
61191
|
+
/***/ "../core/build/src/files/raw_rows_cache.js"
|
|
61192
|
+
/*!*************************************************!*\
|
|
61193
|
+
!*** ../core/build/src/files/raw_rows_cache.js ***!
|
|
61194
|
+
\*************************************************/
|
|
61195
|
+
(__unused_webpack_module, exports) {
|
|
61196
|
+
|
|
61197
|
+
"use strict";
|
|
61198
|
+
|
|
61199
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
61200
|
+
exports.getCachedRawRows = getCachedRawRows;
|
|
61201
|
+
const rowCache = new WeakMap();
|
|
61202
|
+
/** getRawRows() splits the source on every call; a file is never changed, edits create a new one,
|
|
61203
|
+
* so the rows can be cached per file object. The result must not be modified */
|
|
61204
|
+
function getCachedRawRows(file) {
|
|
61205
|
+
let rows = rowCache.get(file);
|
|
61206
|
+
if (rows === undefined) {
|
|
61207
|
+
rows = file.getRawRows();
|
|
61208
|
+
rowCache.set(file, rows);
|
|
61209
|
+
}
|
|
61210
|
+
return rows;
|
|
61211
|
+
}
|
|
61212
|
+
//# sourceMappingURL=raw_rows_cache.js.map
|
|
61213
|
+
|
|
61214
|
+
/***/ },
|
|
61215
|
+
|
|
61182
61216
|
/***/ "../core/build/src/index.js"
|
|
61183
61217
|
/*!**********************************!*\
|
|
61184
61218
|
!*** ../core/build/src/index.js ***!
|
|
@@ -61363,11 +61397,12 @@ exports.Issue = void 0;
|
|
|
61363
61397
|
const position_1 = __webpack_require__(/*! ./position */ "../core/build/src/position.js");
|
|
61364
61398
|
const virtual_position_1 = __webpack_require__(/*! ./virtual_position */ "../core/build/src/virtual_position.js");
|
|
61365
61399
|
const severity_1 = __webpack_require__(/*! ./severity */ "../core/build/src/severity.js");
|
|
61400
|
+
const raw_rows_cache_1 = __webpack_require__(/*! ./files/raw_rows_cache */ "../core/build/src/files/raw_rows_cache.js");
|
|
61366
61401
|
class Issue {
|
|
61367
61402
|
//////////////////////////
|
|
61368
61403
|
static atRow(file, row, message, key, severity) {
|
|
61369
61404
|
const start = new position_1.Position(row, 1);
|
|
61370
|
-
const end = new position_1.Position(row,
|
|
61405
|
+
const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
|
|
61371
61406
|
severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
|
|
61372
61407
|
return new Issue({
|
|
61373
61408
|
filename: file.getFilename(),
|
|
@@ -61383,7 +61418,7 @@ class Issue {
|
|
|
61383
61418
|
}
|
|
61384
61419
|
static atPosition(file, start, message, key, severity, fix) {
|
|
61385
61420
|
const row = start.getRow();
|
|
61386
|
-
const end = new position_1.Position(row,
|
|
61421
|
+
const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
|
|
61387
61422
|
severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
|
|
61388
61423
|
return new Issue({
|
|
61389
61424
|
filename: file.getFilename(),
|
|
@@ -73587,6 +73622,8 @@ class Registry {
|
|
|
73587
73622
|
this.objects = {};
|
|
73588
73623
|
this.objectsByType = {};
|
|
73589
73624
|
this.dependencies = {};
|
|
73625
|
+
/** upper case filename to object containing the file, kept in sync by add/remove methods */
|
|
73626
|
+
this.filenameIndex = new Map();
|
|
73590
73627
|
this.setConfig(conf ? conf : config_1.Config.getDefault());
|
|
73591
73628
|
this.clear();
|
|
73592
73629
|
}
|
|
@@ -73595,13 +73632,14 @@ class Registry {
|
|
|
73595
73632
|
this.objects = {};
|
|
73596
73633
|
this.objectsByType = {};
|
|
73597
73634
|
this.dependencies = {};
|
|
73635
|
+
this.filenameIndex = new Map();
|
|
73598
73636
|
this.ddicReferences = new ddic_references_1.DDICReferences();
|
|
73599
73637
|
this.msagReferences = new msag_references_1.MSAGReferences();
|
|
73600
73638
|
this.macroReferences = new macro_references_1.MacroReferences();
|
|
73601
73639
|
}
|
|
73602
73640
|
static abaplintVersion() {
|
|
73603
73641
|
// magic, see build script "version.js"
|
|
73604
|
-
return "2.120.
|
|
73642
|
+
return "2.120.105";
|
|
73605
73643
|
}
|
|
73606
73644
|
getDDICReferences() {
|
|
73607
73645
|
return this.ddicReferences;
|
|
@@ -73654,11 +73692,13 @@ class Registry {
|
|
|
73654
73692
|
}
|
|
73655
73693
|
getFileByName(filename) {
|
|
73656
73694
|
const upper = filename.toUpperCase();
|
|
73657
|
-
|
|
73658
|
-
|
|
73659
|
-
|
|
73660
|
-
|
|
73661
|
-
|
|
73695
|
+
const obj = this.filenameIndex.get(upper);
|
|
73696
|
+
if (obj === undefined) {
|
|
73697
|
+
return undefined;
|
|
73698
|
+
}
|
|
73699
|
+
for (const f of obj.getFiles()) {
|
|
73700
|
+
if (f.getFilename().toUpperCase() === upper) {
|
|
73701
|
+
return f;
|
|
73662
73702
|
}
|
|
73663
73703
|
}
|
|
73664
73704
|
return undefined;
|
|
@@ -73699,6 +73739,7 @@ class Registry {
|
|
|
73699
73739
|
removeFile(file) {
|
|
73700
73740
|
const obj = this.find(file.getObjectName(), file.getObjectType());
|
|
73701
73741
|
obj.removeFile(file);
|
|
73742
|
+
this.unindexFile(file.getFilename(), obj);
|
|
73702
73743
|
if (obj.getFiles().length === 0) {
|
|
73703
73744
|
this.ddicReferences.clear(obj);
|
|
73704
73745
|
this.msagReferences.clear(obj);
|
|
@@ -73725,6 +73766,7 @@ class Registry {
|
|
|
73725
73766
|
found = this.findOrCreate(f.getObjectName(), f.getObjectType());
|
|
73726
73767
|
}
|
|
73727
73768
|
found.addFile(f);
|
|
73769
|
+
this.filenameIndex.set(filename.toUpperCase(), found);
|
|
73728
73770
|
}
|
|
73729
73771
|
return this;
|
|
73730
73772
|
}
|
|
@@ -73793,11 +73835,13 @@ class Registry {
|
|
|
73793
73835
|
// assumption: the file is already in the registry
|
|
73794
73836
|
findObjectForFile(file) {
|
|
73795
73837
|
const filename = file.getFilename();
|
|
73796
|
-
|
|
73797
|
-
|
|
73798
|
-
|
|
73799
|
-
|
|
73800
|
-
|
|
73838
|
+
const obj = this.filenameIndex.get(filename.toUpperCase());
|
|
73839
|
+
if (obj === undefined) {
|
|
73840
|
+
return undefined;
|
|
73841
|
+
}
|
|
73842
|
+
for (const ofile of obj.getFiles()) {
|
|
73843
|
+
if (ofile.getFilename() === filename) {
|
|
73844
|
+
return obj;
|
|
73801
73845
|
}
|
|
73802
73846
|
}
|
|
73803
73847
|
return undefined;
|
|
@@ -73889,6 +73933,9 @@ class Registry {
|
|
|
73889
73933
|
if (this.objects[remove.getName()][remove.getType()] === undefined) {
|
|
73890
73934
|
throw new Error("removeObject: object not found");
|
|
73891
73935
|
}
|
|
73936
|
+
for (const f of remove.getFiles()) {
|
|
73937
|
+
this.unindexFile(f.getFilename(), remove);
|
|
73938
|
+
}
|
|
73892
73939
|
if (Object.keys(this.objects[remove.getName()]).length === 1) {
|
|
73893
73940
|
delete this.objects[remove.getName()];
|
|
73894
73941
|
}
|
|
@@ -73902,6 +73949,12 @@ class Registry {
|
|
|
73902
73949
|
delete this.objectsByType[remove.getType()][remove.getName()];
|
|
73903
73950
|
}
|
|
73904
73951
|
}
|
|
73952
|
+
unindexFile(filename, obj) {
|
|
73953
|
+
const upper = filename.toUpperCase();
|
|
73954
|
+
if (this.filenameIndex.get(upper) === obj) {
|
|
73955
|
+
this.filenameIndex.delete(upper);
|
|
73956
|
+
}
|
|
73957
|
+
}
|
|
73905
73958
|
find(name, type) {
|
|
73906
73959
|
const searchType = type ? type : "UNKNOWN";
|
|
73907
73960
|
const searchName = name.toUpperCase();
|
|
@@ -74199,6 +74252,7 @@ const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_st
|
|
|
74199
74252
|
const tokens_1 = __webpack_require__(/*! ../abap/1_lexer/tokens */ "../core/build/src/abap/1_lexer/tokens/index.js");
|
|
74200
74253
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
|
|
74201
74254
|
const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/build/src/abap/5_syntax/syntax.js");
|
|
74255
|
+
const raw_rows_cache_1 = __webpack_require__(/*! ../files/raw_rows_cache */ "../core/build/src/files/raw_rows_cache.js");
|
|
74202
74256
|
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
|
|
74203
74257
|
const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
|
|
74204
74258
|
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
@@ -75505,16 +75559,6 @@ class Hierarchy {
|
|
|
75505
75559
|
exports.Hierarchy = Hierarchy;
|
|
75506
75560
|
////////////////////////////////////////
|
|
75507
75561
|
// edits
|
|
75508
|
-
const rowCache = new WeakMap();
|
|
75509
|
-
/** getRawRows() splits the source on every call; a file is never changed, edits create a new one */
|
|
75510
|
-
function rowsOf(file) {
|
|
75511
|
-
let rows = rowCache.get(file);
|
|
75512
|
-
if (rows === undefined) {
|
|
75513
|
-
rows = file.getRawRows();
|
|
75514
|
-
rowCache.set(file, rows);
|
|
75515
|
-
}
|
|
75516
|
-
return rows;
|
|
75517
|
-
}
|
|
75518
75562
|
/** edits of one fix, sorted so that applying them one after the other keeps the positions valid */
|
|
75519
75563
|
function mergeEdits(file, edits) {
|
|
75520
75564
|
const list = [];
|
|
@@ -75534,7 +75578,7 @@ function deleteRegion(file, first, last) {
|
|
|
75534
75578
|
if (first === last && first.getColon() !== undefined) {
|
|
75535
75579
|
return edit_helper_1.EditHelper.deleteStatement(file, first);
|
|
75536
75580
|
}
|
|
75537
|
-
const rows =
|
|
75581
|
+
const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
|
|
75538
75582
|
const start = first.getStart();
|
|
75539
75583
|
const end = last.getEnd();
|
|
75540
75584
|
const before = rows[start.getRow() - 1].substring(0, start.getCol() - 1);
|
|
@@ -75549,7 +75593,7 @@ function deleteStatement(file, statement) {
|
|
|
75549
75593
|
}
|
|
75550
75594
|
/** the source code between two positions, as written */
|
|
75551
75595
|
function rawText(file, start, end) {
|
|
75552
|
-
const rows =
|
|
75596
|
+
const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
|
|
75553
75597
|
if (start.getRow() === end.getRow()) {
|
|
75554
75598
|
return rows[start.getRow() - 1].substring(start.getCol() - 1, end.getCol() - 1);
|
|
75555
75599
|
}
|
|
@@ -85459,8 +85503,23 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
85459
85503
|
}
|
|
85460
85504
|
highSyntaxObj = this.highReg.findObjectForFile(f);
|
|
85461
85505
|
}
|
|
85506
|
+
// the syntax run is expensive and most statements need no downport, so run it on first use
|
|
85507
|
+
let computedSyntax = undefined;
|
|
85508
|
+
const runHighSyntax = () => {
|
|
85509
|
+
if (computedSyntax === undefined) {
|
|
85510
|
+
computedSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
|
|
85511
|
+
}
|
|
85512
|
+
return computedSyntax;
|
|
85513
|
+
};
|
|
85514
|
+
const highSyntax = {
|
|
85515
|
+
get issues() {
|
|
85516
|
+
return runHighSyntax().issues;
|
|
85517
|
+
},
|
|
85518
|
+
get spaghetti() {
|
|
85519
|
+
return runHighSyntax().spaghetti;
|
|
85520
|
+
},
|
|
85521
|
+
};
|
|
85462
85522
|
for (const lowFile of lowObj.getABAPFiles()) {
|
|
85463
|
-
let highSyntax = undefined;
|
|
85464
85523
|
const highFile = highObj.getABAPFileByName(lowFile.getFilename());
|
|
85465
85524
|
if (highFile === undefined) {
|
|
85466
85525
|
continue;
|
|
@@ -85479,9 +85538,6 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
85479
85538
|
// actively editing the files
|
|
85480
85539
|
continue;
|
|
85481
85540
|
}
|
|
85482
|
-
if (highSyntax === undefined) {
|
|
85483
|
-
highSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
|
|
85484
|
-
}
|
|
85485
85541
|
let containsUnknown = false;
|
|
85486
85542
|
const notDownported = [];
|
|
85487
85543
|
for (let i = 0; i < lowStatements.length; i++) {
|
|
@@ -108371,6 +108427,8 @@ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_i
|
|
|
108371
108427
|
const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/build/src/abap/5_syntax/syntax.js");
|
|
108372
108428
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
|
|
108373
108429
|
const types_1 = __webpack_require__(/*! ../abap/types */ "../core/build/src/abap/types/index.js");
|
|
108430
|
+
const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
|
|
108431
|
+
const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "../core/build/src/virtual_position.js");
|
|
108374
108432
|
class StaticCallViaInstanceConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
108375
108433
|
constructor() {
|
|
108376
108434
|
super(...arguments);
|
|
@@ -108410,24 +108468,36 @@ ENDMETHOD.`,
|
|
|
108410
108468
|
if (this.getConfig().allowInTestclassIncludes === true && file.getFilename().includes(".testclasses.")) {
|
|
108411
108469
|
return [];
|
|
108412
108470
|
}
|
|
108413
|
-
const staticMethodCalls =
|
|
108471
|
+
const staticMethodCalls = new Set();
|
|
108472
|
+
for (const s of this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop())) {
|
|
108473
|
+
staticMethodCalls.add(StaticCallViaInstance.positionKey(s));
|
|
108474
|
+
}
|
|
108475
|
+
if (staticMethodCalls.size === 0) {
|
|
108476
|
+
return [];
|
|
108477
|
+
}
|
|
108414
108478
|
const tokens = file.getTokens();
|
|
108415
108479
|
for (let i = 0; i < tokens.length - 1; i++) {
|
|
108416
108480
|
const token = tokens[i];
|
|
108417
108481
|
if (token.getStr() !== "->") {
|
|
108418
108482
|
continue;
|
|
108419
108483
|
}
|
|
108420
|
-
const next = tokens[i + 1];
|
|
108421
|
-
|
|
108422
|
-
|
|
108423
|
-
|
|
108424
|
-
|
|
108425
|
-
|
|
108426
|
-
|
|
108484
|
+
const next = tokens[i + 1].getStart();
|
|
108485
|
+
// a plain reference position also matches a token inside a macro call at the same row and column
|
|
108486
|
+
if (staticMethodCalls.has(StaticCallViaInstance.positionKey(next))
|
|
108487
|
+
|| (next instanceof virtual_position_1.VirtualPosition
|
|
108488
|
+
&& staticMethodCalls.has(StaticCallViaInstance.positionKey(new position_1.Position(next.getRow(), next.getCol()))))) {
|
|
108489
|
+
const message = "Avoid calling static method via instance";
|
|
108490
|
+
issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key));
|
|
108427
108491
|
}
|
|
108428
108492
|
}
|
|
108429
108493
|
return issues;
|
|
108430
108494
|
}
|
|
108495
|
+
static positionKey(p) {
|
|
108496
|
+
if (p instanceof virtual_position_1.VirtualPosition) {
|
|
108497
|
+
return p.getRow() + ":" + p.getCol() + ":" + p.vrow + ":" + p.vcol;
|
|
108498
|
+
}
|
|
108499
|
+
return p.getRow() + ":" + p.getCol();
|
|
108500
|
+
}
|
|
108431
108501
|
listMethodCalls(filename, node) {
|
|
108432
108502
|
const ret = [];
|
|
108433
108503
|
for (const r of node.getData().references) {
|
|
@@ -112018,31 +112088,40 @@ const _scope_type_1 = __webpack_require__(/*! ../abap/5_syntax/_scope_type */ ".
|
|
|
112018
112088
|
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
112019
112089
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
|
|
112020
112090
|
const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "../core/build/src/abap/2_statements/statements/_statement.js");
|
|
112091
|
+
const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "../core/build/src/virtual_position.js");
|
|
112021
112092
|
class WorkArea {
|
|
112022
112093
|
constructor() {
|
|
112023
|
-
|
|
112094
|
+
// keyed by identifier position, insertion order is kept
|
|
112095
|
+
this.workarea = new Map();
|
|
112024
112096
|
}
|
|
112025
112097
|
push(id) {
|
|
112026
|
-
|
|
112027
|
-
|
|
112028
|
-
|
|
112029
|
-
}
|
|
112098
|
+
const key = WorkArea.buildKey(id);
|
|
112099
|
+
if (this.workarea.has(key) === false) {
|
|
112100
|
+
this.workarea.set(key, id);
|
|
112030
112101
|
}
|
|
112031
|
-
this.workarea.push(id);
|
|
112032
112102
|
}
|
|
112033
112103
|
removeIfExists(id) {
|
|
112034
|
-
|
|
112035
|
-
|
|
112036
|
-
|
|
112037
|
-
|
|
112104
|
+
this.workarea.delete(WorkArea.buildKey(id));
|
|
112105
|
+
}
|
|
112106
|
+
/** removes the identifiers referenced somewhere */
|
|
112107
|
+
removeReferenced(referenced) {
|
|
112108
|
+
for (const key of [...this.workarea.keys()]) {
|
|
112109
|
+
if (referenced.has(key)) {
|
|
112110
|
+
this.workarea.delete(key);
|
|
112038
112111
|
}
|
|
112039
112112
|
}
|
|
112040
112113
|
}
|
|
112041
112114
|
get() {
|
|
112042
|
-
return this.workarea;
|
|
112115
|
+
return [...this.workarea.values()];
|
|
112043
112116
|
}
|
|
112044
112117
|
count() {
|
|
112045
|
-
return this.workarea.
|
|
112118
|
+
return this.workarea.size;
|
|
112119
|
+
}
|
|
112120
|
+
/** identifiers from one macro call share the row and column, the virtual position tells them apart */
|
|
112121
|
+
static buildKey(id) {
|
|
112122
|
+
const start = id.getStart();
|
|
112123
|
+
const key = id.getFilename() + "," + start.getRow() + "," + start.getCol();
|
|
112124
|
+
return start instanceof virtual_position_1.VirtualPosition ? key + "," + start.vrow + "," + start.vcol : key;
|
|
112046
112125
|
}
|
|
112047
112126
|
}
|
|
112048
112127
|
class UnusedTypesConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
@@ -112058,6 +112137,8 @@ exports.UnusedTypesConf = UnusedTypesConf;
|
|
|
112058
112137
|
class UnusedTypes {
|
|
112059
112138
|
constructor() {
|
|
112060
112139
|
this.conf = new UnusedTypesConf();
|
|
112140
|
+
/** keys of the identifiers with a type reference in any object, built once per run when needed */
|
|
112141
|
+
this.referenced = undefined;
|
|
112061
112142
|
}
|
|
112062
112143
|
getMetadata() {
|
|
112063
112144
|
return {
|
|
@@ -112081,6 +112162,7 @@ class UnusedTypes {
|
|
|
112081
112162
|
}
|
|
112082
112163
|
initialize(reg) {
|
|
112083
112164
|
this.reg = reg;
|
|
112165
|
+
this.referenced = undefined;
|
|
112084
112166
|
return this;
|
|
112085
112167
|
}
|
|
112086
112168
|
run(obj) {
|
|
@@ -112105,20 +112187,10 @@ class UnusedTypes {
|
|
|
112105
112187
|
if (this.workarea.count() === 0) {
|
|
112106
112188
|
return []; // exit early if all types are used in the current object
|
|
112107
112189
|
}
|
|
112108
|
-
|
|
112109
|
-
|
|
112110
|
-
|
|
112111
|
-
|
|
112112
|
-
else if (o instanceof _abap_object_1.ABAPObject) {
|
|
112113
|
-
if (this.reg.isDependency(o)) {
|
|
112114
|
-
continue; // do not search in dependencies
|
|
112115
|
-
}
|
|
112116
|
-
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
112117
|
-
this.traverse(syntax.spaghetti.getTop(), o, false);
|
|
112118
|
-
}
|
|
112119
|
-
if (this.workarea.count() === 0) {
|
|
112120
|
-
return []; // exit early if all types are used
|
|
112121
|
-
}
|
|
112190
|
+
// uses in other objects, collected once instead of searching all objects for each object
|
|
112191
|
+
this.workarea.removeReferenced(this.getReferenced());
|
|
112192
|
+
if (this.workarea.count() === 0) {
|
|
112193
|
+
return []; // exit early if all types are used
|
|
112122
112194
|
}
|
|
112123
112195
|
// what is left is unused
|
|
112124
112196
|
const ret = [];
|
|
@@ -112162,6 +112234,33 @@ class UnusedTypes {
|
|
|
112162
112234
|
return false;
|
|
112163
112235
|
}
|
|
112164
112236
|
////////////////////////////
|
|
112237
|
+
getReferenced() {
|
|
112238
|
+
if (this.referenced === undefined) {
|
|
112239
|
+
const referenced = new Set();
|
|
112240
|
+
for (const o of this.reg.getObjects()) {
|
|
112241
|
+
if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
|
|
112242
|
+
continue; // do not search in dependencies
|
|
112243
|
+
}
|
|
112244
|
+
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
112245
|
+
this.collectReferenced(syntax.spaghetti.getTop(), referenced);
|
|
112246
|
+
}
|
|
112247
|
+
this.referenced = referenced;
|
|
112248
|
+
}
|
|
112249
|
+
return this.referenced;
|
|
112250
|
+
}
|
|
112251
|
+
/** same nodes and references as checkNode() with add = false */
|
|
112252
|
+
collectReferenced(node, referenced) {
|
|
112253
|
+
if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
|
|
112254
|
+
for (const r of node.getData().references) {
|
|
112255
|
+
if (r.referenceType === _reference_1.ReferenceType.TypeReference && r.resolved) {
|
|
112256
|
+
referenced.add(WorkArea.buildKey(r.resolved));
|
|
112257
|
+
}
|
|
112258
|
+
}
|
|
112259
|
+
}
|
|
112260
|
+
for (const c of node.getChildren()) {
|
|
112261
|
+
this.collectReferenced(c, referenced);
|
|
112262
|
+
}
|
|
112263
|
+
}
|
|
112165
112264
|
traverse(node, obj, add) {
|
|
112166
112265
|
if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
|
|
112167
112266
|
this.checkNode(node, obj, add);
|
|
@@ -112281,17 +112380,17 @@ class WorkArea {
|
|
|
112281
112380
|
this.workarea = new Map();
|
|
112282
112381
|
}
|
|
112283
112382
|
push(id, count = 1) {
|
|
112284
|
-
const key =
|
|
112383
|
+
const key = WorkArea.buildKey(id);
|
|
112285
112384
|
if (this.workarea.has(key)) {
|
|
112286
112385
|
return;
|
|
112287
112386
|
}
|
|
112288
|
-
this.workarea.set(key, { id, count });
|
|
112387
|
+
this.workarea.set(key, { id, count, required: count });
|
|
112289
112388
|
}
|
|
112290
112389
|
removeIfExists(id) {
|
|
112291
112390
|
if (id === undefined) {
|
|
112292
112391
|
return;
|
|
112293
112392
|
}
|
|
112294
|
-
const key =
|
|
112393
|
+
const key = WorkArea.buildKey(id);
|
|
112295
112394
|
const found = this.workarea.get(key);
|
|
112296
112395
|
if (found !== undefined) {
|
|
112297
112396
|
found.count--;
|
|
@@ -112300,13 +112399,23 @@ class WorkArea {
|
|
|
112300
112399
|
}
|
|
112301
112400
|
}
|
|
112302
112401
|
}
|
|
112402
|
+
/** removes the identifiers with enough references, counts include all objects, also the one the
|
|
112403
|
+
* identifiers belong to, so it is compared to the required count and not the remaining count */
|
|
112404
|
+
removeReferenced(counts) {
|
|
112405
|
+
var _a;
|
|
112406
|
+
for (const [key, entry] of this.workarea) {
|
|
112407
|
+
if (((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) >= entry.required) {
|
|
112408
|
+
this.workarea.delete(key);
|
|
112409
|
+
}
|
|
112410
|
+
}
|
|
112411
|
+
}
|
|
112303
112412
|
get() {
|
|
112304
112413
|
return [...this.workarea.values()];
|
|
112305
112414
|
}
|
|
112306
112415
|
count() {
|
|
112307
112416
|
return this.workarea.size;
|
|
112308
112417
|
}
|
|
112309
|
-
buildKey(id) {
|
|
112418
|
+
static buildKey(id) {
|
|
112310
112419
|
const start = id.getStart();
|
|
112311
112420
|
return id.getFilename() + "," + start.getRow() + "," + start.getCol();
|
|
112312
112421
|
}
|
|
@@ -112314,6 +112423,8 @@ class WorkArea {
|
|
|
112314
112423
|
class UnusedVariables {
|
|
112315
112424
|
constructor() {
|
|
112316
112425
|
this.conf = new UnusedVariablesConf();
|
|
112426
|
+
/** read, write and type references per identifier key in all objects, built once per run when needed */
|
|
112427
|
+
this.referenceCounts = undefined;
|
|
112317
112428
|
}
|
|
112318
112429
|
getMetadata() {
|
|
112319
112430
|
return {
|
|
@@ -112351,6 +112462,7 @@ Errors found in INCLUDES are reported for the main program.`,
|
|
|
112351
112462
|
}
|
|
112352
112463
|
initialize(reg) {
|
|
112353
112464
|
this.reg = reg;
|
|
112465
|
+
this.referenceCounts = undefined;
|
|
112354
112466
|
return this;
|
|
112355
112467
|
}
|
|
112356
112468
|
run(obj) {
|
|
@@ -112378,34 +112490,53 @@ Errors found in INCLUDES are reported for the main program.`,
|
|
|
112378
112490
|
if (this.workarea.count() === 0) {
|
|
112379
112491
|
return this.buildIssues(obj); // exit early if all variables are used
|
|
112380
112492
|
}
|
|
112381
|
-
this.findUses(top
|
|
112382
|
-
|
|
112383
|
-
|
|
112384
|
-
|
|
112385
|
-
|
|
112386
|
-
|
|
112387
|
-
|
|
112493
|
+
this.findUses(top);
|
|
112494
|
+
if (this.workarea.count() === 0) {
|
|
112495
|
+
return this.buildIssues(obj); // exit early if all variables are used
|
|
112496
|
+
}
|
|
112497
|
+
// uses in other objects, the counts are built once instead of searching all objects for each object
|
|
112498
|
+
this.workarea.removeReferenced(this.getReferenceCounts());
|
|
112499
|
+
return this.buildIssues(obj);
|
|
112500
|
+
}
|
|
112501
|
+
getReferenceCounts() {
|
|
112502
|
+
if (this.referenceCounts === undefined) {
|
|
112503
|
+
const counts = new Map();
|
|
112504
|
+
for (const o of this.reg.getObjects()) {
|
|
112505
|
+
if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
|
|
112388
112506
|
continue; // do not search in dependencies
|
|
112389
112507
|
}
|
|
112390
112508
|
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
112391
|
-
this.
|
|
112392
|
-
if (this.workarea.count() === 0) {
|
|
112393
|
-
return this.buildIssues(obj); // exit early if all variables are used
|
|
112394
|
-
}
|
|
112509
|
+
this.countUses(syntax.spaghetti.getTop(), counts);
|
|
112395
112510
|
}
|
|
112511
|
+
this.referenceCounts = counts;
|
|
112396
112512
|
}
|
|
112397
|
-
return this.
|
|
112513
|
+
return this.referenceCounts;
|
|
112398
112514
|
}
|
|
112399
|
-
|
|
112515
|
+
static isUse(r) {
|
|
112516
|
+
return r.referenceType === _reference_1.ReferenceType.DataReadReference
|
|
112517
|
+
|| r.referenceType === _reference_1.ReferenceType.DataWriteReference
|
|
112518
|
+
|| r.referenceType === _reference_1.ReferenceType.TypeReference;
|
|
112519
|
+
}
|
|
112520
|
+
findUses(node) {
|
|
112400
112521
|
for (const r of node.getData().references) {
|
|
112401
|
-
if (r
|
|
112402
|
-
|| r.referenceType === _reference_1.ReferenceType.DataWriteReference
|
|
112403
|
-
|| r.referenceType === _reference_1.ReferenceType.TypeReference) {
|
|
112522
|
+
if (UnusedVariables.isUse(r)) {
|
|
112404
112523
|
this.workarea.removeIfExists(r.resolved);
|
|
112405
112524
|
}
|
|
112406
112525
|
}
|
|
112407
112526
|
for (const c of node.getChildren()) {
|
|
112408
|
-
this.findUses(c
|
|
112527
|
+
this.findUses(c);
|
|
112528
|
+
}
|
|
112529
|
+
}
|
|
112530
|
+
countUses(node, counts) {
|
|
112531
|
+
var _a;
|
|
112532
|
+
for (const r of node.getData().references) {
|
|
112533
|
+
if (r.resolved !== undefined && UnusedVariables.isUse(r)) {
|
|
112534
|
+
const key = WorkArea.buildKey(r.resolved);
|
|
112535
|
+
counts.set(key, ((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
112536
|
+
}
|
|
112537
|
+
}
|
|
112538
|
+
for (const c of node.getChildren()) {
|
|
112539
|
+
this.countUses(c, counts);
|
|
112409
112540
|
}
|
|
112410
112541
|
}
|
|
112411
112542
|
buildWorkarea(node, obj) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/cli",
|
|
3
|
-
"version": "2.120.
|
|
3
|
+
"version": "2.120.105",
|
|
4
4
|
"description": "abaplint - Command Line Interface",
|
|
5
5
|
"funding": "https://github.com/sponsors/larshp",
|
|
6
6
|
"bin": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://abaplint.org",
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@abaplint/core": "^2.120.
|
|
42
|
+
"@abaplint/core": "^2.120.105",
|
|
43
43
|
"@types/chai": "^4.3.20",
|
|
44
44
|
"@types/minimist": "^1.2.5",
|
|
45
45
|
"@types/mocha": "^10.0.10",
|