@abaplint/core 2.120.67 → 2.120.68
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/_current_scope.js +11 -0
- package/build/src/abap/5_syntax/_object_oriented.js +36 -0
- package/build/src/abap/5_syntax/expressions/method_call_chain.js +13 -0
- package/build/src/abap/5_syntax/expressions/method_source.js +13 -0
- package/build/src/abap/5_syntax/expressions/source.js +20 -0
- package/build/src/registry.js +1 -1
- package/package.json +1 -1
package/build/abaplint.d.ts
CHANGED
|
@@ -1628,6 +1628,7 @@ export declare class CurrentScope {
|
|
|
1628
1628
|
isInStaticMethod(): boolean;
|
|
1629
1629
|
addLocalFriend(className: string, friendName: string): void;
|
|
1630
1630
|
isLocalFriend(className: string, friendName: string): boolean;
|
|
1631
|
+
getEnclosingMethodName(): string | undefined;
|
|
1631
1632
|
getEnclosingClassName(): string | undefined;
|
|
1632
1633
|
isGlobalOO(): boolean;
|
|
1633
1634
|
isTypePool(): boolean;
|
|
@@ -515,6 +515,17 @@ class CurrentScope {
|
|
|
515
515
|
var _a;
|
|
516
516
|
return ((_a = this.localFriends.get(className.toUpperCase())) === null || _a === void 0 ? void 0 : _a.includes(friendName.toUpperCase())) === true;
|
|
517
517
|
}
|
|
518
|
+
getEnclosingMethodName() {
|
|
519
|
+
let curr = this.current;
|
|
520
|
+
while (curr !== undefined) {
|
|
521
|
+
const stype = curr.getIdentifier().stype;
|
|
522
|
+
if (stype === _scope_type_1.ScopeType.Method || stype === _scope_type_1.ScopeType.MethodInstance) {
|
|
523
|
+
return curr.getIdentifier().sname;
|
|
524
|
+
}
|
|
525
|
+
curr = curr.getParent();
|
|
526
|
+
}
|
|
527
|
+
return undefined;
|
|
528
|
+
}
|
|
518
529
|
getEnclosingClassName() {
|
|
519
530
|
let curr = this.current;
|
|
520
531
|
while (curr !== undefined) {
|
|
@@ -212,6 +212,42 @@ class ObjectOriented {
|
|
|
212
212
|
}
|
|
213
213
|
return "private";
|
|
214
214
|
}
|
|
215
|
+
// the fixture methods of a test class are called by ABAP Unit only, returns the message otherwise
|
|
216
|
+
checkSpecialTestMethodCall(method, foundDef) {
|
|
217
|
+
if (method === undefined
|
|
218
|
+
|| !(foundDef instanceof types_1.ClassDefinition)
|
|
219
|
+
|| foundDef.isForTesting() === false) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
const name = method.getName().toUpperCase();
|
|
223
|
+
if (["SETUP", "TEARDOWN", "CLASS_SETUP", "CLASS_TEARDOWN"].includes(name) === false) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
return `The special method "${name}" cannot be called directly`;
|
|
227
|
+
}
|
|
228
|
+
// SUPER-> can only call the previous implementation of the method it is used in, returns the message otherwise
|
|
229
|
+
// both names are resolved in the super class, so an alias and the method it stands for are the same
|
|
230
|
+
checkSuperCall(superDef, methodName) {
|
|
231
|
+
const enclosing = this.scope.getEnclosingMethodName();
|
|
232
|
+
if (methodName === undefined
|
|
233
|
+
|| enclosing === undefined
|
|
234
|
+
|| methodName.toUpperCase() === enclosing.toUpperCase()) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
const message = "SUPER-> can only be used to call the previous implementation of the same method";
|
|
238
|
+
// a method that is not a redefinition has no previous implementation
|
|
239
|
+
const enclosingClass = this.scope.findClassDefinition(this.scope.getEnclosingClassName());
|
|
240
|
+
const ownDefinition = enclosingClass === null || enclosingClass === void 0 ? void 0 : enclosingClass.getMethodDefinitions().getByName(enclosing);
|
|
241
|
+
if (ownDefinition !== undefined && ownDefinition.isRedefinition() === false) {
|
|
242
|
+
return message;
|
|
243
|
+
}
|
|
244
|
+
const called = this.searchMethodName(superDef, methodName).method;
|
|
245
|
+
const own = this.searchMethodName(superDef, enclosing).method;
|
|
246
|
+
if (called === undefined || own === undefined || called === own) {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
return message;
|
|
250
|
+
}
|
|
215
251
|
// the class declaring the attribute or constant, searched from def up through the super classes
|
|
216
252
|
findAttributeOwner(def, found) {
|
|
217
253
|
const visited = [];
|
|
@@ -76,6 +76,14 @@ class MethodCallChain {
|
|
|
76
76
|
const methodToken = (_a = current.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
|
77
77
|
const methodName = methodToken === null || methodToken === void 0 ? void 0 : methodToken.getStr();
|
|
78
78
|
const def = input.scope.findObjectDefinition(className);
|
|
79
|
+
const isSuper = current === children[2]
|
|
80
|
+
&& first.get() instanceof Expressions.FieldChain
|
|
81
|
+
&& first.concatTokens().toUpperCase() === "SUPER";
|
|
82
|
+
const superMessage = isSuper ? helper.checkSuperCall(def, methodName) : undefined;
|
|
83
|
+
if (superMessage !== undefined) {
|
|
84
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, methodToken, superMessage));
|
|
85
|
+
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
86
|
+
}
|
|
79
87
|
// eslint-disable-next-line prefer-const
|
|
80
88
|
let { method, def: foundDef } = helper.searchMethodName(def, methodName);
|
|
81
89
|
if (method === undefined && current === first) {
|
|
@@ -103,6 +111,11 @@ class MethodCallChain {
|
|
|
103
111
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, methodToken, message));
|
|
104
112
|
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
105
113
|
}
|
|
114
|
+
const specialMessage = isSuper ? undefined : helper.checkSpecialTestMethodCall(method, foundDef);
|
|
115
|
+
if (specialMessage !== undefined) {
|
|
116
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, methodToken, specialMessage));
|
|
117
|
+
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
118
|
+
}
|
|
106
119
|
const voidedName = context instanceof basic_1.VoidType ? context.getVoided() : undefined;
|
|
107
120
|
const extra = helper.methodReferenceExtras(foundDef, className || voidedName);
|
|
108
121
|
input.scope.addReference(methodToken, method, _reference_1.ReferenceType.MethodReference, input.filename, extra);
|
|
@@ -121,6 +121,14 @@ class MethodSource {
|
|
|
121
121
|
const methodToken = current.getFirstToken();
|
|
122
122
|
const methodName = methodToken === null || methodToken === void 0 ? void 0 : methodToken.getStr();
|
|
123
123
|
const def = input.scope.findObjectDefinition(className);
|
|
124
|
+
const isSuper = implicitMe === false
|
|
125
|
+
&& first.get() instanceof Expressions.SourceField
|
|
126
|
+
&& first.concatTokens().toUpperCase() === "SUPER";
|
|
127
|
+
const superMessage = isSuper ? helper.checkSuperCall(def, methodName) : undefined;
|
|
128
|
+
if (superMessage !== undefined) {
|
|
129
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, methodToken, superMessage));
|
|
130
|
+
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
131
|
+
}
|
|
124
132
|
// eslint-disable-next-line prefer-const
|
|
125
133
|
let { method, def: foundDef } = helper.searchMethodName(def, methodName);
|
|
126
134
|
if (implicitMe && current === first && (method === null || method === void 0 ? void 0 : method.isStatic()) === false && input.scope.isInStaticMethod() === true) {
|
|
@@ -137,6 +145,11 @@ class MethodSource {
|
|
|
137
145
|
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
138
146
|
}
|
|
139
147
|
else if (method) {
|
|
148
|
+
const specialMessage = isSuper ? undefined : helper.checkSpecialTestMethodCall(method, foundDef);
|
|
149
|
+
if (specialMessage !== undefined) {
|
|
150
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, methodToken, specialMessage));
|
|
151
|
+
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
152
|
+
}
|
|
140
153
|
const extra = helper.methodReferenceExtras(foundDef, className);
|
|
141
154
|
input.scope.addReference(methodToken, method, _reference_1.ReferenceType.MethodReference, input.filename, extra);
|
|
142
155
|
context = method;
|
|
@@ -56,6 +56,7 @@ const corresponding_body_1 = require("./corresponding_body");
|
|
|
56
56
|
const _builtin_1 = require("../_builtin");
|
|
57
57
|
const attribute_chain_1 = require("./attribute_chain");
|
|
58
58
|
const dereference_1 = require("./dereference");
|
|
59
|
+
const cast_1 = require("./cast");
|
|
59
60
|
const _typed_identifier_1 = require("../../types/_typed_identifier");
|
|
60
61
|
const _type_utils_1 = require("../_type_utils");
|
|
61
62
|
const _syntax_input_1 = require("../_syntax_input");
|
|
@@ -279,6 +280,10 @@ class Source {
|
|
|
279
280
|
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
280
281
|
}
|
|
281
282
|
}
|
|
283
|
+
else if (get instanceof Expressions.Cast) {
|
|
284
|
+
const found = cast_1.Cast.runSyntax(first, input, targetType);
|
|
285
|
+
context = arithmetic === true ? this.infer(context, found, true) : found;
|
|
286
|
+
}
|
|
282
287
|
else if (get instanceof Expressions.FieldChain) {
|
|
283
288
|
const found = field_chain_1.FieldChain.runSyntax(first, input, type, allowGenericDeference);
|
|
284
289
|
context = arithmetic === true ? this.infer(context, found, true) : found;
|
|
@@ -295,6 +300,11 @@ class Source {
|
|
|
295
300
|
context = this.infer(context, found, arithmetic);
|
|
296
301
|
}
|
|
297
302
|
else if (get instanceof Expressions.Dereference) {
|
|
303
|
+
if (this.isNewObjectDereference(node, first)) {
|
|
304
|
+
const message = "NEW cannot be dereferenced directly";
|
|
305
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, first.getFirstToken(), message));
|
|
306
|
+
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
307
|
+
}
|
|
298
308
|
context = dereference_1.Dereference.runSyntax(first, context, input);
|
|
299
309
|
}
|
|
300
310
|
else if (get instanceof Expressions.ComponentChain) {
|
|
@@ -482,6 +492,16 @@ class Source {
|
|
|
482
492
|
}
|
|
483
493
|
return targetType;
|
|
484
494
|
}
|
|
495
|
+
// "NEW ty( )->*" is a syntax error, also in releases where a method call can be dereferenced
|
|
496
|
+
static isNewObjectDereference(node, deref) {
|
|
497
|
+
var _a;
|
|
498
|
+
const children = node.getChildren();
|
|
499
|
+
const before = children[children.indexOf(deref) - 1];
|
|
500
|
+
return before instanceof nodes_1.ExpressionNode
|
|
501
|
+
&& before.get() instanceof Expressions.MethodCallChain
|
|
502
|
+
&& before.getChildren().length === 1
|
|
503
|
+
&& ((_a = before.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.NewObject;
|
|
504
|
+
}
|
|
485
505
|
}
|
|
486
506
|
exports.Source = Source;
|
|
487
507
|
//# sourceMappingURL=source.js.map
|
package/build/src/registry.js
CHANGED