@abaplint/cli 2.120.103 → 2.120.104
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 +208 -85
- package/package.json +2 -2
package/build/cli.js
CHANGED
|
@@ -51069,7 +51069,8 @@ class SyntaxLogic {
|
|
|
51069
51069
|
}
|
|
51070
51070
|
}
|
|
51071
51071
|
}
|
|
51072
|
-
|
|
51072
|
+
// statements only have expressions and tokens as children, nothing to traverse
|
|
51073
|
+
if (isStructure) {
|
|
51073
51074
|
this.traverse(child);
|
|
51074
51075
|
}
|
|
51075
51076
|
}
|
|
@@ -61179,6 +61180,31 @@ exports.MemoryFile = MemoryFile;
|
|
|
61179
61180
|
|
|
61180
61181
|
/***/ },
|
|
61181
61182
|
|
|
61183
|
+
/***/ "../core/build/src/files/raw_rows_cache.js"
|
|
61184
|
+
/*!*************************************************!*\
|
|
61185
|
+
!*** ../core/build/src/files/raw_rows_cache.js ***!
|
|
61186
|
+
\*************************************************/
|
|
61187
|
+
(__unused_webpack_module, exports) {
|
|
61188
|
+
|
|
61189
|
+
"use strict";
|
|
61190
|
+
|
|
61191
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
61192
|
+
exports.getCachedRawRows = getCachedRawRows;
|
|
61193
|
+
const rowCache = new WeakMap();
|
|
61194
|
+
/** getRawRows() splits the source on every call; a file is never changed, edits create a new one,
|
|
61195
|
+
* so the rows can be cached per file object. The result must not be modified */
|
|
61196
|
+
function getCachedRawRows(file) {
|
|
61197
|
+
let rows = rowCache.get(file);
|
|
61198
|
+
if (rows === undefined) {
|
|
61199
|
+
rows = file.getRawRows();
|
|
61200
|
+
rowCache.set(file, rows);
|
|
61201
|
+
}
|
|
61202
|
+
return rows;
|
|
61203
|
+
}
|
|
61204
|
+
//# sourceMappingURL=raw_rows_cache.js.map
|
|
61205
|
+
|
|
61206
|
+
/***/ },
|
|
61207
|
+
|
|
61182
61208
|
/***/ "../core/build/src/index.js"
|
|
61183
61209
|
/*!**********************************!*\
|
|
61184
61210
|
!*** ../core/build/src/index.js ***!
|
|
@@ -61363,11 +61389,12 @@ exports.Issue = void 0;
|
|
|
61363
61389
|
const position_1 = __webpack_require__(/*! ./position */ "../core/build/src/position.js");
|
|
61364
61390
|
const virtual_position_1 = __webpack_require__(/*! ./virtual_position */ "../core/build/src/virtual_position.js");
|
|
61365
61391
|
const severity_1 = __webpack_require__(/*! ./severity */ "../core/build/src/severity.js");
|
|
61392
|
+
const raw_rows_cache_1 = __webpack_require__(/*! ./files/raw_rows_cache */ "../core/build/src/files/raw_rows_cache.js");
|
|
61366
61393
|
class Issue {
|
|
61367
61394
|
//////////////////////////
|
|
61368
61395
|
static atRow(file, row, message, key, severity) {
|
|
61369
61396
|
const start = new position_1.Position(row, 1);
|
|
61370
|
-
const end = new position_1.Position(row,
|
|
61397
|
+
const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
|
|
61371
61398
|
severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
|
|
61372
61399
|
return new Issue({
|
|
61373
61400
|
filename: file.getFilename(),
|
|
@@ -61383,7 +61410,7 @@ class Issue {
|
|
|
61383
61410
|
}
|
|
61384
61411
|
static atPosition(file, start, message, key, severity, fix) {
|
|
61385
61412
|
const row = start.getRow();
|
|
61386
|
-
const end = new position_1.Position(row,
|
|
61413
|
+
const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
|
|
61387
61414
|
severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
|
|
61388
61415
|
return new Issue({
|
|
61389
61416
|
filename: file.getFilename(),
|
|
@@ -73587,6 +73614,8 @@ class Registry {
|
|
|
73587
73614
|
this.objects = {};
|
|
73588
73615
|
this.objectsByType = {};
|
|
73589
73616
|
this.dependencies = {};
|
|
73617
|
+
/** upper case filename to object containing the file, kept in sync by add/remove methods */
|
|
73618
|
+
this.filenameIndex = new Map();
|
|
73590
73619
|
this.setConfig(conf ? conf : config_1.Config.getDefault());
|
|
73591
73620
|
this.clear();
|
|
73592
73621
|
}
|
|
@@ -73595,13 +73624,14 @@ class Registry {
|
|
|
73595
73624
|
this.objects = {};
|
|
73596
73625
|
this.objectsByType = {};
|
|
73597
73626
|
this.dependencies = {};
|
|
73627
|
+
this.filenameIndex = new Map();
|
|
73598
73628
|
this.ddicReferences = new ddic_references_1.DDICReferences();
|
|
73599
73629
|
this.msagReferences = new msag_references_1.MSAGReferences();
|
|
73600
73630
|
this.macroReferences = new macro_references_1.MacroReferences();
|
|
73601
73631
|
}
|
|
73602
73632
|
static abaplintVersion() {
|
|
73603
73633
|
// magic, see build script "version.js"
|
|
73604
|
-
return "2.120.
|
|
73634
|
+
return "2.120.104";
|
|
73605
73635
|
}
|
|
73606
73636
|
getDDICReferences() {
|
|
73607
73637
|
return this.ddicReferences;
|
|
@@ -73654,11 +73684,13 @@ class Registry {
|
|
|
73654
73684
|
}
|
|
73655
73685
|
getFileByName(filename) {
|
|
73656
73686
|
const upper = filename.toUpperCase();
|
|
73657
|
-
|
|
73658
|
-
|
|
73659
|
-
|
|
73660
|
-
|
|
73661
|
-
|
|
73687
|
+
const obj = this.filenameIndex.get(upper);
|
|
73688
|
+
if (obj === undefined) {
|
|
73689
|
+
return undefined;
|
|
73690
|
+
}
|
|
73691
|
+
for (const f of obj.getFiles()) {
|
|
73692
|
+
if (f.getFilename().toUpperCase() === upper) {
|
|
73693
|
+
return f;
|
|
73662
73694
|
}
|
|
73663
73695
|
}
|
|
73664
73696
|
return undefined;
|
|
@@ -73699,6 +73731,7 @@ class Registry {
|
|
|
73699
73731
|
removeFile(file) {
|
|
73700
73732
|
const obj = this.find(file.getObjectName(), file.getObjectType());
|
|
73701
73733
|
obj.removeFile(file);
|
|
73734
|
+
this.unindexFile(file.getFilename(), obj);
|
|
73702
73735
|
if (obj.getFiles().length === 0) {
|
|
73703
73736
|
this.ddicReferences.clear(obj);
|
|
73704
73737
|
this.msagReferences.clear(obj);
|
|
@@ -73725,6 +73758,7 @@ class Registry {
|
|
|
73725
73758
|
found = this.findOrCreate(f.getObjectName(), f.getObjectType());
|
|
73726
73759
|
}
|
|
73727
73760
|
found.addFile(f);
|
|
73761
|
+
this.filenameIndex.set(filename.toUpperCase(), found);
|
|
73728
73762
|
}
|
|
73729
73763
|
return this;
|
|
73730
73764
|
}
|
|
@@ -73793,11 +73827,13 @@ class Registry {
|
|
|
73793
73827
|
// assumption: the file is already in the registry
|
|
73794
73828
|
findObjectForFile(file) {
|
|
73795
73829
|
const filename = file.getFilename();
|
|
73796
|
-
|
|
73797
|
-
|
|
73798
|
-
|
|
73799
|
-
|
|
73800
|
-
|
|
73830
|
+
const obj = this.filenameIndex.get(filename.toUpperCase());
|
|
73831
|
+
if (obj === undefined) {
|
|
73832
|
+
return undefined;
|
|
73833
|
+
}
|
|
73834
|
+
for (const ofile of obj.getFiles()) {
|
|
73835
|
+
if (ofile.getFilename() === filename) {
|
|
73836
|
+
return obj;
|
|
73801
73837
|
}
|
|
73802
73838
|
}
|
|
73803
73839
|
return undefined;
|
|
@@ -73889,6 +73925,9 @@ class Registry {
|
|
|
73889
73925
|
if (this.objects[remove.getName()][remove.getType()] === undefined) {
|
|
73890
73926
|
throw new Error("removeObject: object not found");
|
|
73891
73927
|
}
|
|
73928
|
+
for (const f of remove.getFiles()) {
|
|
73929
|
+
this.unindexFile(f.getFilename(), remove);
|
|
73930
|
+
}
|
|
73892
73931
|
if (Object.keys(this.objects[remove.getName()]).length === 1) {
|
|
73893
73932
|
delete this.objects[remove.getName()];
|
|
73894
73933
|
}
|
|
@@ -73902,6 +73941,12 @@ class Registry {
|
|
|
73902
73941
|
delete this.objectsByType[remove.getType()][remove.getName()];
|
|
73903
73942
|
}
|
|
73904
73943
|
}
|
|
73944
|
+
unindexFile(filename, obj) {
|
|
73945
|
+
const upper = filename.toUpperCase();
|
|
73946
|
+
if (this.filenameIndex.get(upper) === obj) {
|
|
73947
|
+
this.filenameIndex.delete(upper);
|
|
73948
|
+
}
|
|
73949
|
+
}
|
|
73905
73950
|
find(name, type) {
|
|
73906
73951
|
const searchType = type ? type : "UNKNOWN";
|
|
73907
73952
|
const searchName = name.toUpperCase();
|
|
@@ -74199,6 +74244,7 @@ const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_st
|
|
|
74199
74244
|
const tokens_1 = __webpack_require__(/*! ../abap/1_lexer/tokens */ "../core/build/src/abap/1_lexer/tokens/index.js");
|
|
74200
74245
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
|
|
74201
74246
|
const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/build/src/abap/5_syntax/syntax.js");
|
|
74247
|
+
const raw_rows_cache_1 = __webpack_require__(/*! ../files/raw_rows_cache */ "../core/build/src/files/raw_rows_cache.js");
|
|
74202
74248
|
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
|
|
74203
74249
|
const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
|
|
74204
74250
|
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
@@ -75505,16 +75551,6 @@ class Hierarchy {
|
|
|
75505
75551
|
exports.Hierarchy = Hierarchy;
|
|
75506
75552
|
////////////////////////////////////////
|
|
75507
75553
|
// 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
75554
|
/** edits of one fix, sorted so that applying them one after the other keeps the positions valid */
|
|
75519
75555
|
function mergeEdits(file, edits) {
|
|
75520
75556
|
const list = [];
|
|
@@ -75534,7 +75570,7 @@ function deleteRegion(file, first, last) {
|
|
|
75534
75570
|
if (first === last && first.getColon() !== undefined) {
|
|
75535
75571
|
return edit_helper_1.EditHelper.deleteStatement(file, first);
|
|
75536
75572
|
}
|
|
75537
|
-
const rows =
|
|
75573
|
+
const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
|
|
75538
75574
|
const start = first.getStart();
|
|
75539
75575
|
const end = last.getEnd();
|
|
75540
75576
|
const before = rows[start.getRow() - 1].substring(0, start.getCol() - 1);
|
|
@@ -75549,7 +75585,7 @@ function deleteStatement(file, statement) {
|
|
|
75549
75585
|
}
|
|
75550
75586
|
/** the source code between two positions, as written */
|
|
75551
75587
|
function rawText(file, start, end) {
|
|
75552
|
-
const rows =
|
|
75588
|
+
const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
|
|
75553
75589
|
if (start.getRow() === end.getRow()) {
|
|
75554
75590
|
return rows[start.getRow() - 1].substring(start.getCol() - 1, end.getCol() - 1);
|
|
75555
75591
|
}
|
|
@@ -85459,8 +85495,23 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
85459
85495
|
}
|
|
85460
85496
|
highSyntaxObj = this.highReg.findObjectForFile(f);
|
|
85461
85497
|
}
|
|
85498
|
+
// the syntax run is expensive and most statements need no downport, so run it on first use
|
|
85499
|
+
let computedSyntax = undefined;
|
|
85500
|
+
const runHighSyntax = () => {
|
|
85501
|
+
if (computedSyntax === undefined) {
|
|
85502
|
+
computedSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
|
|
85503
|
+
}
|
|
85504
|
+
return computedSyntax;
|
|
85505
|
+
};
|
|
85506
|
+
const highSyntax = {
|
|
85507
|
+
get issues() {
|
|
85508
|
+
return runHighSyntax().issues;
|
|
85509
|
+
},
|
|
85510
|
+
get spaghetti() {
|
|
85511
|
+
return runHighSyntax().spaghetti;
|
|
85512
|
+
},
|
|
85513
|
+
};
|
|
85462
85514
|
for (const lowFile of lowObj.getABAPFiles()) {
|
|
85463
|
-
let highSyntax = undefined;
|
|
85464
85515
|
const highFile = highObj.getABAPFileByName(lowFile.getFilename());
|
|
85465
85516
|
if (highFile === undefined) {
|
|
85466
85517
|
continue;
|
|
@@ -85479,9 +85530,6 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
85479
85530
|
// actively editing the files
|
|
85480
85531
|
continue;
|
|
85481
85532
|
}
|
|
85482
|
-
if (highSyntax === undefined) {
|
|
85483
|
-
highSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
|
|
85484
|
-
}
|
|
85485
85533
|
let containsUnknown = false;
|
|
85486
85534
|
const notDownported = [];
|
|
85487
85535
|
for (let i = 0; i < lowStatements.length; i++) {
|
|
@@ -108371,6 +108419,8 @@ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_i
|
|
|
108371
108419
|
const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/build/src/abap/5_syntax/syntax.js");
|
|
108372
108420
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
|
|
108373
108421
|
const types_1 = __webpack_require__(/*! ../abap/types */ "../core/build/src/abap/types/index.js");
|
|
108422
|
+
const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
|
|
108423
|
+
const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "../core/build/src/virtual_position.js");
|
|
108374
108424
|
class StaticCallViaInstanceConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
108375
108425
|
constructor() {
|
|
108376
108426
|
super(...arguments);
|
|
@@ -108410,24 +108460,36 @@ ENDMETHOD.`,
|
|
|
108410
108460
|
if (this.getConfig().allowInTestclassIncludes === true && file.getFilename().includes(".testclasses.")) {
|
|
108411
108461
|
return [];
|
|
108412
108462
|
}
|
|
108413
|
-
const staticMethodCalls =
|
|
108463
|
+
const staticMethodCalls = new Set();
|
|
108464
|
+
for (const s of this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop())) {
|
|
108465
|
+
staticMethodCalls.add(StaticCallViaInstance.positionKey(s));
|
|
108466
|
+
}
|
|
108467
|
+
if (staticMethodCalls.size === 0) {
|
|
108468
|
+
return [];
|
|
108469
|
+
}
|
|
108414
108470
|
const tokens = file.getTokens();
|
|
108415
108471
|
for (let i = 0; i < tokens.length - 1; i++) {
|
|
108416
108472
|
const token = tokens[i];
|
|
108417
108473
|
if (token.getStr() !== "->") {
|
|
108418
108474
|
continue;
|
|
108419
108475
|
}
|
|
108420
|
-
const next = tokens[i + 1];
|
|
108421
|
-
|
|
108422
|
-
|
|
108423
|
-
|
|
108424
|
-
|
|
108425
|
-
|
|
108426
|
-
|
|
108476
|
+
const next = tokens[i + 1].getStart();
|
|
108477
|
+
// a plain reference position also matches a token inside a macro call at the same row and column
|
|
108478
|
+
if (staticMethodCalls.has(StaticCallViaInstance.positionKey(next))
|
|
108479
|
+
|| (next instanceof virtual_position_1.VirtualPosition
|
|
108480
|
+
&& staticMethodCalls.has(StaticCallViaInstance.positionKey(new position_1.Position(next.getRow(), next.getCol()))))) {
|
|
108481
|
+
const message = "Avoid calling static method via instance";
|
|
108482
|
+
issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key));
|
|
108427
108483
|
}
|
|
108428
108484
|
}
|
|
108429
108485
|
return issues;
|
|
108430
108486
|
}
|
|
108487
|
+
static positionKey(p) {
|
|
108488
|
+
if (p instanceof virtual_position_1.VirtualPosition) {
|
|
108489
|
+
return p.getRow() + ":" + p.getCol() + ":" + p.vrow + ":" + p.vcol;
|
|
108490
|
+
}
|
|
108491
|
+
return p.getRow() + ":" + p.getCol();
|
|
108492
|
+
}
|
|
108431
108493
|
listMethodCalls(filename, node) {
|
|
108432
108494
|
const ret = [];
|
|
108433
108495
|
for (const r of node.getData().references) {
|
|
@@ -112018,31 +112080,40 @@ const _scope_type_1 = __webpack_require__(/*! ../abap/5_syntax/_scope_type */ ".
|
|
|
112018
112080
|
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
112019
112081
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
|
|
112020
112082
|
const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "../core/build/src/abap/2_statements/statements/_statement.js");
|
|
112083
|
+
const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "../core/build/src/virtual_position.js");
|
|
112021
112084
|
class WorkArea {
|
|
112022
112085
|
constructor() {
|
|
112023
|
-
|
|
112086
|
+
// keyed by identifier position, insertion order is kept
|
|
112087
|
+
this.workarea = new Map();
|
|
112024
112088
|
}
|
|
112025
112089
|
push(id) {
|
|
112026
|
-
|
|
112027
|
-
|
|
112028
|
-
|
|
112029
|
-
}
|
|
112090
|
+
const key = WorkArea.buildKey(id);
|
|
112091
|
+
if (this.workarea.has(key) === false) {
|
|
112092
|
+
this.workarea.set(key, id);
|
|
112030
112093
|
}
|
|
112031
|
-
this.workarea.push(id);
|
|
112032
112094
|
}
|
|
112033
112095
|
removeIfExists(id) {
|
|
112034
|
-
|
|
112035
|
-
|
|
112036
|
-
|
|
112037
|
-
|
|
112096
|
+
this.workarea.delete(WorkArea.buildKey(id));
|
|
112097
|
+
}
|
|
112098
|
+
/** removes the identifiers referenced somewhere */
|
|
112099
|
+
removeReferenced(referenced) {
|
|
112100
|
+
for (const key of [...this.workarea.keys()]) {
|
|
112101
|
+
if (referenced.has(key)) {
|
|
112102
|
+
this.workarea.delete(key);
|
|
112038
112103
|
}
|
|
112039
112104
|
}
|
|
112040
112105
|
}
|
|
112041
112106
|
get() {
|
|
112042
|
-
return this.workarea;
|
|
112107
|
+
return [...this.workarea.values()];
|
|
112043
112108
|
}
|
|
112044
112109
|
count() {
|
|
112045
|
-
return this.workarea.
|
|
112110
|
+
return this.workarea.size;
|
|
112111
|
+
}
|
|
112112
|
+
/** identifiers from one macro call share the row and column, the virtual position tells them apart */
|
|
112113
|
+
static buildKey(id) {
|
|
112114
|
+
const start = id.getStart();
|
|
112115
|
+
const key = id.getFilename() + "," + start.getRow() + "," + start.getCol();
|
|
112116
|
+
return start instanceof virtual_position_1.VirtualPosition ? key + "," + start.vrow + "," + start.vcol : key;
|
|
112046
112117
|
}
|
|
112047
112118
|
}
|
|
112048
112119
|
class UnusedTypesConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
@@ -112058,6 +112129,8 @@ exports.UnusedTypesConf = UnusedTypesConf;
|
|
|
112058
112129
|
class UnusedTypes {
|
|
112059
112130
|
constructor() {
|
|
112060
112131
|
this.conf = new UnusedTypesConf();
|
|
112132
|
+
/** keys of the identifiers with a type reference in any object, built once per run when needed */
|
|
112133
|
+
this.referenced = undefined;
|
|
112061
112134
|
}
|
|
112062
112135
|
getMetadata() {
|
|
112063
112136
|
return {
|
|
@@ -112081,6 +112154,7 @@ class UnusedTypes {
|
|
|
112081
112154
|
}
|
|
112082
112155
|
initialize(reg) {
|
|
112083
112156
|
this.reg = reg;
|
|
112157
|
+
this.referenced = undefined;
|
|
112084
112158
|
return this;
|
|
112085
112159
|
}
|
|
112086
112160
|
run(obj) {
|
|
@@ -112105,20 +112179,10 @@ class UnusedTypes {
|
|
|
112105
112179
|
if (this.workarea.count() === 0) {
|
|
112106
112180
|
return []; // exit early if all types are used in the current object
|
|
112107
112181
|
}
|
|
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
|
-
}
|
|
112182
|
+
// uses in other objects, collected once instead of searching all objects for each object
|
|
112183
|
+
this.workarea.removeReferenced(this.getReferenced());
|
|
112184
|
+
if (this.workarea.count() === 0) {
|
|
112185
|
+
return []; // exit early if all types are used
|
|
112122
112186
|
}
|
|
112123
112187
|
// what is left is unused
|
|
112124
112188
|
const ret = [];
|
|
@@ -112162,6 +112226,33 @@ class UnusedTypes {
|
|
|
112162
112226
|
return false;
|
|
112163
112227
|
}
|
|
112164
112228
|
////////////////////////////
|
|
112229
|
+
getReferenced() {
|
|
112230
|
+
if (this.referenced === undefined) {
|
|
112231
|
+
const referenced = new Set();
|
|
112232
|
+
for (const o of this.reg.getObjects()) {
|
|
112233
|
+
if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
|
|
112234
|
+
continue; // do not search in dependencies
|
|
112235
|
+
}
|
|
112236
|
+
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
112237
|
+
this.collectReferenced(syntax.spaghetti.getTop(), referenced);
|
|
112238
|
+
}
|
|
112239
|
+
this.referenced = referenced;
|
|
112240
|
+
}
|
|
112241
|
+
return this.referenced;
|
|
112242
|
+
}
|
|
112243
|
+
/** same nodes and references as checkNode() with add = false */
|
|
112244
|
+
collectReferenced(node, referenced) {
|
|
112245
|
+
if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
|
|
112246
|
+
for (const r of node.getData().references) {
|
|
112247
|
+
if (r.referenceType === _reference_1.ReferenceType.TypeReference && r.resolved) {
|
|
112248
|
+
referenced.add(WorkArea.buildKey(r.resolved));
|
|
112249
|
+
}
|
|
112250
|
+
}
|
|
112251
|
+
}
|
|
112252
|
+
for (const c of node.getChildren()) {
|
|
112253
|
+
this.collectReferenced(c, referenced);
|
|
112254
|
+
}
|
|
112255
|
+
}
|
|
112165
112256
|
traverse(node, obj, add) {
|
|
112166
112257
|
if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
|
|
112167
112258
|
this.checkNode(node, obj, add);
|
|
@@ -112281,17 +112372,17 @@ class WorkArea {
|
|
|
112281
112372
|
this.workarea = new Map();
|
|
112282
112373
|
}
|
|
112283
112374
|
push(id, count = 1) {
|
|
112284
|
-
const key =
|
|
112375
|
+
const key = WorkArea.buildKey(id);
|
|
112285
112376
|
if (this.workarea.has(key)) {
|
|
112286
112377
|
return;
|
|
112287
112378
|
}
|
|
112288
|
-
this.workarea.set(key, { id, count });
|
|
112379
|
+
this.workarea.set(key, { id, count, required: count });
|
|
112289
112380
|
}
|
|
112290
112381
|
removeIfExists(id) {
|
|
112291
112382
|
if (id === undefined) {
|
|
112292
112383
|
return;
|
|
112293
112384
|
}
|
|
112294
|
-
const key =
|
|
112385
|
+
const key = WorkArea.buildKey(id);
|
|
112295
112386
|
const found = this.workarea.get(key);
|
|
112296
112387
|
if (found !== undefined) {
|
|
112297
112388
|
found.count--;
|
|
@@ -112300,13 +112391,23 @@ class WorkArea {
|
|
|
112300
112391
|
}
|
|
112301
112392
|
}
|
|
112302
112393
|
}
|
|
112394
|
+
/** removes the identifiers with enough references, counts include all objects, also the one the
|
|
112395
|
+
* identifiers belong to, so it is compared to the required count and not the remaining count */
|
|
112396
|
+
removeReferenced(counts) {
|
|
112397
|
+
var _a;
|
|
112398
|
+
for (const [key, entry] of this.workarea) {
|
|
112399
|
+
if (((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) >= entry.required) {
|
|
112400
|
+
this.workarea.delete(key);
|
|
112401
|
+
}
|
|
112402
|
+
}
|
|
112403
|
+
}
|
|
112303
112404
|
get() {
|
|
112304
112405
|
return [...this.workarea.values()];
|
|
112305
112406
|
}
|
|
112306
112407
|
count() {
|
|
112307
112408
|
return this.workarea.size;
|
|
112308
112409
|
}
|
|
112309
|
-
buildKey(id) {
|
|
112410
|
+
static buildKey(id) {
|
|
112310
112411
|
const start = id.getStart();
|
|
112311
112412
|
return id.getFilename() + "," + start.getRow() + "," + start.getCol();
|
|
112312
112413
|
}
|
|
@@ -112314,6 +112415,8 @@ class WorkArea {
|
|
|
112314
112415
|
class UnusedVariables {
|
|
112315
112416
|
constructor() {
|
|
112316
112417
|
this.conf = new UnusedVariablesConf();
|
|
112418
|
+
/** read, write and type references per identifier key in all objects, built once per run when needed */
|
|
112419
|
+
this.referenceCounts = undefined;
|
|
112317
112420
|
}
|
|
112318
112421
|
getMetadata() {
|
|
112319
112422
|
return {
|
|
@@ -112351,6 +112454,7 @@ Errors found in INCLUDES are reported for the main program.`,
|
|
|
112351
112454
|
}
|
|
112352
112455
|
initialize(reg) {
|
|
112353
112456
|
this.reg = reg;
|
|
112457
|
+
this.referenceCounts = undefined;
|
|
112354
112458
|
return this;
|
|
112355
112459
|
}
|
|
112356
112460
|
run(obj) {
|
|
@@ -112378,34 +112482,53 @@ Errors found in INCLUDES are reported for the main program.`,
|
|
|
112378
112482
|
if (this.workarea.count() === 0) {
|
|
112379
112483
|
return this.buildIssues(obj); // exit early if all variables are used
|
|
112380
112484
|
}
|
|
112381
|
-
this.findUses(top
|
|
112382
|
-
|
|
112383
|
-
|
|
112384
|
-
|
|
112385
|
-
|
|
112386
|
-
|
|
112387
|
-
|
|
112485
|
+
this.findUses(top);
|
|
112486
|
+
if (this.workarea.count() === 0) {
|
|
112487
|
+
return this.buildIssues(obj); // exit early if all variables are used
|
|
112488
|
+
}
|
|
112489
|
+
// uses in other objects, the counts are built once instead of searching all objects for each object
|
|
112490
|
+
this.workarea.removeReferenced(this.getReferenceCounts());
|
|
112491
|
+
return this.buildIssues(obj);
|
|
112492
|
+
}
|
|
112493
|
+
getReferenceCounts() {
|
|
112494
|
+
if (this.referenceCounts === undefined) {
|
|
112495
|
+
const counts = new Map();
|
|
112496
|
+
for (const o of this.reg.getObjects()) {
|
|
112497
|
+
if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
|
|
112388
112498
|
continue; // do not search in dependencies
|
|
112389
112499
|
}
|
|
112390
112500
|
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
|
-
}
|
|
112501
|
+
this.countUses(syntax.spaghetti.getTop(), counts);
|
|
112395
112502
|
}
|
|
112503
|
+
this.referenceCounts = counts;
|
|
112396
112504
|
}
|
|
112397
|
-
return this.
|
|
112505
|
+
return this.referenceCounts;
|
|
112506
|
+
}
|
|
112507
|
+
static isUse(r) {
|
|
112508
|
+
return r.referenceType === _reference_1.ReferenceType.DataReadReference
|
|
112509
|
+
|| r.referenceType === _reference_1.ReferenceType.DataWriteReference
|
|
112510
|
+
|| r.referenceType === _reference_1.ReferenceType.TypeReference;
|
|
112398
112511
|
}
|
|
112399
|
-
findUses(node
|
|
112512
|
+
findUses(node) {
|
|
112400
112513
|
for (const r of node.getData().references) {
|
|
112401
|
-
if (r
|
|
112402
|
-
|| r.referenceType === _reference_1.ReferenceType.DataWriteReference
|
|
112403
|
-
|| r.referenceType === _reference_1.ReferenceType.TypeReference) {
|
|
112514
|
+
if (UnusedVariables.isUse(r)) {
|
|
112404
112515
|
this.workarea.removeIfExists(r.resolved);
|
|
112405
112516
|
}
|
|
112406
112517
|
}
|
|
112407
112518
|
for (const c of node.getChildren()) {
|
|
112408
|
-
this.findUses(c
|
|
112519
|
+
this.findUses(c);
|
|
112520
|
+
}
|
|
112521
|
+
}
|
|
112522
|
+
countUses(node, counts) {
|
|
112523
|
+
var _a;
|
|
112524
|
+
for (const r of node.getData().references) {
|
|
112525
|
+
if (r.resolved !== undefined && UnusedVariables.isUse(r)) {
|
|
112526
|
+
const key = WorkArea.buildKey(r.resolved);
|
|
112527
|
+
counts.set(key, ((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
112528
|
+
}
|
|
112529
|
+
}
|
|
112530
|
+
for (const c of node.getChildren()) {
|
|
112531
|
+
this.countUses(c, counts);
|
|
112409
112532
|
}
|
|
112410
112533
|
}
|
|
112411
112534
|
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.104",
|
|
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.104",
|
|
43
43
|
"@types/chai": "^4.3.20",
|
|
44
44
|
"@types/minimist": "^1.2.5",
|
|
45
45
|
"@types/mocha": "^10.0.10",
|