@abaplint/core 2.80.10 → 2.81.3
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 +37 -16
- package/build/src/abap/2_statements/expressions/sql_arithmetics.js +2 -1
- package/build/src/abap/2_statements/expressions/sql_function.js +11 -5
- package/build/src/abap/2_statements/statements/move.js +3 -2
- package/build/src/abap/3_structures/structures/normal.js +1 -1
- package/build/src/abap/5_syntax/_builtin.js +817 -80
- package/build/src/abap/5_syntax/_current_scope.js +26 -0
- package/build/src/abap/5_syntax/_object_oriented.js +13 -9
- package/build/src/abap/5_syntax/_reference.js +16 -16
- package/build/src/abap/5_syntax/_scope_type.js +1 -0
- package/build/src/abap/5_syntax/basic_types.js +5 -1
- package/build/src/abap/5_syntax/spaghetti_scope.js +13 -0
- package/build/src/abap/5_syntax/statements/class_implementation.js +6 -5
- package/build/src/abap/5_syntax/statements/method_implementation.js +5 -3
- package/build/src/abap/5_syntax/statements/read_table.js +4 -1
- package/build/src/abap/5_syntax/syntax.js +6 -1
- package/build/src/abap/nodes/expression_node.js +2 -2
- package/build/src/abap/nodes/statement_node.js +1 -1
- package/build/src/abap/types/class_definition.js +1 -2
- package/build/src/edit_helper.js +32 -9
- package/build/src/lsp/_lookup.js +46 -25
- package/build/src/registry.js +1 -1
- package/build/src/rules/index.js +2 -0
- package/build/src/rules/no_chained_assignment.js +52 -0
- package/build/src/rules/parser_missing_space.js +2 -1
- package/build/src/rules/prefer_inline.js +3 -2
- package/build/src/rules/unnecessary_chaining.js +58 -0
- package/build/src/rules/unreachable_code.js +4 -0
- package/package.json +6 -5
|
@@ -54,6 +54,25 @@ class CurrentScope {
|
|
|
54
54
|
}
|
|
55
55
|
this.current.getData().types[upper] = type;
|
|
56
56
|
}
|
|
57
|
+
addExtraLikeType(type) {
|
|
58
|
+
if (type === undefined) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.addExtraLikeTypeNamed(type.getName(), type);
|
|
62
|
+
}
|
|
63
|
+
addExtraLikeTypeNamed(name, type) {
|
|
64
|
+
if (type === undefined) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (this.current === undefined) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const upper = name.toUpperCase();
|
|
71
|
+
if (this.current.getData().extraLikeTypes[upper] !== undefined) {
|
|
72
|
+
throw new Error(`Type name "${name}" already defined`);
|
|
73
|
+
}
|
|
74
|
+
this.current.getData().extraLikeTypes[upper] = type;
|
|
75
|
+
}
|
|
57
76
|
addClassDefinition(c) {
|
|
58
77
|
var _a;
|
|
59
78
|
(_a = this.current) === null || _a === void 0 ? void 0 : _a.getData().cdefs.push(c);
|
|
@@ -231,6 +250,13 @@ class CurrentScope {
|
|
|
231
250
|
}
|
|
232
251
|
return (_a = this.current) === null || _a === void 0 ? void 0 : _a.findType(name);
|
|
233
252
|
}
|
|
253
|
+
findExtraLikeType(name) {
|
|
254
|
+
var _a;
|
|
255
|
+
if (name === undefined) {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
return (_a = this.current) === null || _a === void 0 ? void 0 : _a.findExtraLikeType(name);
|
|
259
|
+
}
|
|
234
260
|
findVariable(name) {
|
|
235
261
|
var _a;
|
|
236
262
|
if (name === undefined) {
|
|
@@ -9,14 +9,6 @@ class ObjectOriented {
|
|
|
9
9
|
constructor(scope) {
|
|
10
10
|
this.scope = scope;
|
|
11
11
|
}
|
|
12
|
-
// returns list of interfaces implemented
|
|
13
|
-
fromInterfaces(classDefinition, skip) {
|
|
14
|
-
const ignore = [];
|
|
15
|
-
for (const i of classDefinition.getImplementing()) {
|
|
16
|
-
ignore.push(...this.fromInterfaceByName(i.name, ignore.concat(skip || [])));
|
|
17
|
-
}
|
|
18
|
-
return ignore;
|
|
19
|
-
}
|
|
20
12
|
fromInterfaceByName(name, ignore) {
|
|
21
13
|
const idef = this.scope.findInterfaceDefinition(name);
|
|
22
14
|
if (idef === undefined || ignore.includes(name.toUpperCase())) {
|
|
@@ -279,8 +271,12 @@ class ObjectOriented {
|
|
|
279
271
|
}
|
|
280
272
|
return csup;
|
|
281
273
|
}
|
|
274
|
+
fromSuperClassesAndInterfaces(child) {
|
|
275
|
+
const implemented = this.fromSuperClasses(child);
|
|
276
|
+
this.fromInterfaces(child, implemented);
|
|
277
|
+
}
|
|
282
278
|
// returns list of interfaces implemented
|
|
283
|
-
|
|
279
|
+
fromSuperClasses(child) {
|
|
284
280
|
let sup = child.getSuperClass();
|
|
285
281
|
const ignore = [];
|
|
286
282
|
while (sup !== undefined) {
|
|
@@ -306,6 +302,14 @@ class ObjectOriented {
|
|
|
306
302
|
}
|
|
307
303
|
return ignore;
|
|
308
304
|
}
|
|
305
|
+
// returns list of interfaces implemented
|
|
306
|
+
fromInterfaces(classDefinition, skip) {
|
|
307
|
+
const ignore = [];
|
|
308
|
+
for (const i of classDefinition.getImplementing()) {
|
|
309
|
+
ignore.push(...this.fromInterfaceByName(i.name, ignore.concat(skip || [])));
|
|
310
|
+
}
|
|
311
|
+
return ignore;
|
|
312
|
+
}
|
|
309
313
|
}
|
|
310
314
|
exports.ObjectOriented = ObjectOriented;
|
|
311
315
|
//# sourceMappingURL=_object_oriented.js.map
|
|
@@ -4,21 +4,21 @@ exports.ReferenceType = void 0;
|
|
|
4
4
|
var ReferenceType;
|
|
5
5
|
(function (ReferenceType) {
|
|
6
6
|
/** for classes and interface references */
|
|
7
|
-
ReferenceType["ObjectOrientedReference"] = "
|
|
8
|
-
ReferenceType["ObjectOrientedVoidReference"] = "
|
|
9
|
-
ReferenceType["ObjectOrientedUnknownReference"] = "
|
|
10
|
-
ReferenceType["TableReference"] = "
|
|
11
|
-
ReferenceType["TableVoidReference"] = "
|
|
12
|
-
ReferenceType["MethodReference"] = "
|
|
13
|
-
ReferenceType["BuiltinMethodReference"] = "
|
|
14
|
-
ReferenceType["MethodImplementationReference"] = "
|
|
15
|
-
ReferenceType["TypeReference"] = "
|
|
16
|
-
ReferenceType["BuiltinTypeReference"] = "
|
|
17
|
-
ReferenceType["VoidType"] = "
|
|
18
|
-
ReferenceType["InferredType"] = "
|
|
19
|
-
ReferenceType["FormReference"] = "
|
|
20
|
-
// FormVoidReference = "
|
|
21
|
-
ReferenceType["DataReadReference"] = "
|
|
22
|
-
ReferenceType["DataWriteReference"] = "
|
|
7
|
+
ReferenceType["ObjectOrientedReference"] = "Object";
|
|
8
|
+
ReferenceType["ObjectOrientedVoidReference"] = "Object (Void)";
|
|
9
|
+
ReferenceType["ObjectOrientedUnknownReference"] = "Object (Unknown)";
|
|
10
|
+
ReferenceType["TableReference"] = "Table";
|
|
11
|
+
ReferenceType["TableVoidReference"] = "Table (Void)";
|
|
12
|
+
ReferenceType["MethodReference"] = "Method";
|
|
13
|
+
ReferenceType["BuiltinMethodReference"] = "Builtin Method";
|
|
14
|
+
ReferenceType["MethodImplementationReference"] = "Method Implementation";
|
|
15
|
+
ReferenceType["TypeReference"] = "Type";
|
|
16
|
+
ReferenceType["BuiltinTypeReference"] = "Builtin Type";
|
|
17
|
+
ReferenceType["VoidType"] = "Type (Void)";
|
|
18
|
+
ReferenceType["InferredType"] = "Inferred Type";
|
|
19
|
+
ReferenceType["FormReference"] = "Form";
|
|
20
|
+
// FormVoidReference = "Form (void)",
|
|
21
|
+
ReferenceType["DataReadReference"] = "Read From";
|
|
22
|
+
ReferenceType["DataWriteReference"] = "Write To";
|
|
23
23
|
})(ReferenceType = exports.ReferenceType || (exports.ReferenceType = {}));
|
|
24
24
|
//# sourceMappingURL=_reference.js.map
|
|
@@ -14,6 +14,7 @@ var ScopeType;
|
|
|
14
14
|
ScopeType["Form"] = "form";
|
|
15
15
|
ScopeType["FunctionModule"] = "function";
|
|
16
16
|
ScopeType["Method"] = "method";
|
|
17
|
+
ScopeType["MethodInstance"] = "method_instance";
|
|
17
18
|
ScopeType["For"] = "for";
|
|
18
19
|
ScopeType["OpenSQL"] = "open_sql";
|
|
19
20
|
})(ScopeType = exports.ScopeType || (exports.ScopeType = {}));
|
|
@@ -79,8 +79,12 @@ class BasicTypes {
|
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
81
|
const name = children.shift().getFirstToken().getStr();
|
|
82
|
-
|
|
82
|
+
let found = this.scope.findVariable(name);
|
|
83
83
|
type = found === null || found === void 0 ? void 0 : found.getType();
|
|
84
|
+
if (found === undefined) {
|
|
85
|
+
found = this.scope.findExtraLikeType(name);
|
|
86
|
+
type = found === null || found === void 0 ? void 0 : found.getType();
|
|
87
|
+
}
|
|
84
88
|
if (found) {
|
|
85
89
|
this.scope.addReference(chain === null || chain === void 0 ? void 0 : chain.getFirstToken(), found, _reference_1.ReferenceType.TypeReference, this.filename);
|
|
86
90
|
}
|
|
@@ -12,6 +12,7 @@ class ScopeData {
|
|
|
12
12
|
idefs: [],
|
|
13
13
|
forms: [],
|
|
14
14
|
types: {},
|
|
15
|
+
extraLikeTypes: {},
|
|
15
16
|
deferred: [],
|
|
16
17
|
references: [],
|
|
17
18
|
};
|
|
@@ -126,6 +127,18 @@ class SpaghettiScopeNode extends ScopeData {
|
|
|
126
127
|
}
|
|
127
128
|
return undefined;
|
|
128
129
|
}
|
|
130
|
+
findExtraLikeType(name) {
|
|
131
|
+
let search = this;
|
|
132
|
+
const upper = name.toUpperCase();
|
|
133
|
+
while (search !== undefined) {
|
|
134
|
+
const data = search.getData();
|
|
135
|
+
if (data.extraLikeTypes[upper]) {
|
|
136
|
+
return data.extraLikeTypes[upper];
|
|
137
|
+
}
|
|
138
|
+
search = search.getParent();
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
129
142
|
findVariable(name) {
|
|
130
143
|
let search = this;
|
|
131
144
|
const upper = name.toUpperCase();
|
|
@@ -17,7 +17,6 @@ class ClassImplementation {
|
|
|
17
17
|
if (classDefinition === undefined) {
|
|
18
18
|
throw new Error("Class definition for \"" + className + "\" not found");
|
|
19
19
|
}
|
|
20
|
-
const classAttributes = classDefinition.getAttributes();
|
|
21
20
|
for (const t of classDefinition.getTypeDefinitions().getAll()) {
|
|
22
21
|
scope.addType(t.type);
|
|
23
22
|
}
|
|
@@ -27,11 +26,13 @@ class ClassImplementation {
|
|
|
27
26
|
}
|
|
28
27
|
scope.addIdentifier(new _typed_identifier_1.TypedIdentifier(new tokens_1.Identifier(new position_1.Position(1, 1), "me"), _builtin_1.BuiltIn.filename, new basic_1.ObjectReferenceType(classDefinition)));
|
|
29
28
|
helper.addAliasedAttributes(classDefinition); // todo, this is not correct, take care of instance vs static
|
|
29
|
+
const classAttributes = classDefinition.getAttributes();
|
|
30
30
|
scope.addList(classAttributes.getConstants());
|
|
31
|
-
scope.addList(classAttributes.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
scope.addList(classAttributes.getStatic());
|
|
32
|
+
for (const i of classAttributes.getInstance()) {
|
|
33
|
+
scope.addExtraLikeType(i);
|
|
34
|
+
}
|
|
35
|
+
helper.fromSuperClassesAndInterfaces(classDefinition);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
exports.ClassImplementation = ClassImplementation;
|
|
@@ -11,17 +11,19 @@ class MethodImplementation {
|
|
|
11
11
|
const className = scope.getName();
|
|
12
12
|
const methodToken = node.findFirstExpression(Expressions.MethodName).getFirstToken();
|
|
13
13
|
const methodName = methodToken === null || methodToken === void 0 ? void 0 : methodToken.getStr();
|
|
14
|
-
scope.push(_scope_type_1.ScopeType.Method, methodName, node.getFirstToken().getStart(), filename);
|
|
15
14
|
const classDefinition = scope.findClassDefinition(className);
|
|
16
15
|
if (classDefinition === undefined) {
|
|
17
|
-
scope.pop(node.getLastToken().getEnd());
|
|
18
16
|
throw new Error("Class definition for \"" + className + "\" not found");
|
|
19
17
|
}
|
|
20
18
|
const { method: methodDefinition } = helper.searchMethodName(classDefinition, methodName);
|
|
21
19
|
if (methodDefinition === undefined) {
|
|
22
|
-
scope.pop(node.getLastToken().getEnd());
|
|
23
20
|
throw new Error("Method definition \"" + methodName + "\" not found");
|
|
24
21
|
}
|
|
22
|
+
if (methodDefinition.isStatic() === false) {
|
|
23
|
+
scope.push(_scope_type_1.ScopeType.MethodInstance, methodName, node.getFirstToken().getStart(), filename);
|
|
24
|
+
scope.addList(classDefinition.getAttributes().getInstance());
|
|
25
|
+
}
|
|
26
|
+
scope.push(_scope_type_1.ScopeType.Method, methodName, node.getFirstToken().getStart(), filename);
|
|
25
27
|
scope.addReference(methodToken, methodDefinition, _reference_1.ReferenceType.MethodImplementationReference, filename);
|
|
26
28
|
scope.addList(methodDefinition.getParameters().getAll());
|
|
27
29
|
for (const i of helper.findInterfaces(classDefinition)) {
|
|
@@ -11,6 +11,7 @@ const component_compare_simple_1 = require("../expressions/component_compare_sim
|
|
|
11
11
|
const _type_utils_1 = require("../_type_utils");
|
|
12
12
|
class ReadTable {
|
|
13
13
|
runSyntax(node, scope, filename) {
|
|
14
|
+
const concat = node.concatTokens().toUpperCase();
|
|
14
15
|
const sources = node.findDirectExpressions(Expressions.Source);
|
|
15
16
|
let firstSource = node.findDirectExpression(Expressions.SimpleSource2);
|
|
16
17
|
if (firstSource === undefined) {
|
|
@@ -53,6 +54,9 @@ class ReadTable {
|
|
|
53
54
|
}
|
|
54
55
|
const target = node.findDirectExpression(Expressions.ReadTableTarget);
|
|
55
56
|
if (target) {
|
|
57
|
+
if (concat.includes(" REFERENCE INTO ")) {
|
|
58
|
+
rowType = new basic_1.DataReference(rowType);
|
|
59
|
+
}
|
|
56
60
|
const inline = target.findFirstExpression(Expressions.InlineData);
|
|
57
61
|
if (inline) {
|
|
58
62
|
new inline_data_1.InlineData().runSyntax(inline, scope, filename, rowType);
|
|
@@ -76,7 +80,6 @@ class ReadTable {
|
|
|
76
80
|
return;
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
|
-
const concat = node.concatTokens().toUpperCase();
|
|
80
83
|
if (target === undefined && concat.includes(" TRANSPORTING NO FIELDS ") === false) {
|
|
81
84
|
// if sourceType is void, assume its with header
|
|
82
85
|
if (sourceType instanceof basic_1.TableType && sourceType.isWithHeader() === false) {
|
|
@@ -412,11 +412,16 @@ class SyntaxLogic {
|
|
|
412
412
|
}
|
|
413
413
|
else if (s instanceof Statements.EndForm
|
|
414
414
|
|| s instanceof Statements.EndFunction
|
|
415
|
-
|| s instanceof Statements.EndMethod
|
|
416
415
|
|| s instanceof Statements.EndClass
|
|
417
416
|
|| s instanceof Statements.EndInterface) {
|
|
418
417
|
this.scope.pop(node.getLastToken().getEnd());
|
|
419
418
|
}
|
|
419
|
+
else if (s instanceof Statements.EndMethod) {
|
|
420
|
+
this.scope.pop(node.getLastToken().getEnd());
|
|
421
|
+
if (this.scope.getType() === _scope_type_1.ScopeType.MethodInstance) {
|
|
422
|
+
this.scope.pop(node.getLastToken().getEnd());
|
|
423
|
+
}
|
|
424
|
+
}
|
|
420
425
|
}
|
|
421
426
|
}
|
|
422
427
|
exports.SyntaxLogic = SyntaxLogic;
|
|
@@ -189,7 +189,7 @@ class ExpressionNode extends _abstract_node_1.AbstractNode {
|
|
|
189
189
|
}
|
|
190
190
|
return ret;
|
|
191
191
|
}
|
|
192
|
-
findAllExpressionsMulti(type) {
|
|
192
|
+
findAllExpressionsMulti(type, recursive = false) {
|
|
193
193
|
const ret = [];
|
|
194
194
|
for (const child of this.getChildren()) {
|
|
195
195
|
if (child instanceof token_node_1.TokenNode) {
|
|
@@ -201,7 +201,7 @@ class ExpressionNode extends _abstract_node_1.AbstractNode {
|
|
|
201
201
|
ret.push(child);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
if (before === ret.length) {
|
|
204
|
+
if (before === ret.length || recursive === true) {
|
|
205
205
|
ret.push(...child.findAllExpressionsMulti(type));
|
|
206
206
|
}
|
|
207
207
|
}
|
|
@@ -211,7 +211,7 @@ class StatementNode extends _abstract_node_1.AbstractNode {
|
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
if (before === ret.length || recursive === true) {
|
|
214
|
-
ret.push(...child.findAllExpressionsMulti(type));
|
|
214
|
+
ret.push(...child.findAllExpressionsMulti(type, recursive));
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
return ret;
|
|
@@ -31,8 +31,7 @@ class ClassDefinition extends _identifier_1.Identifier {
|
|
|
31
31
|
this.friends = this.findFriends(def, filename, scope);
|
|
32
32
|
this.parse(filename, scope);
|
|
33
33
|
const helper = new _object_oriented_1.ObjectOriented(scope);
|
|
34
|
-
|
|
35
|
-
helper.fromInterfaces(this, implemented);
|
|
34
|
+
helper.fromSuperClassesAndInterfaces(this);
|
|
36
35
|
this.attributes = new class_attributes_1.Attributes(this.node, this.filename, scope);
|
|
37
36
|
this.types = this.attributes.getTypes();
|
|
38
37
|
this.methodDefs = new method_definitions_1.MethodDefinitions(this.node, this.filename, scope);
|
package/build/src/edit_helper.js
CHANGED
|
@@ -97,11 +97,12 @@ class EditHelper {
|
|
|
97
97
|
if (scolon === undefined) {
|
|
98
98
|
return EditHelper.deleteRange(file, statement.getFirstToken().getStart(), statement.getLastToken().getEnd());
|
|
99
99
|
}
|
|
100
|
-
// find statements part of chain
|
|
101
|
-
let chainCount = 0;
|
|
102
100
|
let setPrevious = true;
|
|
101
|
+
let setNext = true;
|
|
103
102
|
/** previous statement in the chain */
|
|
104
103
|
let previousStatement = undefined;
|
|
104
|
+
/** next statement in the chain */
|
|
105
|
+
let nextStatement = undefined;
|
|
105
106
|
for (const s of file.getStatements()) {
|
|
106
107
|
const colon = s.getColon();
|
|
107
108
|
if (colon === undefined) {
|
|
@@ -109,16 +110,22 @@ class EditHelper {
|
|
|
109
110
|
}
|
|
110
111
|
else if (s === statement) {
|
|
111
112
|
setPrevious = false;
|
|
113
|
+
setNext = true;
|
|
112
114
|
continue;
|
|
113
115
|
}
|
|
114
|
-
else if (
|
|
115
|
-
|
|
116
|
+
else if (setPrevious === true) {
|
|
117
|
+
if (scolon.getStart().equals(colon.getStart())) {
|
|
118
|
+
previousStatement = s;
|
|
119
|
+
}
|
|
116
120
|
}
|
|
117
|
-
if (
|
|
118
|
-
|
|
121
|
+
else if (setNext === true) {
|
|
122
|
+
if (scolon.getStart().equals(colon.getStart())) {
|
|
123
|
+
nextStatement = s;
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
119
126
|
}
|
|
120
127
|
}
|
|
121
|
-
if (
|
|
128
|
+
if (previousStatement === undefined && nextStatement === undefined) {
|
|
122
129
|
// the statement to be deleted is the only one in the chain
|
|
123
130
|
return EditHelper.deleteRange(file, statement.getFirstToken().getStart(), statement.getLastToken().getEnd());
|
|
124
131
|
}
|
|
@@ -130,14 +137,30 @@ class EditHelper {
|
|
|
130
137
|
break;
|
|
131
138
|
}
|
|
132
139
|
}
|
|
140
|
+
const colon = statement.getColon();
|
|
133
141
|
if (statement.getLastToken().getStr() === "." && previousStatement) {
|
|
142
|
+
// last statement in chain
|
|
134
143
|
const edit1 = EditHelper.replaceToken(file, previousStatement.getLastToken(), ".");
|
|
135
|
-
const edit2 = EditHelper.deleteRange(file,
|
|
144
|
+
const edit2 = EditHelper.deleteRange(file, previousStatement.getLastToken().getEnd(), statement.getLastToken().getEnd());
|
|
136
145
|
return EditHelper.merge(edit1, edit2);
|
|
137
146
|
}
|
|
147
|
+
else if (previousStatement === undefined && colon && nextStatement) {
|
|
148
|
+
// first statement in chain
|
|
149
|
+
return EditHelper.deleteRange(file, this.firstAfterColon(statement), this.firstAfterColon(nextStatement));
|
|
150
|
+
}
|
|
138
151
|
else {
|
|
139
|
-
|
|
152
|
+
// middle statement
|
|
153
|
+
return EditHelper.deleteRange(file, startDelete, this.firstAfterColon(nextStatement));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
static firstAfterColon(statement) {
|
|
157
|
+
const colon = statement.getColon().getStart();
|
|
158
|
+
for (const t of statement.getTokens()) {
|
|
159
|
+
if (t.getStart().isAfter(colon)) {
|
|
160
|
+
return t.getStart();
|
|
161
|
+
}
|
|
140
162
|
}
|
|
163
|
+
throw new Error("firstAfterColon, emtpy statement?");
|
|
141
164
|
}
|
|
142
165
|
static deleteToken(file, token) {
|
|
143
166
|
const filename = file.getFilename();
|
package/build/src/lsp/_lookup.js
CHANGED
|
@@ -28,36 +28,40 @@ class LSPLookup {
|
|
|
28
28
|
const clas = bottomScope.findClassDefinition(cursor.token.getStr());
|
|
29
29
|
if (clas && clas.getStart().equals(cursor.token.getStart())) {
|
|
30
30
|
const found = _lsp_utils_1.LSPUtils.identiferToLocation(clas);
|
|
31
|
-
return {
|
|
31
|
+
return {
|
|
32
|
+
hover: "Class Definition, " + cursor.token.getStr(),
|
|
32
33
|
definition: found,
|
|
33
34
|
definitionId: clas,
|
|
34
35
|
implementation: undefined,
|
|
35
|
-
scope: bottomScope
|
|
36
|
+
scope: bottomScope,
|
|
37
|
+
};
|
|
36
38
|
}
|
|
37
39
|
const intf = bottomScope.findInterfaceDefinition(cursor.token.getStr());
|
|
38
40
|
if (intf && intf.getStart().equals(cursor.token.getStart())) {
|
|
39
41
|
const found = _lsp_utils_1.LSPUtils.identiferToLocation(intf);
|
|
40
|
-
return {
|
|
42
|
+
return {
|
|
43
|
+
hover: "Interface Definition, " + cursor.token.getStr(),
|
|
41
44
|
definition: found,
|
|
42
45
|
definitionId: intf,
|
|
43
46
|
implementation: undefined,
|
|
44
|
-
scope: bottomScope
|
|
47
|
+
scope: bottomScope,
|
|
48
|
+
};
|
|
45
49
|
}
|
|
46
50
|
const type = bottomScope.findType(cursor.token.getStr());
|
|
47
51
|
if (type !== undefined && type.getStart().equals(cursor.token.getStart())) {
|
|
48
52
|
const found = _lsp_utils_1.LSPUtils.identiferToLocation(type);
|
|
49
|
-
const hover = "Type
|
|
53
|
+
const hover = "Type Definition, " + cursor.token.getStr() + "\n\n" + this.dumpType(type);
|
|
50
54
|
return { hover, definition: found, definitionId: type, scope: bottomScope };
|
|
51
55
|
}
|
|
52
56
|
const method = this.findMethodDefinition(cursor, bottomScope);
|
|
53
57
|
if (method !== undefined && method.getStart().equals(cursor.token.getStart())) {
|
|
54
58
|
const found = _lsp_utils_1.LSPUtils.identiferToLocation(method);
|
|
55
|
-
const hover = "Method
|
|
59
|
+
const hover = "Method Definition \"" + method.getName() + "\"";
|
|
56
60
|
return { hover, definition: found, definitionId: method, scope: bottomScope };
|
|
57
61
|
}
|
|
58
62
|
const variable = bottomScope.findVariable(cursor.token.getStr());
|
|
59
63
|
if (variable !== undefined && variable.getStart().equals(cursor.token.getStart())) {
|
|
60
|
-
const hover = "Variable
|
|
64
|
+
const hover = "Variable Definition\n\n" + this.dumpType(variable);
|
|
61
65
|
let location = undefined;
|
|
62
66
|
if (variable.getMeta().includes("built-in" /* BuiltIn */) === false) {
|
|
63
67
|
location = _lsp_utils_1.LSPUtils.identiferToLocation(variable);
|
|
@@ -103,23 +107,23 @@ class LSPLookup {
|
|
|
103
107
|
value = value + "\n\nMeta: " + variable.getMeta().join(", ");
|
|
104
108
|
}
|
|
105
109
|
if (variable.getType().containsVoid() === true) {
|
|
106
|
-
value = value + "\n\nContains
|
|
110
|
+
value = value + "\n\nContains Void types";
|
|
107
111
|
}
|
|
108
112
|
if (variable.getType().getQualifiedName()) {
|
|
109
|
-
value = value + "\n\nQualified
|
|
113
|
+
value = value + "\n\nQualified Type Name: ```" + variable.getType().getQualifiedName() + "```";
|
|
110
114
|
}
|
|
111
115
|
if (variable.getType().isGeneric() === true) {
|
|
112
|
-
value = value + "\n\nIs
|
|
116
|
+
value = value + "\n\nIs Generic Type";
|
|
113
117
|
}
|
|
114
118
|
return value;
|
|
115
119
|
}
|
|
116
120
|
static referenceHover(ref, scope, reg) {
|
|
117
|
-
var _a, _b, _c;
|
|
121
|
+
var _a, _b, _c, _d, _e;
|
|
118
122
|
let name = "";
|
|
119
123
|
if (ref.resolved) {
|
|
120
124
|
name = "```" + ref.resolved.getName() + "```";
|
|
121
125
|
}
|
|
122
|
-
let ret =
|
|
126
|
+
let ret = `${ref.referenceType} ${name}`;
|
|
123
127
|
if (ref.referenceType === _reference_1.ReferenceType.MethodReference && ((_a = ref.extra) === null || _a === void 0 ? void 0 : _a.ooName)) {
|
|
124
128
|
let cdef = scope.findClassDefinition(ref.extra.ooName);
|
|
125
129
|
if (cdef === undefined) {
|
|
@@ -136,45 +140,62 @@ class LSPLookup {
|
|
|
136
140
|
else if (ref.resolved instanceof _typed_identifier_1.TypedIdentifier) {
|
|
137
141
|
ret += "\n\n" + this.dumpType(ref.resolved);
|
|
138
142
|
}
|
|
143
|
+
else if (ref.referenceType === _reference_1.ReferenceType.BuiltinMethodReference) {
|
|
144
|
+
const builtinDef = new _builtin_1.BuiltIn().searchBuiltin((_e = (_d = ref.resolved) === null || _d === void 0 ? void 0 : _d.getName()) === null || _e === void 0 ? void 0 : _e.toUpperCase());
|
|
145
|
+
if (builtinDef === undefined) {
|
|
146
|
+
return "Error: builtin method signature not found";
|
|
147
|
+
}
|
|
148
|
+
ret += "\n\n" + this.methodParameters(builtinDef);
|
|
149
|
+
}
|
|
150
|
+
if (ref.resolved) {
|
|
151
|
+
ret += "\n\n(Resolved)";
|
|
152
|
+
}
|
|
139
153
|
if (ref.extra !== undefined && Object.keys(ref.extra).length > 0) {
|
|
140
154
|
ret += "\n\nExtra: " + JSON.stringify(ref.extra);
|
|
141
155
|
}
|
|
142
156
|
return ret;
|
|
143
157
|
}
|
|
144
|
-
static hoverMethod(method,
|
|
145
|
-
if (
|
|
158
|
+
static hoverMethod(method, classDef) {
|
|
159
|
+
if (classDef === undefined) {
|
|
146
160
|
return "class not found";
|
|
147
161
|
}
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
162
|
+
const methodDef = classDef.getMethodDefinitions().getByName(method);
|
|
163
|
+
if (methodDef === undefined) {
|
|
150
164
|
return "method not found in definition";
|
|
151
165
|
}
|
|
166
|
+
return this.methodParameters(methodDef);
|
|
167
|
+
}
|
|
168
|
+
static methodParameters(methodDef) {
|
|
152
169
|
let ret = "";
|
|
153
|
-
|
|
170
|
+
const parameters = methodDef.getParameters();
|
|
171
|
+
const importing = parameters.getImporting();
|
|
172
|
+
if (importing.length > 0) {
|
|
154
173
|
ret += "IMPORTING\n";
|
|
155
|
-
for (const p of
|
|
174
|
+
for (const p of importing) {
|
|
156
175
|
ret += this.singleParameter(p);
|
|
157
176
|
}
|
|
158
177
|
}
|
|
159
|
-
|
|
178
|
+
const exporting = parameters.getExporting();
|
|
179
|
+
if (exporting.length > 0) {
|
|
160
180
|
ret += "EXPORTING\n";
|
|
161
|
-
for (const p of
|
|
181
|
+
for (const p of exporting) {
|
|
162
182
|
ret += this.singleParameter(p);
|
|
163
183
|
}
|
|
164
184
|
}
|
|
165
|
-
|
|
185
|
+
const changing = parameters.getChanging();
|
|
186
|
+
if (changing.length > 0) {
|
|
166
187
|
ret += "CHANGING\n";
|
|
167
|
-
for (const p of
|
|
188
|
+
for (const p of changing) {
|
|
168
189
|
ret += this.singleParameter(p);
|
|
169
190
|
}
|
|
170
191
|
}
|
|
171
|
-
const r =
|
|
192
|
+
const r = parameters.getReturning();
|
|
172
193
|
if (r) {
|
|
173
194
|
ret += "RETURNING\n" + this.singleParameter(r);
|
|
174
195
|
}
|
|
175
|
-
if (
|
|
196
|
+
if (methodDef.getRaising().length > 0) {
|
|
176
197
|
ret += "RAISING\n";
|
|
177
|
-
for (const p of
|
|
198
|
+
for (const p of methodDef.getRaising()) {
|
|
178
199
|
ret += "* " + p + "\n";
|
|
179
200
|
}
|
|
180
201
|
}
|
package/build/src/registry.js
CHANGED
package/build/src/rules/index.js
CHANGED
|
@@ -92,6 +92,7 @@ __exportStar(require("./msag_consistency"), exports);
|
|
|
92
92
|
__exportStar(require("./names_no_dash"), exports);
|
|
93
93
|
__exportStar(require("./nesting"), exports);
|
|
94
94
|
__exportStar(require("./newline_between_methods"), exports);
|
|
95
|
+
__exportStar(require("./no_chained_assignment"), exports);
|
|
95
96
|
__exportStar(require("./no_public_attributes"), exports);
|
|
96
97
|
__exportStar(require("./no_yoda_conditions"), exports);
|
|
97
98
|
__exportStar(require("./object_naming"), exports);
|
|
@@ -131,6 +132,7 @@ __exportStar(require("./type_form_parameters"), exports);
|
|
|
131
132
|
__exportStar(require("./types_naming"), exports);
|
|
132
133
|
__exportStar(require("./uncaught_exception"), exports);
|
|
133
134
|
__exportStar(require("./unknown_types"), exports);
|
|
135
|
+
__exportStar(require("./unnecessary_chaining"), exports);
|
|
134
136
|
__exportStar(require("./unreachable_code"), exports);
|
|
135
137
|
__exportStar(require("./unsecure_fae"), exports);
|
|
136
138
|
__exportStar(require("./unused_ddic"), exports);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoChainedAssignment = exports.NoChainedAssignmentConf = void 0;
|
|
4
|
+
const Expressions = require("../abap/2_statements/expressions");
|
|
5
|
+
const Statements = require("../abap/2_statements/statements");
|
|
6
|
+
const issue_1 = require("../issue");
|
|
7
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
8
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
9
|
+
const _irule_1 = require("./_irule");
|
|
10
|
+
class NoChainedAssignmentConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
11
|
+
}
|
|
12
|
+
exports.NoChainedAssignmentConf = NoChainedAssignmentConf;
|
|
13
|
+
class NoChainedAssignment extends _abap_rule_1.ABAPRule {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.conf = new NoChainedAssignmentConf();
|
|
17
|
+
}
|
|
18
|
+
getMetadata() {
|
|
19
|
+
return {
|
|
20
|
+
key: "no_chained_assignment",
|
|
21
|
+
title: "No chained assignment",
|
|
22
|
+
shortDescription: `Find chained assingments and reports issues`,
|
|
23
|
+
extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#dont-chain-assignments`,
|
|
24
|
+
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Styleguide],
|
|
25
|
+
badExample: `var1 = var2 = var3.`,
|
|
26
|
+
goodExample: `var2 = var3.
|
|
27
|
+
var1 = var2.`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
getConfig() {
|
|
31
|
+
return this.conf;
|
|
32
|
+
}
|
|
33
|
+
setConfig(conf) {
|
|
34
|
+
this.conf = conf;
|
|
35
|
+
}
|
|
36
|
+
runParsed(file) {
|
|
37
|
+
const issues = [];
|
|
38
|
+
for (const s of file.getStatements()) {
|
|
39
|
+
if (!(s.get() instanceof Statements.Move)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (s.findDirectExpressions(Expressions.Target).length >= 2) {
|
|
43
|
+
const message = "No chained assignment";
|
|
44
|
+
const issue = issue_1.Issue.atStatement(file, s, message, this.getMetadata().key);
|
|
45
|
+
issues.push(issue);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return issues;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.NoChainedAssignment = NoChainedAssignment;
|
|
52
|
+
//# sourceMappingURL=no_chained_assignment.js.map
|
|
@@ -50,7 +50,8 @@ This rule makes sure the spaces are consistently required across the language.`,
|
|
|
50
50
|
}
|
|
51
51
|
missingSpace(statement) {
|
|
52
52
|
const found = statement.findAllExpressionsMulti([Expressions.CondSub, Expressions.SQLCond,
|
|
53
|
-
Expressions.ValueBody, Expressions.NewObject, Expressions.Cond,
|
|
53
|
+
Expressions.ValueBody, Expressions.NewObject, Expressions.Cond,
|
|
54
|
+
Expressions.ComponentCond, Expressions.MethodCallParam], true);
|
|
54
55
|
let pos = undefined;
|
|
55
56
|
for (const f of found) {
|
|
56
57
|
const type = f.get();
|
|
@@ -74,7 +74,7 @@ DATA(percentage) = CONV decfloat34( comment_number / abs_statement_number ) * 10
|
|
|
74
74
|
}
|
|
75
75
|
///////////////////////////
|
|
76
76
|
analyzeScope(node, obj) {
|
|
77
|
-
var _a;
|
|
77
|
+
var _a, _b;
|
|
78
78
|
const ret = [];
|
|
79
79
|
const vars = node.getData().vars;
|
|
80
80
|
for (const name in vars) {
|
|
@@ -113,7 +113,8 @@ DATA(percentage) = CONV decfloat34( comment_number / abs_statement_number ) * 10
|
|
|
113
113
|
|| statementType instanceof Statements.Catch
|
|
114
114
|
|| statementType instanceof Statements.ReadTable
|
|
115
115
|
|| statementType instanceof Statements.Loop)
|
|
116
|
-
|| ((_a = writeStatement === null || writeStatement === void 0 ? void 0 : writeStatement.concatTokens()) === null || _a === void 0 ? void 0 : _a.includes("?="))
|
|
116
|
+
|| ((_a = writeStatement === null || writeStatement === void 0 ? void 0 : writeStatement.concatTokens()) === null || _a === void 0 ? void 0 : _a.includes("?="))
|
|
117
|
+
|| ((_b = writeStatement === null || writeStatement === void 0 ? void 0 : writeStatement.concatTokens()) === null || _b === void 0 ? void 0 : _b.includes(" #("))) {
|
|
117
118
|
continue;
|
|
118
119
|
}
|
|
119
120
|
const statement = edit_helper_1.EditHelper.findStatement(identifier.getToken(), file);
|