@abaplint/core 2.120.66 → 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.
@@ -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;
@@ -18,7 +18,9 @@ class ModifyLine {
18
18
  const ocp = (0, combi_1.str)("OF CURRENT PAGE");
19
19
  const intensified = (0, combi_1.seq)("INTENSIFIED", onOff);
20
20
  const intensifiedOpt = (0, combi_1.seq)("INTENSIFIED", (0, combi_1.opt)(onOff));
21
- const lineFormat = (0, combi_1.seq)("LINE FORMAT", (0, combi_1.per)("INPUT OFF", "INVERSE", "RESET", intensifiedOpt, expressions_1.Color));
21
+ const inputOpt = (0, combi_1.seq)("INPUT", (0, combi_1.opt)((0, combi_1.alt)(eq, onOff)));
22
+ const inverseOpt = (0, combi_1.seq)("INVERSE", (0, combi_1.opt)((0, combi_1.alt)(eq, onOff)));
23
+ const lineFormat = (0, combi_1.seq)("LINE FORMAT", (0, combi_1.per)(inputOpt, inverseOpt, "RESET", intensifiedOpt, expressions_1.Color));
22
24
  const options = (0, combi_1.per)(index, value, format, page, lineFormat, lineValue, ocp, intensified, expressions_1.Color);
23
25
  const ret = (0, combi_1.seq)("MODIFY", (0, combi_1.altPrio)("CURRENT LINE", (0, combi_1.seq)("LINE", expressions_1.Source)), (0, combi_1.opt)(options));
24
26
  return (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, ret);
@@ -409,6 +409,7 @@ class CurrentScope {
409
409
  if (name === undefined) {
410
410
  return undefined;
411
411
  }
412
+ name = name.replace(/^!/, "");
412
413
  const found = (_a = this.current) === null || _a === void 0 ? void 0 : _a.findVariable(name);
413
414
  if (found) {
414
415
  return found;
@@ -514,6 +515,17 @@ class CurrentScope {
514
515
  var _a;
515
516
  return ((_a = this.localFriends.get(className.toUpperCase())) === null || _a === void 0 ? void 0 : _a.includes(friendName.toUpperCase())) === true;
516
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
+ }
517
529
  getEnclosingClassName() {
518
530
  let curr = this.current;
519
531
  while (curr !== undefined) {
@@ -173,6 +173,97 @@ class ObjectOriented {
173
173
  }
174
174
  // does the supplied class have friendship with "friendName"?
175
175
  // note that interfaces of the friend, and subclasses of the friend also have friendship
176
+ // returns the visibility as text if a member declared in foundDef, reached via def, cannot be accessed from enclosing
177
+ memberNotVisible(visibility, def, foundDef, enclosing) {
178
+ var _a, _b;
179
+ if (visibility === visibility_1.Visibility.Public || foundDef === undefined) {
180
+ return undefined;
181
+ }
182
+ else if (!(foundDef instanceof types_1.ClassDefinition)) {
183
+ // interface members are always public
184
+ return undefined;
185
+ }
186
+ const name = foundDef.getName().toUpperCase();
187
+ enclosing = enclosing === null || enclosing === void 0 ? void 0 : enclosing.toUpperCase();
188
+ if (enclosing === undefined || enclosing === name) {
189
+ return undefined;
190
+ }
191
+ // friendship with the class used at the call site also gives access to inherited members
192
+ const visited = [];
193
+ let current = def instanceof types_1.ClassDefinition ? def : foundDef;
194
+ while (current !== undefined && visited.includes(current.getName().toUpperCase()) === false) {
195
+ visited.push(current.getName().toUpperCase());
196
+ if (this.hasFriendship(current, enclosing)) {
197
+ return undefined;
198
+ }
199
+ const sup = current.getSuperClass();
200
+ current = sup === undefined ? undefined : this.scope.findClassDefinition(sup);
201
+ }
202
+ if (visibility === visibility_1.Visibility.Protected) {
203
+ // subclasses can access protected members
204
+ let sup = (_a = this.scope.findClassDefinition(enclosing)) === null || _a === void 0 ? void 0 : _a.getSuperClass();
205
+ while (sup !== undefined) {
206
+ if (sup.toUpperCase() === name) {
207
+ return undefined;
208
+ }
209
+ sup = (_b = this.scope.findClassDefinition(sup)) === null || _b === void 0 ? void 0 : _b.getSuperClass();
210
+ }
211
+ return "protected";
212
+ }
213
+ return "private";
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
+ }
251
+ // the class declaring the attribute or constant, searched from def up through the super classes
252
+ findAttributeOwner(def, found) {
253
+ const visited = [];
254
+ let current = def;
255
+ while (current instanceof types_1.ClassDefinition && visited.includes(current.getName().toUpperCase()) === false) {
256
+ visited.push(current.getName().toUpperCase());
257
+ const attributes = current.getAttributes();
258
+ if (attributes.getAll().includes(found)
259
+ || attributes.getConstants().includes(found)) {
260
+ return current;
261
+ }
262
+ const sup = current.getSuperClass();
263
+ current = sup === undefined ? undefined : this.findSuperDefinition(sup);
264
+ }
265
+ return undefined;
266
+ }
176
267
  hasFriendship(cd, friendName) {
177
268
  var _a;
178
269
  const friends = cd.getFriends().map(f => f.toUpperCase());
@@ -8,6 +8,8 @@ const _object_oriented_1 = require("../_object_oriented");
8
8
  const data_reference_type_1 = require("../../types/basic/data_reference_type");
9
9
  const _reference_1 = require("../_reference");
10
10
  const basic_1 = require("../../types/basic");
11
+ const class_attribute_1 = require("../../types/class_attribute");
12
+ const class_constant_1 = require("../../types/class_constant");
11
13
  const _syntax_input_1 = require("../_syntax_input");
12
14
  class AttributeName {
13
15
  static runSyntax(context, node, input, type, error = true) {
@@ -36,6 +38,15 @@ class AttributeName {
36
38
  }
37
39
  return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
38
40
  }
41
+ if (found instanceof class_attribute_1.ClassAttribute || found instanceof class_constant_1.ClassConstant) {
42
+ const owner = helper.findAttributeOwner(def, found);
43
+ const notVisible = helper.memberNotVisible(found.getVisibility(), def, owner, input.scope.getEnclosingClassName());
44
+ if (notVisible !== undefined) {
45
+ const message = `Attribute "${name}" is ${notVisible} and cannot be accessed`;
46
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, token, message));
47
+ return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
48
+ }
49
+ }
39
50
  if (type) {
40
51
  input.scope.addReference(token, found, type, input.filename);
41
52
  }
@@ -47,8 +47,6 @@ const _reference_1 = require("../_reference");
47
47
  const component_name_1 = require("./component_name");
48
48
  const attribute_name_1 = require("./attribute_name");
49
49
  const _syntax_input_1 = require("../_syntax_input");
50
- const visibility_1 = require("../../4_file_information/visibility");
51
- const class_definition_1 = require("../../types/class_definition");
52
50
  class MethodCallChain {
53
51
  static runSyntax(node, input, targetType) {
54
52
  var _a, _b;
@@ -78,6 +76,14 @@ class MethodCallChain {
78
76
  const methodToken = (_a = current.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
79
77
  const methodName = methodToken === null || methodToken === void 0 ? void 0 : methodToken.getStr();
80
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
+ }
81
87
  // eslint-disable-next-line prefer-const
82
88
  let { method, def: foundDef } = helper.searchMethodName(def, methodName);
83
89
  if (method === undefined && current === first) {
@@ -97,12 +103,19 @@ class MethodCallChain {
97
103
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, methodToken, message));
98
104
  return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
99
105
  }
100
- const notVisible = method ? this.checkVisibility(method, def, foundDef, input) : undefined;
106
+ const notVisible = method
107
+ ? helper.memberNotVisible(method.getVisibility(), def, foundDef, input.scope.getEnclosingClassName())
108
+ : undefined;
101
109
  if (notVisible !== undefined) {
102
110
  const message = `Method "${methodName}" is ${notVisible} and cannot be accessed`;
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);
@@ -145,47 +158,6 @@ class MethodCallChain {
145
158
  return context;
146
159
  }
147
160
  //////////////////////////////////////
148
- // returns the visibility as text if the method cannot be accessed from the current scope
149
- static checkVisibility(method, def, foundDef, input) {
150
- var _a, _b, _c;
151
- const visibility = method.getVisibility();
152
- if (visibility === visibility_1.Visibility.Public || foundDef === undefined) {
153
- return undefined;
154
- }
155
- else if (!(foundDef instanceof class_definition_1.ClassDefinition)) {
156
- // interface members are always public
157
- return undefined;
158
- }
159
- const name = foundDef.getName().toUpperCase();
160
- const enclosing = (_a = input.scope.getEnclosingClassName()) === null || _a === void 0 ? void 0 : _a.toUpperCase();
161
- if (enclosing === undefined || enclosing === name) {
162
- return undefined;
163
- }
164
- // friendship with the class used at the call site also gives access to inherited members
165
- const helper = new _object_oriented_1.ObjectOriented(input.scope);
166
- const visited = [];
167
- let current = def instanceof class_definition_1.ClassDefinition ? def : foundDef;
168
- while (current !== undefined && visited.includes(current.getName().toUpperCase()) === false) {
169
- visited.push(current.getName().toUpperCase());
170
- if (helper.hasFriendship(current, enclosing)) {
171
- return undefined;
172
- }
173
- const sup = current.getSuperClass();
174
- current = sup === undefined ? undefined : input.scope.findClassDefinition(sup);
175
- }
176
- if (visibility === visibility_1.Visibility.Protected) {
177
- // subclasses can access protected members
178
- let sup = (_b = input.scope.findClassDefinition(enclosing)) === null || _b === void 0 ? void 0 : _b.getSuperClass();
179
- while (sup !== undefined) {
180
- if (sup.toUpperCase() === name) {
181
- return undefined;
182
- }
183
- sup = (_c = input.scope.findClassDefinition(sup)) === null || _c === void 0 ? void 0 : _c.getSuperClass();
184
- }
185
- return "protected";
186
- }
187
- return "private";
188
- }
189
161
  static findTop(first, input, targetType) {
190
162
  var _a;
191
163
  if (first.get() instanceof Expressions.ClassName) {
@@ -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
@@ -48,6 +48,7 @@ const expressions_1 = require("../../2_statements/expressions");
48
48
  const field_length_1 = require("./field_length");
49
49
  const cast_1 = require("./cast");
50
50
  const _syntax_input_1 = require("../_syntax_input");
51
+ const version_1 = require("../../../version");
51
52
  class Target {
52
53
  static runSyntax(node, input) {
53
54
  const concat = node.concatTokens();
@@ -113,6 +114,12 @@ class Target {
113
114
  if (!(context instanceof basic_1.VoidType)) {
114
115
  context = context.getType();
115
116
  }
117
+ if ((context === null || context === void 0 ? void 0 : context.isGeneric()) === true
118
+ && !(0, version_1.releaseAtLeast)(input.scope.getRelease(), version_1.Release.v756)
119
+ && input.scope.getLanguageVersion() !== version_1.LanguageVersion.Cloud
120
+ && !input.scope.getOpenABAP()) {
121
+ throw new Error("A generic reference cannot be dereferenced");
122
+ }
116
123
  }
117
124
  else if (current.get() instanceof Expressions.ComponentName) {
118
125
  context = component_name_1.ComponentName.runSyntax(context, current, input);
@@ -116,6 +116,7 @@ class Indent {
116
116
  || type instanceof Statements.ProcessBeforeOutput
117
117
  || type instanceof Statements.ProcessOnValueRequest
118
118
  || type instanceof Statements.TopOfPage
119
+ || type instanceof Statements.EndOfPage
119
120
  || type instanceof Statements.Get
120
121
  || type instanceof Statements.EndOfSelection
121
122
  || type instanceof Statements.LoadOfProgram) {
@@ -211,6 +212,7 @@ class Indent {
211
212
  || type instanceof Statements.Initialization
212
213
  || type instanceof Statements.AtUserCommand
213
214
  || type instanceof Statements.TopOfPage
215
+ || type instanceof Statements.EndOfPage
214
216
  || type instanceof Statements.EndOfSelection
215
217
  || type instanceof Statements.Public
216
218
  || type instanceof Statements.Protected
@@ -75,7 +75,7 @@ class Registry {
75
75
  }
76
76
  static abaplintVersion() {
77
77
  // magic, see build script "version.js"
78
- return "2.120.66";
78
+ return "2.120.68";
79
79
  }
80
80
  getDDICReferences() {
81
81
  return this.ddicReferences;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.66",
3
+ "version": "2.120.68",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",