@abaplint/core 2.93.80 → 2.93.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.
|
@@ -8,11 +8,23 @@ const component_compare_1 = require("../expressions/component_compare");
|
|
|
8
8
|
const component_cond_1 = require("../expressions/component_cond");
|
|
9
9
|
class DeleteInternal {
|
|
10
10
|
runSyntax(node, scope, filename) {
|
|
11
|
+
var _a;
|
|
11
12
|
for (const s of node.findDirectExpressions(Expressions.Source)) {
|
|
12
13
|
new source_1.Source().runSyntax(s, scope, filename);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const target = node.findDirectExpression(Expressions.Target);
|
|
16
|
+
if (target) {
|
|
17
|
+
let tabl = undefined;
|
|
18
|
+
if (node.getChildren().length === 5 && node.getChildren()[2].concatTokens().toUpperCase() === "FROM") {
|
|
19
|
+
// it might be a database table
|
|
20
|
+
tabl = (_a = scope.getDDIC()) === null || _a === void 0 ? void 0 : _a.lookupTableOrView(target.concatTokens());
|
|
21
|
+
if (tabl) {
|
|
22
|
+
scope.getDDICReferences().addUsing(scope.getParentObj(), { object: tabl.object });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (tabl === undefined) {
|
|
26
|
+
new target_1.Target().runSyntax(target, scope, filename);
|
|
27
|
+
}
|
|
16
28
|
}
|
|
17
29
|
for (const t of node.findDirectExpressions(Expressions.ComponentCompare)) {
|
|
18
30
|
new component_compare_1.ComponentCompare().runSyntax(t, scope, filename);
|
package/build/src/registry.js
CHANGED
|
@@ -24,6 +24,7 @@ const tokens_1 = require("../abap/1_lexer/tokens");
|
|
|
24
24
|
const include_graph_1 = require("../utils/include_graph");
|
|
25
25
|
const objects_1 = require("../objects");
|
|
26
26
|
const _builtin_1 = require("../abap/5_syntax/_builtin");
|
|
27
|
+
const _scope_type_1 = require("../abap/5_syntax/_scope_type");
|
|
27
28
|
// todo: refactor each sub-rule to new classes?
|
|
28
29
|
// todo: add configuration
|
|
29
30
|
class DownportConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
@@ -35,6 +36,83 @@ class SkipToNextFile extends Error {
|
|
|
35
36
|
this.issue = issue;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
39
|
+
class SpagHelper {
|
|
40
|
+
constructor(spag) {
|
|
41
|
+
this.spag = spag;
|
|
42
|
+
}
|
|
43
|
+
renameVariable(oldName, pos, lowFile, newName) {
|
|
44
|
+
let fix = undefined;
|
|
45
|
+
const references = this.findReferences(oldName, pos);
|
|
46
|
+
references.sort((a, b) => {
|
|
47
|
+
if (a.start.equals(b.start)) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
return a.start.isAfter(b.start) ? 1 : -1;
|
|
51
|
+
});
|
|
52
|
+
for (const r of references) {
|
|
53
|
+
const replace = edit_helper_1.EditHelper.replaceRange(lowFile, r.start, r.end, newName);
|
|
54
|
+
if (fix === undefined) {
|
|
55
|
+
fix = replace;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
fix = edit_helper_1.EditHelper.merge(replace, fix);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return fix;
|
|
62
|
+
}
|
|
63
|
+
findReferences(name, pos) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const positions = [];
|
|
66
|
+
function has(element) {
|
|
67
|
+
return positions.some(a => a.start.equals(element.start));
|
|
68
|
+
}
|
|
69
|
+
for (const r of this.spag.getData().references) {
|
|
70
|
+
if (((_a = r.resolved) === null || _a === void 0 ? void 0 : _a.getName()) === name && ((_b = r.resolved) === null || _b === void 0 ? void 0 : _b.getStart().equals(pos))) {
|
|
71
|
+
const sub = {
|
|
72
|
+
start: r.position.getStart(),
|
|
73
|
+
end: r.position.getEnd(),
|
|
74
|
+
};
|
|
75
|
+
if (has(sub) === false) {
|
|
76
|
+
positions.push(sub);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const child of this.spag.getChildren()) {
|
|
81
|
+
const subPositions = new SpagHelper(child).findReferences(name, pos);
|
|
82
|
+
for (const sub of subPositions) {
|
|
83
|
+
if (has(sub) === false) {
|
|
84
|
+
positions.push(sub);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return positions;
|
|
89
|
+
}
|
|
90
|
+
findRecursiveDuplicate(name, skip) {
|
|
91
|
+
var _a;
|
|
92
|
+
const found = this.spag.findVariable(name);
|
|
93
|
+
if ((found === null || found === void 0 ? void 0 : found.getStart().equals(skip)) === false) {
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
96
|
+
for (const child of ((_a = this.spag) === null || _a === void 0 ? void 0 : _a.getChildren()) || []) {
|
|
97
|
+
const sub = new SpagHelper(child).findRecursiveDuplicate(name, skip);
|
|
98
|
+
if (sub) {
|
|
99
|
+
return sub;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
isDuplicateName(name, pos) {
|
|
105
|
+
let parent = this.spag.getParent();
|
|
106
|
+
while ((parent === null || parent === void 0 ? void 0 : parent.getIdentifier().stype) === _scope_type_1.ScopeType.Let
|
|
107
|
+
|| (parent === null || parent === void 0 ? void 0 : parent.getIdentifier().stype) === _scope_type_1.ScopeType.For) {
|
|
108
|
+
parent = parent.getParent();
|
|
109
|
+
}
|
|
110
|
+
if (parent === undefined) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
return new SpagHelper(parent).findRecursiveDuplicate(name, pos) !== undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
38
116
|
class Downport {
|
|
39
117
|
constructor() {
|
|
40
118
|
this.conf = new DownportConf();
|
|
@@ -1478,7 +1556,7 @@ ${indentation} output = ${topTarget}.`;
|
|
|
1478
1556
|
const start = loopTargetFieldExpression.getFirstToken().getStart();
|
|
1479
1557
|
const spag = highSyntax.spaghetti.lookupPosition(start, lowFile.getFilename());
|
|
1480
1558
|
if (loopTargetFieldName && spag) {
|
|
1481
|
-
if (
|
|
1559
|
+
if (new SpagHelper(spag).isDuplicateName(loopTargetFieldName, start)) {
|
|
1482
1560
|
this.renameVariable(spag, loopTargetFieldName, start, lowFile, highSyntax);
|
|
1483
1561
|
}
|
|
1484
1562
|
}
|
|
@@ -1725,6 +1803,11 @@ ${indentation} output = ${topTarget}.`;
|
|
|
1725
1803
|
if (firstName === "") {
|
|
1726
1804
|
firstName = name;
|
|
1727
1805
|
}
|
|
1806
|
+
// TODO TODO TODO, WORK IN PROGRESS
|
|
1807
|
+
const spag = highSyntax.spaghetti.lookupPosition(init.getFirstToken().getStart(), lowFile.getFilename());
|
|
1808
|
+
if (spag && new SpagHelper(spag).isDuplicateName(name, init.getFirstToken().getStart())) {
|
|
1809
|
+
this.renameVariable(spag, name, init.getFirstToken().getStart(), lowFile, highSyntax);
|
|
1810
|
+
}
|
|
1728
1811
|
const s = (_a = init.findFirstExpression(Expressions.Source)) === null || _a === void 0 ? void 0 : _a.concatTokens();
|
|
1729
1812
|
const t = (_b = init.findFirstExpression(Expressions.TypeName)) === null || _b === void 0 ? void 0 : _b.concatTokens();
|
|
1730
1813
|
if (s) {
|
|
@@ -1923,7 +2006,7 @@ ${indentation} output = ${topTarget}.`;
|
|
|
1923
2006
|
if (spag === undefined) {
|
|
1924
2007
|
continue;
|
|
1925
2008
|
}
|
|
1926
|
-
if (
|
|
2009
|
+
if (new SpagHelper(spag).isDuplicateName(name, c.getFirstToken().getStart())) {
|
|
1927
2010
|
this.renameVariable(spag, name, c.getFirstToken().getStart(), lowFile, highSyntax);
|
|
1928
2011
|
}
|
|
1929
2012
|
const found = spag.findVariable(name);
|
|
@@ -1944,40 +2027,11 @@ ${indentation} output = ${topTarget}.`;
|
|
|
1944
2027
|
return ret;
|
|
1945
2028
|
}
|
|
1946
2029
|
renameVariable(spag, name, pos, lowFile, highSyntax) {
|
|
1947
|
-
|
|
1948
|
-
const
|
|
1949
|
-
const positions = new Set();
|
|
1950
|
-
let fix = undefined;
|
|
1951
|
-
for (const r of spag.getData().references) {
|
|
1952
|
-
if (((_a = r.resolved) === null || _a === void 0 ? void 0 : _a.getName()) === name && ((_b = r.resolved) === null || _b === void 0 ? void 0 : _b.getStart().equals(pos))) {
|
|
1953
|
-
const key = JSON.stringify(r.position.getStart());
|
|
1954
|
-
if (positions.has(key)) {
|
|
1955
|
-
continue;
|
|
1956
|
-
}
|
|
1957
|
-
positions.add(key);
|
|
1958
|
-
const replace = edit_helper_1.EditHelper.replaceRange(lowFile, r.position.getStart(), r.position.getEnd(), uniqueName);
|
|
1959
|
-
if (fix === undefined) {
|
|
1960
|
-
fix = replace;
|
|
1961
|
-
}
|
|
1962
|
-
else {
|
|
1963
|
-
fix = edit_helper_1.EditHelper.merge(replace, fix);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
2030
|
+
const newName = this.uniqueName(pos, lowFile.getFilename(), highSyntax);
|
|
2031
|
+
const fix = new SpagHelper(spag).renameVariable(name, pos, lowFile, newName);
|
|
1967
2032
|
const issue = issue_1.Issue.atPosition(lowFile, pos, "Rename before outline", this.getMetadata().key, this.conf.severity, fix);
|
|
1968
2033
|
throw new SkipToNextFile(issue);
|
|
1969
2034
|
}
|
|
1970
|
-
isDuplicateName(spag, name, pos) {
|
|
1971
|
-
var _a;
|
|
1972
|
-
let isDuplicate = false;
|
|
1973
|
-
for (const child of ((_a = spag.getParent()) === null || _a === void 0 ? void 0 : _a.getChildren()) || []) {
|
|
1974
|
-
const found = child.findVariable(name);
|
|
1975
|
-
if ((found === null || found === void 0 ? void 0 : found.getStart().equals(pos)) === false) {
|
|
1976
|
-
isDuplicate = true;
|
|
1977
|
-
}
|
|
1978
|
-
}
|
|
1979
|
-
return isDuplicate;
|
|
1980
|
-
}
|
|
1981
2035
|
findType(i, lowFile, highSyntax, ref = false) {
|
|
1982
2036
|
var _a;
|
|
1983
2037
|
const expr = i.findDirectExpression(Expressions.TypeNameOrInfer);
|