@abaplint/core 2.120.107 → 2.120.108
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/abaplint.d.ts +1 -0
- package/build/src/abap/5_syntax/_key_compare.js +66 -0
- package/build/src/abap/5_syntax/statements/insert_internal.js +8 -0
- package/build/src/abap/5_syntax/statements/loop.js +2 -27
- package/build/src/abap/types/class_definition.js +52 -1
- package/build/src/registry.js +1 -1
- package/build/src/rules/_procedure_analysis.js +1 -0
- package/build/src/rules/constant_condition.js +201 -3
- package/build/src/rules/identical_conditions.js +76 -2
- package/build/src/rules/index.js +2 -0
- package/build/src/rules/inline_generic_source.js +170 -0
- package/build/src/rules/redundant_conversion.js +99 -2
- package/build/src/rules/sequential_read_sorted.js +318 -0
- package/build/src/rules/xml_consistency.js +24 -0
- package/package.json +1 -1
package/build/abaplint.d.ts
CHANGED
|
@@ -1257,6 +1257,7 @@ declare class ClassDefinition_3 extends Identifier implements IClassDefinition {
|
|
|
1257
1257
|
isSharedMemory(): boolean;
|
|
1258
1258
|
getCreateVisibility(): Visibility;
|
|
1259
1259
|
private checkClassNameLength;
|
|
1260
|
+
private checkLocalTypesInPublicSections;
|
|
1260
1261
|
private findSuper;
|
|
1261
1262
|
private checkMethodNameLength;
|
|
1262
1263
|
private checkClassConstructor;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.hasKeyCompare = hasKeyCompare;
|
|
37
|
+
const Expressions = __importStar(require("../2_statements/expressions"));
|
|
38
|
+
const nodes_1 = require("../nodes");
|
|
39
|
+
/** True if a conjunct of the WHERE condition reachable through AND only, ie. not under OR or NOT,
|
|
40
|
+
* compares the key component with = or IS INITIAL. Without such a comparison of its first component,
|
|
41
|
+
* a sorted key cannot be used to optimize the WHERE condition */
|
|
42
|
+
function hasKeyCompare(cond, component) {
|
|
43
|
+
if (cond.findDirectTokenByText("OR") !== undefined) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
for (const child of cond.getChildren()) {
|
|
47
|
+
if (child.get() instanceof Expressions.ComponentCompare && child instanceof nodes_1.ExpressionNode) {
|
|
48
|
+
const concat = child.concatTokens().toUpperCase().replace(/\s+/g, " ");
|
|
49
|
+
if (concat.startsWith(component + " = ")
|
|
50
|
+
|| concat.startsWith(component + " EQ ")
|
|
51
|
+
|| concat === component + " IS INITIAL") {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (child.get() instanceof Expressions.ComponentCondSub
|
|
56
|
+
&& child instanceof nodes_1.ExpressionNode
|
|
57
|
+
&& child.findDirectTokenByText("NOT") === undefined) {
|
|
58
|
+
const sub = child.findDirectExpression(Expressions.ComponentCond);
|
|
59
|
+
if (sub !== undefined && hasKeyCompare(sub, component)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=_key_compare.js.map
|
|
@@ -45,6 +45,7 @@ const _type_utils_1 = require("../_type_utils");
|
|
|
45
45
|
const _syntax_input_1 = require("../_syntax_input");
|
|
46
46
|
class InsertInternal {
|
|
47
47
|
runSyntax(node, input) {
|
|
48
|
+
var _a;
|
|
48
49
|
let targetType;
|
|
49
50
|
const t = node.findDirectExpression(Expressions.Target);
|
|
50
51
|
if (t) {
|
|
@@ -107,6 +108,13 @@ class InsertInternal {
|
|
|
107
108
|
// yea, well, INSERT doesnt convert the values automatically, like everything else?
|
|
108
109
|
error = true;
|
|
109
110
|
}
|
|
111
|
+
else if (sourceType instanceof basic_1.CharacterType
|
|
112
|
+
&& targetType instanceof basic_1.CharacterType
|
|
113
|
+
&& ((_a = sourceType.getAbstractTypeData()) === null || _a === void 0 ? void 0 : _a.derivedFromConstant) === true
|
|
114
|
+
&& sourceType.getLength() !== targetType.getLength()) {
|
|
115
|
+
// character literal of different length than the row type
|
|
116
|
+
error = true;
|
|
117
|
+
}
|
|
110
118
|
if (error === true) {
|
|
111
119
|
const message = "Types not compatible";
|
|
112
120
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
@@ -35,7 +35,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Loop = void 0;
|
|
37
37
|
const Expressions = __importStar(require("../../2_statements/expressions"));
|
|
38
|
-
const nodes_1 = require("../../nodes");
|
|
39
38
|
const basic_1 = require("../../types/basic");
|
|
40
39
|
const target_1 = require("../expressions/target");
|
|
41
40
|
const source_1 = require("../expressions/source");
|
|
@@ -47,6 +46,7 @@ const dynamic_1 = require("../expressions/dynamic");
|
|
|
47
46
|
const loop_group_by_1 = require("../expressions/loop_group_by");
|
|
48
47
|
const _syntax_input_1 = require("../_syntax_input");
|
|
49
48
|
const version_1 = require("../../../version");
|
|
49
|
+
const _key_compare_1 = require("../_key_compare");
|
|
50
50
|
class Loop {
|
|
51
51
|
runSyntax(node, input) {
|
|
52
52
|
var _a, _b;
|
|
@@ -151,7 +151,7 @@ class Loop {
|
|
|
151
151
|
// the first component of a sorted secondary key must be compared with = or IS INITIAL
|
|
152
152
|
// in a part of the condition joined by AND, otherwise the WHERE cannot be optimized
|
|
153
153
|
const first = key.keyFields[0].toUpperCase();
|
|
154
|
-
if (
|
|
154
|
+
if ((0, _key_compare_1.hasKeyCompare)(cond, first) === false) {
|
|
155
155
|
const message = "Loop, WHERE cannot be optimized for secondary key " + name +
|
|
156
156
|
", key component " + first + " needs a comparison with = or IS INITIAL joined by AND";
|
|
157
157
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
@@ -198,31 +198,6 @@ class Loop {
|
|
|
198
198
|
loop_group_by_1.LoopGroupBy.runSyntax(group, input);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
// true if a conjunct reachable through AND only, ie. not under OR or NOT, compares the component with = or IS INITIAL
|
|
202
|
-
hasKeyCompare(cond, component) {
|
|
203
|
-
if (cond.findDirectTokenByText("OR") !== undefined) {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
for (const child of cond.getChildren()) {
|
|
207
|
-
if (child.get() instanceof Expressions.ComponentCompare && child instanceof nodes_1.ExpressionNode) {
|
|
208
|
-
const concat = child.concatTokens().toUpperCase().replace(/\s+/g, " ");
|
|
209
|
-
if (concat.startsWith(component + " = ")
|
|
210
|
-
|| concat.startsWith(component + " EQ ")
|
|
211
|
-
|| concat === component + " IS INITIAL") {
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
else if (child.get() instanceof Expressions.ComponentCondSub
|
|
216
|
-
&& child instanceof nodes_1.ExpressionNode
|
|
217
|
-
&& child.findDirectTokenByText("NOT") === undefined) {
|
|
218
|
-
const sub = child.findDirectExpression(Expressions.ComponentCond);
|
|
219
|
-
if (sub !== undefined && this.hasKeyCompare(sub, component)) {
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
201
|
}
|
|
227
202
|
exports.Loop = Loop;
|
|
228
203
|
//# sourceMappingURL=loop.js.map
|
|
@@ -80,7 +80,7 @@ class ClassDefinition extends _identifier_1.Identifier {
|
|
|
80
80
|
this.events.push(new event_definition_1.EventDefinition(e, visibility_1.Visibility.Public, input)); // todo, all these are not Public
|
|
81
81
|
}
|
|
82
82
|
this.methodDefs = new method_definitions_1.MethodDefinitions(node, input);
|
|
83
|
-
input.scope.pop(node.getLastToken().getEnd());
|
|
83
|
+
const scope = input.scope.pop(node.getLastToken().getEnd());
|
|
84
84
|
const concat = def.concatTokens().toUpperCase();
|
|
85
85
|
this.testing = concat.includes(" FOR TESTING");
|
|
86
86
|
this.sharedMemory = concat.includes(" SHARED MEMORY ENABLED");
|
|
@@ -102,6 +102,7 @@ class ClassDefinition extends _identifier_1.Identifier {
|
|
|
102
102
|
this.checkClassNameLength(input);
|
|
103
103
|
this.checkMethodNameLength(input);
|
|
104
104
|
this.checkClassConstructor(input);
|
|
105
|
+
this.checkLocalTypesInPublicSections(input, node, scope.getTop());
|
|
105
106
|
}
|
|
106
107
|
getFriends() {
|
|
107
108
|
return this.friends;
|
|
@@ -156,6 +157,56 @@ class ClassDefinition extends _identifier_1.Identifier {
|
|
|
156
157
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, this.getToken(), message));
|
|
157
158
|
}
|
|
158
159
|
}
|
|
160
|
+
// the local types, classes and interfaces of a class pool can only be used in the PRIVATE SECTION of the global class
|
|
161
|
+
checkLocalTypesInPublicSections(input, node, scope) {
|
|
162
|
+
if (this.globalValue === false || input.filename.toLowerCase().endsWith(".clas.abap") === false) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const prefix = input.filename.toLowerCase().replace(/abap$/, "");
|
|
166
|
+
const isLocal = (filename) => {
|
|
167
|
+
const lower = filename.toLowerCase();
|
|
168
|
+
return lower.startsWith(prefix)
|
|
169
|
+
&& (lower.endsWith(".clas.locals_def.abap") || lower.endsWith(".clas.locals_imp.abap"));
|
|
170
|
+
};
|
|
171
|
+
const references = [];
|
|
172
|
+
const collect = (n) => {
|
|
173
|
+
for (const r of n.getData().references) {
|
|
174
|
+
if ((r.referenceType === _reference_1.ReferenceType.TypeReference || r.referenceType === _reference_1.ReferenceType.ObjectOrientedReference)
|
|
175
|
+
&& r.position.getFilename() === input.filename
|
|
176
|
+
&& r.position.getName().includes("~") === false // lif~meth of an ALIASES, the INTERFACES statement is reported
|
|
177
|
+
&& r.resolved !== undefined
|
|
178
|
+
&& isLocal(r.resolved.getFilename())) {
|
|
179
|
+
references.push(r);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
n.getChildren().forEach(collect);
|
|
183
|
+
};
|
|
184
|
+
collect(scope);
|
|
185
|
+
if (references.length === 0) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const sections = [
|
|
189
|
+
{ section: node.findDirectStructure(Structures.PublicSection), name: "PUBLIC" },
|
|
190
|
+
];
|
|
191
|
+
// a FINAL class has no subclasses, so the PROTECTED SECTION is effectively private
|
|
192
|
+
if (this.finalValue === false) {
|
|
193
|
+
sections.push({ section: node.findDirectStructure(Structures.ProtectedSection), name: "PROTECTED" });
|
|
194
|
+
}
|
|
195
|
+
for (const { section, name } of sections) {
|
|
196
|
+
for (const statement of (section === null || section === void 0 ? void 0 : section.findAllStatementNodes()) || []) {
|
|
197
|
+
// compare with the tokens, the statements of a chain share the first tokens
|
|
198
|
+
const tokens = statement.getTokens();
|
|
199
|
+
const found = references
|
|
200
|
+
.filter(r => tokens.some(t => t.getStart().equals(r.position.getStart())))
|
|
201
|
+
.sort((a, b) => a.position.getStart().isBefore(b.position.getStart()) ? -1 : 1)[0];
|
|
202
|
+
if (found !== undefined) {
|
|
203
|
+
const message = "\"" + found.position.getName().toUpperCase() +
|
|
204
|
+
"\" is local to the class pool and cannot be used in the " + name + " SECTION of the global class";
|
|
205
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, found.position.getToken(), message));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
159
210
|
findSuper(def, input) {
|
|
160
211
|
var _a;
|
|
161
212
|
const token = (_a = def === null || def === void 0 ? void 0 : def.findDirectExpression(expressions_1.SuperClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
package/build/src/registry.js
CHANGED
|
@@ -50,6 +50,7 @@ exports.isReferenceType = isReferenceType;
|
|
|
50
50
|
exports.identicalTypes = identicalTypes;
|
|
51
51
|
exports.simplePredicate = simplePredicate;
|
|
52
52
|
exports.characterConstant = characterConstant;
|
|
53
|
+
exports.textLiteral = textLiteral;
|
|
53
54
|
exports.sameCharacters = sameCharacters;
|
|
54
55
|
exports.isCondition = isCondition;
|
|
55
56
|
exports.dataSource = dataSource;
|
|
@@ -35,11 +35,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ConstantCondition = exports.ConstantConditionConf = void 0;
|
|
37
37
|
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
39
|
+
const nodes_1 = require("../abap/nodes");
|
|
38
40
|
const basic_1 = require("../abap/types/basic");
|
|
41
|
+
const _typed_identifier_1 = require("../abap/types/_typed_identifier");
|
|
42
|
+
const issue_1 = require("../issue");
|
|
39
43
|
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
40
44
|
const _irule_1 = require("./_irule");
|
|
41
45
|
const _procedure_analysis_1 = require("./_procedure_analysis");
|
|
42
46
|
class ConstantConditionConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
/** Report x <> a OR x <> b, always true, and x = a AND x = b, always false, for different character values a and b */
|
|
50
|
+
this.exclusiveValues = true;
|
|
51
|
+
}
|
|
43
52
|
}
|
|
44
53
|
exports.ConstantConditionConf = ConstantConditionConf;
|
|
45
54
|
class ConstantCondition {
|
|
@@ -50,7 +59,8 @@ class ConstantCondition {
|
|
|
50
59
|
return {
|
|
51
60
|
key: "constant_condition",
|
|
52
61
|
title: "Constant condition",
|
|
53
|
-
shortDescription: `Finds IF and ELSEIF conditions on local variables whose value is known
|
|
62
|
+
shortDescription: `Finds IF and ELSEIF conditions on local variables whose value is known, and conditions that compare
|
|
63
|
+
a field with two different values and are always true or always false`,
|
|
54
64
|
extendedInformation: `Reports two cases, for local variables of a METHOD, FORM or FUNCTION.
|
|
55
65
|
|
|
56
66
|
1. DATA(c) = <constant>. where the constant is a character literal like 'X', or a character constant like
|
|
@@ -69,15 +79,31 @@ an ELSEIF branch that is always taken turns into ELSE. Nothing is reported if a
|
|
|
69
79
|
data that is used outside of it.
|
|
70
80
|
|
|
71
81
|
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
72
|
-
INCLUDE, test seams, enhancements or native SQL. No release requirement
|
|
82
|
+
INCLUDE, test seams, enhancements or native SQL. No release requirement.
|
|
83
|
+
|
|
84
|
+
Option exclusiveValues: reports x <> a OR x <> b, which is always true, and x = a AND x = b, which is always
|
|
85
|
+
false, in any condition of a METHOD, FORM or FUNCTION, also with dynamic code. Also with NE and EQ, with NOT,
|
|
86
|
+
with the operands swapped, and with more conditions joined by the same operator. x is a data object of type c,
|
|
87
|
+
generic c or string, without calls, offsets or table expressions. a and b are character literals or character
|
|
88
|
+
constants, also components of constant structures of a class or interface, with different values. Usually one
|
|
89
|
+
of the operators or one of the values is wrong, there is no quick fix.
|
|
90
|
+
Not reported: conditions that mix AND and OR or contain a call, values that are not known, like constants of
|
|
91
|
+
classes outside the registry, other types of x, which can convert different values to the same one, ASSERT,
|
|
92
|
+
and SQL conditions, where a NULL value makes both comparisons unknown.`,
|
|
73
93
|
tags: [_irule_1.RuleTag.Quickfix],
|
|
74
94
|
badExample: `DATA(lv_active) = abap_true.
|
|
75
95
|
IF lv_active = abap_true.
|
|
76
96
|
run( ).
|
|
77
97
|
ELSE.
|
|
78
98
|
skip( ).
|
|
99
|
+
ENDIF.
|
|
100
|
+
IF lv_kind <> 'N' OR lv_kind <> 'P'.
|
|
101
|
+
skip( ).
|
|
102
|
+
ENDIF.`,
|
|
103
|
+
goodExample: `run( ).
|
|
104
|
+
IF lv_kind <> 'N' AND lv_kind <> 'P'.
|
|
105
|
+
skip( ).
|
|
79
106
|
ENDIF.`,
|
|
80
|
-
goodExample: `run( ).`,
|
|
81
107
|
};
|
|
82
108
|
}
|
|
83
109
|
getConfig() {
|
|
@@ -97,6 +123,9 @@ ENDIF.`,
|
|
|
97
123
|
}
|
|
98
124
|
const issues = [];
|
|
99
125
|
for (const procedure of analysis.procedures) {
|
|
126
|
+
if (this.conf.exclusiveValues) {
|
|
127
|
+
issues.push(...this.exclusiveValues(procedure));
|
|
128
|
+
}
|
|
100
129
|
if (procedure.supported === false) {
|
|
101
130
|
continue;
|
|
102
131
|
}
|
|
@@ -198,6 +227,175 @@ ENDIF.`,
|
|
|
198
227
|
return source.countTokens() === 1 && source.findDirectExpression(Expressions.FieldChain) !== undefined
|
|
199
228
|
&& source.getFirstToken().getStart().equals(read.token.getStart());
|
|
200
229
|
}
|
|
230
|
+
/** x <> a OR x <> b, x = a AND x = b */
|
|
231
|
+
exclusiveValues(procedure) {
|
|
232
|
+
const issues = [];
|
|
233
|
+
for (const statement of procedure.statements) {
|
|
234
|
+
if (statement.get() instanceof Statements.Assert) {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
for (const cond of statement.findAllExpressionsRecursive(Expressions.Cond)) {
|
|
238
|
+
const operators = cond.getChildren().filter(c => c instanceof nodes_1.TokenNode).map(c => c.getFirstToken().getStr().toUpperCase());
|
|
239
|
+
const operator = operators[0];
|
|
240
|
+
if ((operator !== "OR" && operator !== "AND") || operators.some(o => o !== operator) || this.hasCall(cond)) {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const seen = [];
|
|
244
|
+
for (const child of cond.getChildren()) {
|
|
245
|
+
const comparison = child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.Compare
|
|
246
|
+
? this.valueComparison(procedure, child) : undefined;
|
|
247
|
+
if (comparison === undefined || comparison.equal !== (operator === "AND")) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const other = seen.find(s => s.subject === comparison.subject && !(0, _procedure_analysis_1.sameCharacters)(s.value, comparison.value));
|
|
251
|
+
if (other !== undefined) {
|
|
252
|
+
const message = "Condition is always " + (operator === "OR" ? "true" : "false") + ", "
|
|
253
|
+
+ this.subjectText(comparison) + " cannot be both "
|
|
254
|
+
+ other.constant.concatTokens() + " and " + comparison.constant.concatTokens();
|
|
255
|
+
issues.push(issue_1.Issue.atRange(procedure.file, other.compare.getFirstToken().getStart(), comparison.compare.getLastToken().getEnd(), message, this.getMetadata().key, this.conf.severity));
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
seen.push(comparison);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return issues;
|
|
263
|
+
}
|
|
264
|
+
hasCall(node) {
|
|
265
|
+
return node.findFirstExpression(Expressions.MethodCall) !== undefined
|
|
266
|
+
|| node.findFirstExpression(Expressions.MethodCallChain) !== undefined
|
|
267
|
+
|| node.findFirstExpression(Expressions.NewObject) !== undefined;
|
|
268
|
+
}
|
|
269
|
+
/** x = a, x <> a, a = x, NOT x = a etc, x character-like and a a known character value */
|
|
270
|
+
valueComparison(procedure, compare) {
|
|
271
|
+
const children = compare.getChildren();
|
|
272
|
+
const negated = children[0] instanceof nodes_1.TokenNode && children[0].getFirstToken().getStr().toUpperCase() === "NOT";
|
|
273
|
+
const rest = children.slice(negated ? 1 : 0);
|
|
274
|
+
if (rest.length !== 3 || !(rest[0] instanceof nodes_1.ExpressionNode) || !(rest[2] instanceof nodes_1.ExpressionNode)
|
|
275
|
+
|| !(rest[1].get() instanceof Expressions.CompareOperator)) {
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
const operator = rest[1].concatTokens().toUpperCase().replace(/ /g, "");
|
|
279
|
+
let equal;
|
|
280
|
+
if (operator === "=" || operator === "EQ") {
|
|
281
|
+
equal = true;
|
|
282
|
+
}
|
|
283
|
+
else if (operator === "<>" || operator === "><" || operator === "NE") {
|
|
284
|
+
equal = false;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
for (const [subject, constant] of [[rest[0], rest[2]], [rest[2], rest[0]]]) {
|
|
290
|
+
const value = this.constantValue(procedure, constant);
|
|
291
|
+
const type = value === undefined ? undefined : this.subjectType(procedure, subject);
|
|
292
|
+
if (value !== undefined
|
|
293
|
+
&& (type instanceof basic_1.CharacterType || type instanceof basic_1.CGenericType || type instanceof basic_1.StringType)) {
|
|
294
|
+
const text = subject.getTokens().map(t => t.getStr().toUpperCase()).join(" ");
|
|
295
|
+
return { subject: text, value, equal: equal !== negated, compare, constant };
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
subjectText(comparison) {
|
|
301
|
+
var _a;
|
|
302
|
+
var _b;
|
|
303
|
+
return (_b = (_a = comparison.compare.getChildren().find(c => c instanceof nodes_1.ExpressionNode && c !== comparison.constant
|
|
304
|
+
&& c.get() instanceof Expressions.Source)) === null || _a === void 0 ? void 0 : _a.concatTokens()) !== null && _b !== void 0 ? _b : comparison.subject;
|
|
305
|
+
}
|
|
306
|
+
/** type of a field, field symbol, attribute or component chain, without calls, offsets or table expressions */
|
|
307
|
+
subjectType(procedure, source) {
|
|
308
|
+
var _a;
|
|
309
|
+
var _b;
|
|
310
|
+
const chain = source.getChildren().length === 1 ? source.findDirectExpression(Expressions.FieldChain) : undefined;
|
|
311
|
+
const children = (_b = chain === null || chain === void 0 ? void 0 : chain.getChildren()) !== null && _b !== void 0 ? _b : [];
|
|
312
|
+
let identifier;
|
|
313
|
+
let next;
|
|
314
|
+
if (children[0] instanceof nodes_1.ExpressionNode
|
|
315
|
+
&& (children[0].get() instanceof Expressions.SourceField || children[0].get() instanceof Expressions.SourceFieldSymbol)) {
|
|
316
|
+
identifier = procedure.identifierAt(children[0].getFirstToken());
|
|
317
|
+
next = 1;
|
|
318
|
+
}
|
|
319
|
+
else if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.ClassName
|
|
320
|
+
&& ((_a = children[1]) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr()) === "=>" && children[2] instanceof nodes_1.ExpressionNode) {
|
|
321
|
+
identifier = procedure.identifierAt(children[2].getFirstToken());
|
|
322
|
+
next = 3;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
let type = identifier instanceof _typed_identifier_1.TypedIdentifier ? identifier.getType() : undefined;
|
|
328
|
+
for (let i = next; i < children.length; i += 2) {
|
|
329
|
+
const separator = children[i];
|
|
330
|
+
const name = children[i + 1];
|
|
331
|
+
if (!(separator instanceof nodes_1.TokenNode) || !(name instanceof nodes_1.ExpressionNode) || type === undefined) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
else if (separator.getFirstToken().getStr() === "->" && name.get() instanceof Expressions.AttributeName) {
|
|
335
|
+
const attribute = procedure.identifierAt(name.getFirstToken());
|
|
336
|
+
type = attribute instanceof _typed_identifier_1.TypedIdentifier ? attribute.getType() : undefined;
|
|
337
|
+
}
|
|
338
|
+
else if (separator.getFirstToken().getStr() === "-" && name.get() instanceof Expressions.ComponentName
|
|
339
|
+
&& type instanceof basic_1.StructureType) {
|
|
340
|
+
type = type.getComponentByName(name.getFirstToken().getStr());
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return type;
|
|
347
|
+
}
|
|
348
|
+
/** value of a character literal, a character constant or a character component of a constant structure */
|
|
349
|
+
constantValue(procedure, source) {
|
|
350
|
+
var _a;
|
|
351
|
+
var _b;
|
|
352
|
+
if (source.findDirectExpression(Expressions.Constant) !== undefined) {
|
|
353
|
+
return (0, _procedure_analysis_1.characterConstant)(procedure, source);
|
|
354
|
+
}
|
|
355
|
+
const chain = source.getChildren().length === 1 ? source.findDirectExpression(Expressions.FieldChain) : undefined;
|
|
356
|
+
const children = (_b = chain === null || chain === void 0 ? void 0 : chain.getChildren()) !== null && _b !== void 0 ? _b : [];
|
|
357
|
+
let identifier;
|
|
358
|
+
let next;
|
|
359
|
+
if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.SourceField) {
|
|
360
|
+
identifier = procedure.identifierAt(children[0].getFirstToken());
|
|
361
|
+
next = 1;
|
|
362
|
+
}
|
|
363
|
+
else if (children[0] instanceof nodes_1.ExpressionNode && children[0].get() instanceof Expressions.ClassName
|
|
364
|
+
&& ((_a = children[1]) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr()) === "=>" && children[2] instanceof nodes_1.ExpressionNode
|
|
365
|
+
&& children[2].get() instanceof Expressions.AttributeName) {
|
|
366
|
+
identifier = procedure.identifierAt(children[2].getFirstToken());
|
|
367
|
+
next = 3;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
if (!(identifier instanceof _typed_identifier_1.TypedIdentifier) || !(0, _procedure_analysis_1.isImmutable)(identifier)) {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
let type = identifier.getType();
|
|
376
|
+
let value = identifier.getValue();
|
|
377
|
+
if (children.length === next + 2) {
|
|
378
|
+
const name = children[next + 1];
|
|
379
|
+
if (children[next].getFirstToken().getStr() !== "-" || !(name instanceof nodes_1.ExpressionNode)
|
|
380
|
+
|| !(name.get() instanceof Expressions.ComponentName) || !(type instanceof basic_1.StructureType)
|
|
381
|
+
|| typeof value !== "object") {
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
const component = name.getFirstToken().getStr().toLowerCase();
|
|
385
|
+
type = type.getComponentByName(component);
|
|
386
|
+
const key = Object.keys(value).find(k => k.toLowerCase() === component);
|
|
387
|
+
value = key === undefined ? undefined : value[key];
|
|
388
|
+
}
|
|
389
|
+
else if (children.length !== next) {
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
const text = typeof value === "string" ? (0, _procedure_analysis_1.textLiteral)(value) : undefined;
|
|
393
|
+
if (!(type instanceof basic_1.CharacterType) || text === undefined) {
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
// the value is cut to the length of the constant
|
|
397
|
+
return text.substring(0, type.getLength());
|
|
398
|
+
}
|
|
201
399
|
}
|
|
202
400
|
exports.ConstantCondition = ConstantCondition;
|
|
203
401
|
//# sourceMappingURL=constant_condition.js.map
|
|
@@ -55,6 +55,11 @@ class Conditions {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
class IdenticalConditionsConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
58
|
+
constructor() {
|
|
59
|
+
super(...arguments);
|
|
60
|
+
/** Report a comparison of an operand with itself, like a = a or a <> a */
|
|
61
|
+
this.selfComparison = true;
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
exports.IdenticalConditionsConf = IdenticalConditionsConf;
|
|
60
65
|
class IdenticalConditions extends _abap_rule_1.ABAPRule {
|
|
@@ -69,19 +74,30 @@ class IdenticalConditions extends _abap_rule_1.ABAPRule {
|
|
|
69
74
|
shortDescription: `Find identical conditions in IF + CASE + WHILE etc
|
|
70
75
|
|
|
71
76
|
Prerequsites: code is pretty printed with identical cAsE`,
|
|
77
|
+
extendedInformation: `Option selfComparison: reports a comparison with =, <>, <, >, <= or >= (and EQ, NE, LT, GT, LE, GE)
|
|
78
|
+
whose two operands are the same data object, like a = a or ls_new-id <> ls_new-id. The comparison is always true or
|
|
79
|
+
always false, usually one side should be another field.
|
|
80
|
+
|
|
81
|
+
Only operands that are data objects are compared: fields, components, attributes, field symbols, dereferences,
|
|
82
|
+
offset/length and table expressions without calls. Not reported: method calls and built-in functions, which can
|
|
83
|
+
return different values, literals like 1 = 1, ASSERT, and SQL conditions.`,
|
|
72
84
|
tags: [_irule_1.RuleTag.SingleFile],
|
|
73
85
|
badExample: `IF foo = bar OR 1 = a OR foo = bar.
|
|
74
86
|
ENDIF.
|
|
75
87
|
CASE bar.
|
|
76
88
|
WHEN '1'.
|
|
77
89
|
WHEN 'A' OR '1'.
|
|
78
|
-
ENDCASE
|
|
90
|
+
ENDCASE.
|
|
91
|
+
IF ls_new-id = ls_new-id.
|
|
92
|
+
ENDIF.`,
|
|
79
93
|
goodExample: `IF foo = bar OR 1 = a.
|
|
80
94
|
ENDIF.
|
|
81
95
|
CASE bar.
|
|
82
96
|
WHEN '1'.
|
|
83
97
|
WHEN 'A'.
|
|
84
|
-
ENDCASE
|
|
98
|
+
ENDCASE.
|
|
99
|
+
IF ls_new-id = ls_old-id.
|
|
100
|
+
ENDIF.`,
|
|
85
101
|
};
|
|
86
102
|
}
|
|
87
103
|
getConfig() {
|
|
@@ -105,9 +121,67 @@ ENDCASE.`,
|
|
|
105
121
|
for (const i of structure.findAllExpressions(Expressions.Cond)) {
|
|
106
122
|
issues = issues.concat(this.analyzeCond(file, i));
|
|
107
123
|
}
|
|
124
|
+
if (this.conf.selfComparison) {
|
|
125
|
+
issues = issues.concat(this.analyzeSelfComparison(file));
|
|
126
|
+
}
|
|
108
127
|
return issues;
|
|
109
128
|
}
|
|
110
129
|
////////////////
|
|
130
|
+
analyzeSelfComparison(file) {
|
|
131
|
+
const issues = [];
|
|
132
|
+
for (const statement of file.getStatements()) {
|
|
133
|
+
if (statement.get() instanceof Statements.Assert) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
for (const compare of statement.findAllExpressionsRecursive(Expressions.Compare)) {
|
|
137
|
+
const children = compare.getChildren();
|
|
138
|
+
const negated = children[0] instanceof nodes_1.TokenNode && children[0].getFirstToken().getStr().toUpperCase() === "NOT";
|
|
139
|
+
const rest = children.slice(negated ? 1 : 0);
|
|
140
|
+
if (rest.length !== 3
|
|
141
|
+
|| !(rest[0] instanceof nodes_1.ExpressionNode) || !(rest[0].get() instanceof Expressions.Source)
|
|
142
|
+
|| !(rest[1] instanceof nodes_1.ExpressionNode) || !(rest[1].get() instanceof Expressions.CompareOperator)
|
|
143
|
+
|| !(rest[2] instanceof nodes_1.ExpressionNode) || !(rest[2].get() instanceof Expressions.Source)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const operator = rest[1].concatTokens().toUpperCase().replace(/ /g, "");
|
|
147
|
+
const value = this.selfValue(operator);
|
|
148
|
+
const left = this.dataObject(rest[0]);
|
|
149
|
+
if (value === undefined || left === undefined || left !== this.dataObject(rest[2])) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const result = value !== negated ? "true" : "false";
|
|
153
|
+
const message = "Comparison is always " + result + ", " + rest[0].concatTokens() + " is compared with itself";
|
|
154
|
+
issues.push(issue_1.Issue.atRange(file, compare.getFirstToken().getStart(), compare.getLastToken().getEnd(), message, this.getMetadata().key, this.conf.severity));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return issues;
|
|
158
|
+
}
|
|
159
|
+
/** result of comparing a value with itself, undefined for operators like CO or CP */
|
|
160
|
+
selfValue(operator) {
|
|
161
|
+
if (["=", "EQ", "<=", "=<", "LE", ">=", "=>", "GE"].includes(operator)) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
else if (["<>", "><", "NE", "<", "LT", ">", "GT"].includes(operator)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
/** the text of an operand that is a data object without calls, names in upper case, literals as they are */
|
|
170
|
+
dataObject(source) {
|
|
171
|
+
const children = source.getChildren();
|
|
172
|
+
if (!(children[0] instanceof nodes_1.ExpressionNode) || !(children[0].get() instanceof Expressions.FieldChain)
|
|
173
|
+
|| (children.length === 2 && !(children[1].get() instanceof Expressions.Dereference))
|
|
174
|
+
|| children.length > 2
|
|
175
|
+
|| source.findFirstExpression(Expressions.MethodCall) !== undefined
|
|
176
|
+
|| source.findFirstExpression(Expressions.MethodCallChain) !== undefined
|
|
177
|
+
|| source.findFirstExpression(Expressions.NewObject) !== undefined) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
return source.getTokens().map(t => {
|
|
181
|
+
const str = t.getStr();
|
|
182
|
+
return str.startsWith("'") || str.startsWith("`") || str.startsWith("|") || str.startsWith("}") ? str : str.toUpperCase();
|
|
183
|
+
}).join(" ");
|
|
184
|
+
}
|
|
111
185
|
analyzeCond(file, node) {
|
|
112
186
|
const conditions = new Conditions();
|
|
113
187
|
let operator = "";
|
package/build/src/rules/index.js
CHANGED
|
@@ -116,6 +116,7 @@ __exportStar(require("./in_statement_indentation"), exports);
|
|
|
116
116
|
__exportStar(require("./indentation"), exports);
|
|
117
117
|
__exportStar(require("./index_completely_contained"), exports);
|
|
118
118
|
__exportStar(require("./inline_data_old_versions"), exports);
|
|
119
|
+
__exportStar(require("./inline_generic_source"), exports);
|
|
119
120
|
__exportStar(require("./inline_packed_computation"), exports);
|
|
120
121
|
__exportStar(require("./intf_referencing_clas"), exports);
|
|
121
122
|
__exportStar(require("./invalid_table_index"), exports);
|
|
@@ -197,6 +198,7 @@ __exportStar(require("./select_single_full_key"), exports);
|
|
|
197
198
|
__exportStar(require("./selection_screen_naming"), exports);
|
|
198
199
|
__exportStar(require("./selection_screen_texts_missing"), exports);
|
|
199
200
|
__exportStar(require("./sequential_blank"), exports);
|
|
201
|
+
__exportStar(require("./sequential_read_sorted"), exports);
|
|
200
202
|
__exportStar(require("./short_case"), exports);
|
|
201
203
|
__exportStar(require("./sicf_consistency"), exports);
|
|
202
204
|
__exportStar(require("./single_use_expression_temp"), exports);
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.InlineGenericSource = exports.InlineGenericSourceConf = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
39
|
+
const _reference_1 = require("../abap/5_syntax/_reference");
|
|
40
|
+
const syntax_1 = require("../abap/5_syntax/syntax");
|
|
41
|
+
const nodes_1 = require("../abap/nodes");
|
|
42
|
+
const _typed_identifier_1 = require("../abap/types/_typed_identifier");
|
|
43
|
+
const basic_1 = require("../abap/types/basic");
|
|
44
|
+
const edit_helper_1 = require("../edit_helper");
|
|
45
|
+
const issue_1 = require("../issue");
|
|
46
|
+
const _abap_object_1 = require("../objects/_abap_object");
|
|
47
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
48
|
+
const _irule_1 = require("./_irule");
|
|
49
|
+
class InlineGenericSourceConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
50
|
+
}
|
|
51
|
+
exports.InlineGenericSourceConf = InlineGenericSourceConf;
|
|
52
|
+
class InlineGenericSource {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.conf = new InlineGenericSourceConf();
|
|
55
|
+
}
|
|
56
|
+
getMetadata() {
|
|
57
|
+
return {
|
|
58
|
+
key: "inline_generic_source",
|
|
59
|
+
title: "Inline declaration from a generically typed source",
|
|
60
|
+
shortDescription: `Finds inline declarations whose value is a generically typed parameter or field symbol`,
|
|
61
|
+
extendedInformation: `DATA( ) or FINAL( ) takes the type of the source. When the source is a parameter or
|
|
62
|
+
field symbol with a generic type, the type is fixed when the program is compiled: string for clike and
|
|
63
|
+
csequence, xstring for xsequence. The syntax check warns "The fixed type STRING is used for the generic
|
|
64
|
+
type CLIKE".
|
|
65
|
+
|
|
66
|
+
Reported for DATA(var) = source and FINAL(var) = source when the source is just the parameter or field
|
|
67
|
+
symbol. Most other generic types cannot be made concrete, that is a syntax error which check_syntax reports.
|
|
68
|
+
|
|
69
|
+
Declare the variable with a type, or name the type with CONV.
|
|
70
|
+
|
|
71
|
+
The pragma ##TYPE, which hides the syntax check warning, also hides this issue.
|
|
72
|
+
|
|
73
|
+
prefer_inline does not suggest inline declarations for generic sources, this rule reports the ones
|
|
74
|
+
that exist.
|
|
75
|
+
|
|
76
|
+
https://help.sap.com/doc/abapdocu_758_index_htm/7.58/en-US/abapmove.htm`,
|
|
77
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
78
|
+
pragma: "##TYPE",
|
|
79
|
+
badExample: `METHOD m. " IMPORTING iv TYPE clike
|
|
80
|
+
DATA(lv) = iv.
|
|
81
|
+
ENDMETHOD.`,
|
|
82
|
+
goodExample: `METHOD m. " IMPORTING iv TYPE clike
|
|
83
|
+
DATA(lv) = CONV string( iv ).
|
|
84
|
+
ENDMETHOD.`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
getConfig() {
|
|
88
|
+
return this.conf;
|
|
89
|
+
}
|
|
90
|
+
setConfig(conf) {
|
|
91
|
+
this.conf = conf;
|
|
92
|
+
}
|
|
93
|
+
initialize(reg) {
|
|
94
|
+
this.reg = reg;
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
run(obj) {
|
|
98
|
+
var _a, _b, _c;
|
|
99
|
+
if (!(obj instanceof _abap_object_1.ABAPObject)) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
const syntax = new syntax_1.SyntaxLogic(this.reg, obj).run();
|
|
103
|
+
if (syntax.issues.length > 0) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
const issues = [];
|
|
107
|
+
for (const file of obj.getABAPFiles()) {
|
|
108
|
+
for (const statement of file.getStatements()) {
|
|
109
|
+
if (!(statement.get() instanceof Statements.Move)
|
|
110
|
+
|| statement.getPragmas().some(p => p.getStr().toUpperCase() === this.getMetadata().pragma)) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const inline = (_a = statement.findDirectExpression(Expressions.Target)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.InlineData);
|
|
114
|
+
const name = (_b = inline === null || inline === void 0 ? void 0 : inline.findDirectExpression(Expressions.TargetField)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
|
|
115
|
+
const operand = this.singleOperand(statement.findDirectExpression(Expressions.Source));
|
|
116
|
+
if (name === undefined || operand === undefined) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const scope = syntax.spaghetti.lookupPosition(name.getStart(), file.getFilename());
|
|
120
|
+
const resolved = (_c = scope === null || scope === void 0 ? void 0 : scope.getData().references.find(reference => reference.referenceType === _reference_1.ReferenceType.DataReadReference
|
|
121
|
+
&& reference.position.getStart().equals(operand.getFirstToken().getStart()))) === null || _c === void 0 ? void 0 : _c.resolved;
|
|
122
|
+
if (!(resolved instanceof _typed_identifier_1.TypedIdentifier)) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const fixed = this.fixedType(resolved.getType());
|
|
126
|
+
if (fixed === undefined) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const message = `The fixed type ${fixed.fixed} is used for the generic type ${fixed.generic} of "${operand.concatTokens()}", ` +
|
|
130
|
+
`declare "${name.getStr()}" with a type or use CONV`;
|
|
131
|
+
const replacement = `CONV ${fixed.conv}( ${operand.concatTokens()} )`;
|
|
132
|
+
const fix = edit_helper_1.EditHelper.replaceRange(file, operand.getFirstToken().getStart(), operand.getLastToken().getEnd(), replacement);
|
|
133
|
+
issues.push(issue_1.Issue.atToken(file, name, message, this.getMetadata().key, this.conf.severity, fix));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return issues;
|
|
137
|
+
}
|
|
138
|
+
/** The source when it is a single field or field symbol, without components, offset/length or dereference */
|
|
139
|
+
singleOperand(source) {
|
|
140
|
+
if (source === undefined || source.getChildren().length !== 1) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
const chain = source.findDirectExpression(Expressions.FieldChain);
|
|
144
|
+
if (chain === undefined || chain.getChildren().length !== 1) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
const first = chain.getFirstChild();
|
|
148
|
+
if (first instanceof nodes_1.ExpressionNode
|
|
149
|
+
&& (first.get() instanceof Expressions.SourceField || first.get() instanceof Expressions.SourceFieldSymbol)) {
|
|
150
|
+
return chain;
|
|
151
|
+
}
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
/** The type the system uses for a generic type in an inline declaration, undefined if the type is not generic,
|
|
155
|
+
* or is a generic type that check_syntax does not make concrete */
|
|
156
|
+
fixedType(type) {
|
|
157
|
+
if (type instanceof basic_1.CLikeType) {
|
|
158
|
+
return { generic: "CLIKE", fixed: "STRING", conv: "string" };
|
|
159
|
+
}
|
|
160
|
+
else if (type instanceof basic_1.CSequenceType) {
|
|
161
|
+
return { generic: "CSEQUENCE", fixed: "STRING", conv: "string" };
|
|
162
|
+
}
|
|
163
|
+
else if (type instanceof basic_1.XSequenceType) {
|
|
164
|
+
return { generic: "XSEQUENCE", fixed: "XSTRING", conv: "xstring" };
|
|
165
|
+
}
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.InlineGenericSource = InlineGenericSource;
|
|
170
|
+
//# sourceMappingURL=inline_generic_source.js.map
|
|
@@ -49,6 +49,12 @@ const _irule_1 = require("./_irule");
|
|
|
49
49
|
const edit_helper_1 = require("../edit_helper");
|
|
50
50
|
const version_1 = require("../version");
|
|
51
51
|
class RedundantConversionConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
54
|
+
/** Also report a CONV that is the whole right-hand side of an assignment whose target already has the
|
|
55
|
+
* conversion type, e.g. "count = CONV i( text )." with count TYPE i, the assignment converts by itself */
|
|
56
|
+
this.assignmentTarget = true;
|
|
57
|
+
}
|
|
52
58
|
}
|
|
53
59
|
exports.RedundantConversionConf = RedundantConversionConf;
|
|
54
60
|
class RedundantConversion {
|
|
@@ -61,7 +67,12 @@ class RedundantConversion {
|
|
|
61
67
|
title: "Redundant Conversion",
|
|
62
68
|
shortDescription: `Find redundant CONV expressions`,
|
|
63
69
|
extendedInformation: `Reports CONV expressions whose operand already has the conversion's target type,
|
|
64
|
-
including the result of a built-in function with a fixed result type, like to_upper( ) or strlen( )
|
|
70
|
+
including the result of a built-in function with a fixed result type, like to_upper( ) or strlen( ).
|
|
71
|
+
|
|
72
|
+
With option assignmentTarget, also reports a CONV that is the whole right-hand side of an assignment
|
|
73
|
+
whose target already has the conversion's type, "count = CONV i( text )." with count TYPE i, the
|
|
74
|
+
assignment converts by itself. Not reported for inline declarations, enumerated types, LET, and operands
|
|
75
|
+
with a generic type.`,
|
|
65
76
|
tags: [_irule_1.RuleTag.Quickfix],
|
|
66
77
|
badExample: `DATA text TYPE string.
|
|
67
78
|
text = CONV string( text ).`,
|
|
@@ -121,7 +132,11 @@ text = text.`,
|
|
|
121
132
|
}
|
|
122
133
|
const operandHasSameType = operandType !== undefined && this.sameType(target.getType(), operandType);
|
|
123
134
|
const arithmeticHasSameContext = this.arithmeticUsesSameTargetType(source, bodySource, file, scope, target.getType());
|
|
124
|
-
|
|
135
|
+
const assignmentHasSameType = this.conf.assignmentTarget !== false
|
|
136
|
+
&& this.assignmentTargetHasSameType(source, file, scope, target.getType());
|
|
137
|
+
if (operandHasSameType === false
|
|
138
|
+
&& arithmeticHasSameContext === false
|
|
139
|
+
&& assignmentHasSameType === false) {
|
|
125
140
|
continue;
|
|
126
141
|
}
|
|
127
142
|
const closingParen = source.getDirectTokens().find(token => token.getStr() === ")" && token.getStart().isAfter(bodySource.getLastToken().getStart()));
|
|
@@ -156,6 +171,88 @@ text = text.`,
|
|
|
156
171
|
return assignmentTarget instanceof _typed_identifier_1.TypedIdentifier
|
|
157
172
|
&& this.sameType(conversionType, assignmentTarget.getType());
|
|
158
173
|
}
|
|
174
|
+
/** "target = CONV i( text )." where target has the conversion type, the assignment converts the same way */
|
|
175
|
+
assignmentTargetHasSameType(conversion, file, scope, conversionType) {
|
|
176
|
+
var _a;
|
|
177
|
+
// CONV converts the base type to an enumerated type, a plain assignment does not compile
|
|
178
|
+
if (conversionType instanceof basic_1.EnumType) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
const body = conversion.findDirectExpression(Expressions.ConvBody);
|
|
182
|
+
if (body === undefined
|
|
183
|
+
|| body.findDirectExpression(Expressions.Let) !== undefined
|
|
184
|
+
// "CONV type ( body )" without a trailing operator
|
|
185
|
+
|| conversion.getChildren().length !== 5) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
// "target = CONV ...", not "+=", "?=", "a = b = CONV ..." or MOVE
|
|
189
|
+
const statement = file.getStatements().find(candidate => candidate.includesToken(conversion.getFirstToken()));
|
|
190
|
+
const children = (_a = statement === null || statement === void 0 ? void 0 : statement.getChildren()) !== null && _a !== void 0 ? _a : [];
|
|
191
|
+
const target = children[0];
|
|
192
|
+
if (!((statement === null || statement === void 0 ? void 0 : statement.get()) instanceof Statements.Move)
|
|
193
|
+
|| children.length !== 4
|
|
194
|
+
|| !(target instanceof nodes_1.ExpressionNode)
|
|
195
|
+
|| !(target.get() instanceof Expressions.Target)
|
|
196
|
+
|| children[1].concatTokens() !== "="
|
|
197
|
+
|| children[2] !== conversion) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
// a generic operand gets its type from the CONV, also "ref->*" with ref TYPE REF TO data
|
|
201
|
+
const bodyStart = body.getFirstToken().getStart();
|
|
202
|
+
const bodyEnd = body.getLastToken().getEnd();
|
|
203
|
+
const genericOperand = scope.getData().references.some(reference => {
|
|
204
|
+
if (reference.referenceType !== _reference_1.ReferenceType.DataReadReference
|
|
205
|
+
|| reference.position.getFilename() !== file.getFilename()
|
|
206
|
+
|| reference.position.getStart().isBetween(bodyStart, bodyEnd) === false
|
|
207
|
+
|| !(reference.resolved instanceof _typed_identifier_1.TypedIdentifier)) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
const type = reference.resolved.getType();
|
|
211
|
+
return type.isGeneric() || (type instanceof basic_1.DataReference && type.getType().isGeneric());
|
|
212
|
+
});
|
|
213
|
+
if (genericOperand === true) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
const targetType = this.targetType(target, scope);
|
|
217
|
+
return targetType !== undefined && this.sameType(conversionType, targetType);
|
|
218
|
+
}
|
|
219
|
+
/** Type of a variable, field symbol, attribute or structure component, undefined for anything else */
|
|
220
|
+
targetType(target, scope) {
|
|
221
|
+
var _a;
|
|
222
|
+
let type;
|
|
223
|
+
for (const child of target.getChildren()) {
|
|
224
|
+
if (child instanceof nodes_1.TokenNode) {
|
|
225
|
+
if (["-", "->", "=>"].includes(child.getFirstToken().getStr()) === false) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else if (child.get() instanceof Expressions.TargetField
|
|
230
|
+
|| child.get() instanceof Expressions.TargetFieldSymbol
|
|
231
|
+
|| child.get() instanceof Expressions.AttributeName) {
|
|
232
|
+
const resolved = (_a = scope.getData().references.find(reference => (reference.referenceType === _reference_1.ReferenceType.DataWriteReference
|
|
233
|
+
|| reference.referenceType === _reference_1.ReferenceType.DataReadReference)
|
|
234
|
+
&& reference.position.getStart().equals(child.getFirstToken().getStart()))) === null || _a === void 0 ? void 0 : _a.resolved;
|
|
235
|
+
if (!(resolved instanceof _typed_identifier_1.TypedIdentifier)) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
type = resolved.getType();
|
|
239
|
+
}
|
|
240
|
+
else if (child.get() instanceof Expressions.ComponentName) {
|
|
241
|
+
if (type instanceof basic_1.TableType) {
|
|
242
|
+
type = type.getRowType();
|
|
243
|
+
}
|
|
244
|
+
if (!(type instanceof basic_1.StructureType)) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
type = type.getComponentByName(child.concatTokens());
|
|
248
|
+
}
|
|
249
|
+
else if (!(child.get() instanceof Expressions.ClassName)) {
|
|
250
|
+
// inline declarations, dereferences, table expressions, offsets and lengths
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return type;
|
|
255
|
+
}
|
|
159
256
|
sourceType(source, scope) {
|
|
160
257
|
let context;
|
|
161
258
|
// boolc( <condition> ) is not a MethodCallChain, xsdbool( ) has the same shape but is not reported
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SequentialReadSorted = exports.SequentialReadSortedConf = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
39
|
+
const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
40
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
41
|
+
const issue_1 = require("../issue");
|
|
42
|
+
const _irule_1 = require("./_irule");
|
|
43
|
+
const syntax_1 = require("../abap/5_syntax/syntax");
|
|
44
|
+
const _key_compare_1 = require("../abap/5_syntax/_key_compare");
|
|
45
|
+
const _abap_object_1 = require("../objects/_abap_object");
|
|
46
|
+
const basic_1 = require("../abap/types/basic");
|
|
47
|
+
const nodes_1 = require("../abap/nodes");
|
|
48
|
+
const _typed_identifier_1 = require("../abap/types/_typed_identifier");
|
|
49
|
+
const tokens_1 = require("../abap/1_lexer/tokens");
|
|
50
|
+
const severity_1 = require("../severity");
|
|
51
|
+
class SequentialReadSortedConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
54
|
+
this.severity = severity_1.Severity.Warning;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.SequentialReadSortedConf = SequentialReadSortedConf;
|
|
58
|
+
class SequentialReadSorted {
|
|
59
|
+
constructor() {
|
|
60
|
+
this.conf = new SequentialReadSortedConf();
|
|
61
|
+
}
|
|
62
|
+
getMetadata() {
|
|
63
|
+
return {
|
|
64
|
+
key: "sequential_read_sorted",
|
|
65
|
+
title: "Sequential read on a sorted table",
|
|
66
|
+
shortDescription: `A WHERE condition or a free key on a sorted table that does not use the primary key`,
|
|
67
|
+
extendedInformation: `A sorted table is read with a binary search only when the condition fixes an initial part of
|
|
68
|
+
its key. When the first key component is not compared with = or EQ (or IS INITIAL) in a part of the condition joined
|
|
69
|
+
by AND, every line is read, like on a standard table. The SAP check "Low Performance Operations on Internal Tables"
|
|
70
|
+
reports this as "Possible sequential read on a sorted table".
|
|
71
|
+
|
|
72
|
+
Checked: LOOP AT ... WHERE, DELETE ... WHERE, MODIFY ... WHERE, READ TABLE ... WITH KEY and table expressions
|
|
73
|
+
itab[ comp = ... ], on a table whose type is statically known as SORTED with explicit key components, using the
|
|
74
|
+
primary key.
|
|
75
|
+
|
|
76
|
+
Not checked: standard, hashed, generic and unknown table types, tables with a default key, a dynamic WHERE or
|
|
77
|
+
dynamic components, WITH TABLE KEY, a named key (USING KEY, KEY ... COMPONENTS) other than primary_key,
|
|
78
|
+
READ TABLE ... BINARY SEARCH and access by index, including LOOP AT and DELETE with FROM or TO.
|
|
79
|
+
|
|
80
|
+
Fix: compare the first key component with =, change the key or the table type, or add a secondary key.
|
|
81
|
+
If the sequential read is intended, add the pseudo comment "#EC CI_SORTSEQ to the statement.`,
|
|
82
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Performance],
|
|
83
|
+
pseudoComment: "EC CI_SORTSEQ",
|
|
84
|
+
badExample: `DATA lt_nodes TYPE SORTED TABLE OF ty_node WITH UNIQUE KEY path name.
|
|
85
|
+
LOOP AT lt_nodes INTO ls_node WHERE name = lv_name.
|
|
86
|
+
ENDLOOP.
|
|
87
|
+
DELETE lt_nodes WHERE path CP lv_pattern.`,
|
|
88
|
+
goodExample: `DATA lt_nodes TYPE SORTED TABLE OF ty_node WITH UNIQUE KEY path name.
|
|
89
|
+
LOOP AT lt_nodes INTO ls_node WHERE path = lv_path AND name = lv_name.
|
|
90
|
+
ENDLOOP.
|
|
91
|
+
DELETE lt_nodes WHERE path CP lv_pattern. "#EC CI_SORTSEQ`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
getConfig() {
|
|
95
|
+
return this.conf;
|
|
96
|
+
}
|
|
97
|
+
initialize(reg) {
|
|
98
|
+
this.reg = reg;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
setConfig(conf) {
|
|
102
|
+
this.conf = conf;
|
|
103
|
+
}
|
|
104
|
+
run(obj) {
|
|
105
|
+
if (!(obj instanceof _abap_object_1.ABAPObject) || obj.getType() === "INTF") {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const issues = [];
|
|
109
|
+
let spaghetti = undefined;
|
|
110
|
+
for (const file of obj.getABAPFiles()) {
|
|
111
|
+
const statements = file.getStatements();
|
|
112
|
+
const pseudoRows = this.findPseudoCommentRows(statements);
|
|
113
|
+
for (const statement of statements) {
|
|
114
|
+
const get = statement.get();
|
|
115
|
+
if (get instanceof _statement_1.Comment) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const isWhere = get instanceof Statements.Loop
|
|
119
|
+
|| get instanceof Statements.DeleteInternal
|
|
120
|
+
|| get instanceof Statements.ModifyInternal;
|
|
121
|
+
const isRead = get instanceof Statements.ReadTable;
|
|
122
|
+
if (isWhere === false
|
|
123
|
+
&& isRead === false
|
|
124
|
+
&& statement.findFirstExpression(Expressions.TableExpression) === undefined) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (this.hasPseudoComment(statement, pseudoRows)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (spaghetti === undefined) {
|
|
131
|
+
spaghetti = new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti;
|
|
132
|
+
}
|
|
133
|
+
if (isWhere === true) {
|
|
134
|
+
this.checkWhere(statement, spaghetti, file, issues);
|
|
135
|
+
}
|
|
136
|
+
else if (isRead === true) {
|
|
137
|
+
this.checkReadTable(statement, spaghetti, file, issues);
|
|
138
|
+
}
|
|
139
|
+
this.checkTableExpressions(statement, statement, spaghetti, file, issues);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return issues;
|
|
143
|
+
}
|
|
144
|
+
////////////////
|
|
145
|
+
findPseudoCommentRows(statements) {
|
|
146
|
+
const rows = new Set();
|
|
147
|
+
for (const s of statements) {
|
|
148
|
+
if (s.get() instanceof _statement_1.Comment && s.concatTokens().toUpperCase().includes(this.getMetadata().pseudoComment + "")) {
|
|
149
|
+
rows.add(s.getStart().getRow());
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return rows;
|
|
153
|
+
}
|
|
154
|
+
/** the pseudo comment is accepted on any row of the statement */
|
|
155
|
+
hasPseudoComment(statement, pseudoRows) {
|
|
156
|
+
for (let row = statement.getStart().getRow(); row <= statement.getEnd().getRow(); row++) {
|
|
157
|
+
if (pseudoRows.has(row)) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
/** LOOP AT, DELETE and MODIFY with a static WHERE condition */
|
|
164
|
+
checkWhere(statement, spaghetti, file, issues) {
|
|
165
|
+
var _a;
|
|
166
|
+
const cond = statement.findDirectExpression(Expressions.ComponentCond);
|
|
167
|
+
if (cond === undefined || this.usesPrimaryKey(statement) === false) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
let table;
|
|
171
|
+
if (statement.get() instanceof Statements.Loop) {
|
|
172
|
+
table = (_a = statement.findDirectExpression(Expressions.LoopSource)) === null || _a === void 0 ? void 0 : _a.getFirstChild();
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
table = statement.findDirectExpression(Expressions.Target);
|
|
176
|
+
}
|
|
177
|
+
if (table === undefined) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (!(statement.get() instanceof Statements.ModifyInternal)
|
|
181
|
+
&& (statement.findDirectTokenByText("FROM") !== undefined || statement.findDirectTokenByText("TO") !== undefined)) {
|
|
182
|
+
// an index range
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const first = this.firstKeyComponent(this.findType(table, spaghetti, file));
|
|
186
|
+
if (first !== undefined && (0, _key_compare_1.hasKeyCompare)(cond, first) === false) {
|
|
187
|
+
this.report(statement, table.concatTokens(), first, file, issues);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
checkReadTable(statement, spaghetti, file, issues) {
|
|
191
|
+
var _a;
|
|
192
|
+
if (statement.findTokenSequencePosition("WITH", "KEY") === undefined
|
|
193
|
+
|| statement.findDirectTokenByText("COMPONENTS") !== undefined
|
|
194
|
+
|| statement.findDirectTokenByText("BINARY") !== undefined) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const compare = statement.findDirectExpression(Expressions.ComponentCompareSimple);
|
|
198
|
+
const table = (_a = statement.findDirectExpression(Expressions.SimpleSource2)) !== null && _a !== void 0 ? _a : statement.findDirectExpression(Expressions.Source);
|
|
199
|
+
if (compare === undefined || table === undefined) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const first = this.firstKeyComponent(this.findType(table, spaghetti, file));
|
|
203
|
+
if (first !== undefined && this.hasFreeKeyComponent(compare, first) === false) {
|
|
204
|
+
this.report(statement, table.concatTokens(), first, file, issues);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** table expressions with a free key, itab[ comp = ... ], anywhere in the statement */
|
|
208
|
+
checkTableExpressions(node, statement, spaghetti, file, issues) {
|
|
209
|
+
var _a;
|
|
210
|
+
const children = node.getChildren();
|
|
211
|
+
for (let i = 0; i < children.length; i++) {
|
|
212
|
+
const child = children[i];
|
|
213
|
+
if (child instanceof nodes_1.TokenNode) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (child.get() instanceof Expressions.TableExpression
|
|
217
|
+
&& child instanceof nodes_1.ExpressionNode
|
|
218
|
+
&& (node.get() instanceof Expressions.FieldChain || node.get() instanceof Expressions.Target)
|
|
219
|
+
&& ((_a = child.getChildren()[1]) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.ComponentChainSimple) {
|
|
220
|
+
// a free key, not an index and not a named key: KEY name [COMPONENTS]
|
|
221
|
+
const first = this.firstKeyComponent(this.findChainType(children.slice(0, i), spaghetti, file));
|
|
222
|
+
if (first !== undefined && this.hasFreeKeyComponent(child, first) === false) {
|
|
223
|
+
const name = children.slice(0, i).map(c => c.concatTokens()).join("");
|
|
224
|
+
this.report(statement, name, first, file, issues);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
this.checkTableExpressions(child, statement, spaghetti, file, issues);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
report(statement, name, first, file, issues) {
|
|
231
|
+
const message = `Sequential read on sorted table ${name}, the first key component ${first} is not compared with =, ` +
|
|
232
|
+
`add it to the condition or "#EC CI_SORTSEQ`;
|
|
233
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
|
|
234
|
+
}
|
|
235
|
+
/** false if USING KEY names a key other than the primary key, or a dynamic one */
|
|
236
|
+
usesPrimaryKey(statement) {
|
|
237
|
+
if (statement.findDirectTokenByText("USING") === undefined) {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
const keyName = statement.findExpressionAfterToken("KEY");
|
|
241
|
+
return (keyName === null || keyName === void 0 ? void 0 : keyName.get()) instanceof Expressions.SimpleName && keyName.concatTokens().toUpperCase() === "PRIMARY_KEY";
|
|
242
|
+
}
|
|
243
|
+
/** true if a free key, ComponentCompareSimple or the fields of a TableExpression, specifies the component;
|
|
244
|
+
* also true when a component is dynamic, as it cannot be decided */
|
|
245
|
+
hasFreeKeyComponent(node, component) {
|
|
246
|
+
if (node.findDirectExpression(Expressions.Dynamic) !== undefined) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
return node.findDirectExpressions(Expressions.ComponentChainSimple)
|
|
250
|
+
.some(c => c.concatTokens().toUpperCase().replace(/\s+/g, "") === component);
|
|
251
|
+
}
|
|
252
|
+
/** The first component of the primary key of a sorted table with explicit key components, else undefined */
|
|
253
|
+
firstKeyComponent(type) {
|
|
254
|
+
var _a, _b;
|
|
255
|
+
if (!(type instanceof basic_1.TableType)
|
|
256
|
+
|| type.getAccessType() !== basic_1.TableAccessType.sorted
|
|
257
|
+
|| type.getOptions().keyType !== basic_1.TableKeyType.user
|
|
258
|
+
|| type.isGeneric()) {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
return (_b = (_a = type.getOptions().primaryKey) === null || _a === void 0 ? void 0 : _a.keyFields[0]) === null || _b === void 0 ? void 0 : _b.toUpperCase();
|
|
262
|
+
}
|
|
263
|
+
findType(node, spaghetti, file) {
|
|
264
|
+
if (!(node.get() instanceof Expressions.Target)) {
|
|
265
|
+
const chain = node.getChildren().length === 1 ? node.findDirectExpression(Expressions.FieldChain) : undefined;
|
|
266
|
+
if (chain === undefined) {
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
node = chain;
|
|
270
|
+
}
|
|
271
|
+
return this.findChainType(node.getChildren(), spaghetti, file);
|
|
272
|
+
}
|
|
273
|
+
/** The type of a chain of names, components, attributes, dereferences and table expressions, else undefined */
|
|
274
|
+
findChainType(children, spaghetti, file) {
|
|
275
|
+
var _a;
|
|
276
|
+
let type = undefined;
|
|
277
|
+
for (const child of children) {
|
|
278
|
+
const get = child.get();
|
|
279
|
+
if (get instanceof Expressions.SourceField
|
|
280
|
+
|| get instanceof Expressions.SourceFieldSymbol
|
|
281
|
+
|| get instanceof Expressions.TargetField
|
|
282
|
+
|| get instanceof Expressions.TargetFieldSymbol
|
|
283
|
+
|| get instanceof Expressions.AttributeName) {
|
|
284
|
+
type = (_a = this.findReference(child.getFirstToken().getStart(), spaghetti, file)) === null || _a === void 0 ? void 0 : _a.getType();
|
|
285
|
+
}
|
|
286
|
+
else if (get instanceof Expressions.ComponentName) {
|
|
287
|
+
type = type instanceof basic_1.StructureType ? type.getComponentByName(child.concatTokens()) : undefined;
|
|
288
|
+
}
|
|
289
|
+
else if (get instanceof Expressions.Dereference) {
|
|
290
|
+
type = type instanceof basic_1.DataReference ? type.getType() : undefined;
|
|
291
|
+
}
|
|
292
|
+
else if (get instanceof Expressions.TableExpression) {
|
|
293
|
+
type = type instanceof basic_1.TableType ? type.getRowType() : undefined;
|
|
294
|
+
}
|
|
295
|
+
else if (get instanceof Expressions.ClassName || get instanceof tokens_1.StaticArrow) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
else if (!(get instanceof tokens_1.Dash) && !(get instanceof tokens_1.InstanceArrow)) {
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
if (type === undefined) {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return type;
|
|
306
|
+
}
|
|
307
|
+
findReference(start, spaghetti, file) {
|
|
308
|
+
const scope = spaghetti.lookupPosition(start, file.getFilename());
|
|
309
|
+
for (const r of (scope === null || scope === void 0 ? void 0 : scope.getData().references) || []) {
|
|
310
|
+
if (r.position.getStart().equals(start) && r.resolved instanceof _typed_identifier_1.TypedIdentifier) {
|
|
311
|
+
return r.resolved;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
exports.SequentialReadSorted = SequentialReadSorted;
|
|
318
|
+
//# sourceMappingURL=sequential_read_sorted.js.map
|
|
@@ -41,6 +41,7 @@ const _abap_object_1 = require("../objects/_abap_object");
|
|
|
41
41
|
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
42
42
|
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
43
43
|
const severity_1 = require("../severity");
|
|
44
|
+
const xml_utils_1 = require("../xml_utils");
|
|
44
45
|
const ABAPGIT_ATTRIBUTES = [
|
|
45
46
|
["version", /<abapGit\b[^>]*\bversion="([^"]+)"/],
|
|
46
47
|
["serializer_version", /<abapGit\b[^>]*\bserializer_version="([^"]+)"/],
|
|
@@ -73,6 +74,7 @@ class XMLConsistency {
|
|
|
73
74
|
* QUAN fields in TABL objects have reference table and field values
|
|
74
75
|
* Transparent TABL objects have delivery class and size category set
|
|
75
76
|
* TABL fields with a built-in type carry the INTTYPE abapGit serializes for it, for the confirmed pairs
|
|
77
|
+
* Documentation lines(TDLINE) in CLAS and INTF objects are max 72 characters, longer lines are cut by the system
|
|
76
78
|
* Lock parameter names in ENQU objects are max 16 characters
|
|
77
79
|
* DEVC objects are serialized as package.devc.xml
|
|
78
80
|
* Texts and translations do not exceed maximum allowed length.`,
|
|
@@ -160,6 +162,27 @@ class XMLConsistency {
|
|
|
160
162
|
issues.push(issue_1.Issue.atRow(file, 1, "Class matching XML name not found in ABAP file", this.getMetadata().key, this.conf.severity));
|
|
161
163
|
}
|
|
162
164
|
issues.push(...this.checkClearedFields(obj, file, "VSEOCLASS", XMLConsistency.clearedClassFields));
|
|
165
|
+
issues.push(...this.checkDocumentationLines(obj, file));
|
|
166
|
+
return issues;
|
|
167
|
+
}
|
|
168
|
+
// the documentation editor stores lines of max 72 characters, longer TDLINEs are cut when deserialized
|
|
169
|
+
checkDocumentationLines(obj, file) {
|
|
170
|
+
const maxLength = 72;
|
|
171
|
+
const issues = [];
|
|
172
|
+
const xml = obj.getXML();
|
|
173
|
+
if (xml === undefined) {
|
|
174
|
+
return issues;
|
|
175
|
+
}
|
|
176
|
+
const regex = /<TDLINE>([^<]*)<\/TDLINE>/g;
|
|
177
|
+
let match;
|
|
178
|
+
while ((match = regex.exec(xml)) !== null) {
|
|
179
|
+
const text = (0, xml_utils_1.unescape)(match[1]);
|
|
180
|
+
if (text.length > maxLength) {
|
|
181
|
+
const row = xml.substring(0, match.index).split("\n").length;
|
|
182
|
+
const message = `Documentation line exceeds maximum length of ${maxLength} characters (actual: ${text.length}), "${text}"`;
|
|
183
|
+
issues.push(issue_1.Issue.atRow(file, row, message, this.getMetadata().key, this.conf.textAndTranslationLengthSeverity));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
163
186
|
return issues;
|
|
164
187
|
}
|
|
165
188
|
checkClearedFields(obj, file, structure, fields) {
|
|
@@ -221,6 +244,7 @@ class XMLConsistency {
|
|
|
221
244
|
issues.push(issue_1.Issue.atRow(file, 1, "Interface matching XML name not found in ABAP file", this.getMetadata().key, this.conf.severity));
|
|
222
245
|
}
|
|
223
246
|
issues.push(...this.checkClearedFields(obj, file, "VSEOINTERF", XMLConsistency.clearedInterfaceFields));
|
|
247
|
+
issues.push(...this.checkDocumentationLines(obj, file));
|
|
224
248
|
return issues;
|
|
225
249
|
}
|
|
226
250
|
checkTextLength(file, fieldName, text, maxLength, lang) {
|