@abaplint/core 2.81.2 → 2.82.1

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.
@@ -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
- fromSuperClass(child) {
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"] = "ObjectOrientedReference";
8
- ReferenceType["ObjectOrientedVoidReference"] = "ObjectOrientedVoidReference";
9
- ReferenceType["ObjectOrientedUnknownReference"] = "ObjectOrientedUnknownReference";
10
- ReferenceType["TableReference"] = "TableReference";
11
- ReferenceType["TableVoidReference"] = "TableVoidReference";
12
- ReferenceType["MethodReference"] = "MethodReference";
13
- ReferenceType["BuiltinMethodReference"] = "BuiltinMethodReference";
14
- ReferenceType["MethodImplementationReference"] = "MethodImplementationReference";
15
- ReferenceType["TypeReference"] = "TypeReference";
16
- ReferenceType["BuiltinTypeReference"] = "BuiltinTypeReference";
17
- ReferenceType["VoidType"] = "VoidType";
18
- ReferenceType["InferredType"] = "InferredType";
19
- ReferenceType["FormReference"] = "FormReference";
20
- // FormVoidReference = "FormReference",
21
- ReferenceType["DataReadReference"] = "DataReadReference";
22
- ReferenceType["DataWriteReference"] = "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
@@ -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,13 +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
31
  scope.addList(classAttributes.getStatic());
32
32
  for (const i of classAttributes.getInstance()) {
33
33
  scope.addExtraLikeType(i);
34
34
  }
35
- const implemented = helper.fromSuperClass(classDefinition);
36
- helper.fromInterfaces(classDefinition, implemented);
35
+ helper.fromSuperClassesAndInterfaces(classDefinition);
37
36
  }
38
37
  }
39
38
  exports.ClassImplementation = ClassImplementation;
@@ -13,12 +13,10 @@ class MethodImplementation {
13
13
  const methodName = methodToken === null || methodToken === void 0 ? void 0 : methodToken.getStr();
14
14
  const classDefinition = scope.findClassDefinition(className);
15
15
  if (classDefinition === undefined) {
16
- // scope.pop(node.getLastToken().getEnd());
17
16
  throw new Error("Class definition for \"" + className + "\" not found");
18
17
  }
19
18
  const { method: methodDefinition } = helper.searchMethodName(classDefinition, methodName);
20
19
  if (methodDefinition === undefined) {
21
- // scope.pop(node.getLastToken().getEnd());
22
20
  throw new Error("Method definition \"" + methodName + "\" not found");
23
21
  }
24
22
  if (methodDefinition.isStatic() === false) {
@@ -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
- const implemented = helper.fromSuperClass(this);
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);
@@ -114,10 +114,14 @@ class EditHelper {
114
114
  continue;
115
115
  }
116
116
  else if (setPrevious === true) {
117
- previousStatement = s;
117
+ if (scolon.getStart().equals(colon.getStart())) {
118
+ previousStatement = s;
119
+ }
118
120
  }
119
121
  else if (setNext === true) {
120
- nextStatement = s;
122
+ if (scolon.getStart().equals(colon.getStart())) {
123
+ nextStatement = s;
124
+ }
121
125
  break;
122
126
  }
123
127
  }
@@ -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 { hover: "Class definition, " + cursor.token.getStr(),
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 { hover: "Interface definition, " + cursor.token.getStr(),
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 definition, " + cursor.token.getStr() + "\n\n" + this.dumpType(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 definition \"" + method.getName() + "\"";
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 definition\n\n" + this.dumpType(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 void types";
110
+ value = value + "\n\nContains Void types";
107
111
  }
108
112
  if (variable.getType().getQualifiedName()) {
109
- value = value + "\n\nQualified type name: ```" + variable.getType().getQualifiedName() + "```";
113
+ value = value + "\n\nQualified Type Name: ```" + variable.getType().getQualifiedName() + "```";
110
114
  }
111
115
  if (variable.getType().isGeneric() === true) {
112
- value = value + "\n\nIs generic type";
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 = "Resolved Reference: " + ref.referenceType + " " + name;
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, def) {
145
- if (def === undefined) {
158
+ static hoverMethod(method, classDef) {
159
+ if (classDef === undefined) {
146
160
  return "class not found";
147
161
  }
148
- const mdef = def.getMethodDefinitions().getByName(method);
149
- if (mdef === undefined) {
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
- if (mdef.getParameters().getImporting().length > 0) {
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 mdef.getParameters().getImporting()) {
174
+ for (const p of importing) {
156
175
  ret += this.singleParameter(p);
157
176
  }
158
177
  }
159
- if (mdef.getParameters().getExporting().length > 0) {
178
+ const exporting = parameters.getExporting();
179
+ if (exporting.length > 0) {
160
180
  ret += "EXPORTING\n";
161
- for (const p of mdef.getParameters().getExporting()) {
181
+ for (const p of exporting) {
162
182
  ret += this.singleParameter(p);
163
183
  }
164
184
  }
165
- if (mdef.getParameters().getChanging().length > 0) {
185
+ const changing = parameters.getChanging();
186
+ if (changing.length > 0) {
166
187
  ret += "CHANGING\n";
167
- for (const p of mdef.getParameters().getChanging()) {
188
+ for (const p of changing) {
168
189
  ret += this.singleParameter(p);
169
190
  }
170
191
  }
171
- const r = mdef.getParameters().getReturning();
192
+ const r = parameters.getReturning();
172
193
  if (r) {
173
194
  ret += "RETURNING\n" + this.singleParameter(r);
174
195
  }
175
- if (mdef.getRaising().length > 0) {
196
+ if (methodDef.getRaising().length > 0) {
176
197
  ret += "RAISING\n";
177
- for (const p of mdef.getRaising()) {
198
+ for (const p of methodDef.getRaising()) {
178
199
  ret += "* " + p + "\n";
179
200
  }
180
201
  }
@@ -68,7 +68,7 @@ class Registry {
68
68
  }
69
69
  static abaplintVersion() {
70
70
  // magic, see build script "version.sh"
71
- return "2.81.2";
71
+ return "2.82.1";
72
72
  }
73
73
  getDDICReferences() {
74
74
  return this.references;
@@ -124,6 +124,7 @@ __exportStar(require("./space_before_colon"), exports);
124
124
  __exportStar(require("./space_before_dot"), exports);
125
125
  __exportStar(require("./sql_escape_host_variables"), exports);
126
126
  __exportStar(require("./start_at_tab"), exports);
127
+ __exportStar(require("./static_call_via_instance"), exports);
127
128
  __exportStar(require("./superclass_final"), exports);
128
129
  __exportStar(require("./sy_modification"), exports);
129
130
  __exportStar(require("./tabl_enhancement_category"), exports);
@@ -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, Expressions.ComponentCond, Expressions.MethodCallParam], true);
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();
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StaticCallViaInstance = exports.StaticCallViaInstanceConf = void 0;
4
+ /* eslint-disable max-len */
5
+ const issue_1 = require("../issue");
6
+ const _abap_rule_1 = require("./_abap_rule");
7
+ const _basic_rule_config_1 = require("./_basic_rule_config");
8
+ const _irule_1 = require("./_irule");
9
+ const syntax_1 = require("../abap/5_syntax/syntax");
10
+ const _reference_1 = require("../abap/5_syntax/_reference");
11
+ const types_1 = require("../abap/types");
12
+ class StaticCallViaInstanceConf extends _basic_rule_config_1.BasicRuleConfig {
13
+ }
14
+ exports.StaticCallViaInstanceConf = StaticCallViaInstanceConf;
15
+ class StaticCallViaInstance extends _abap_rule_1.ABAPRule {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.conf = new StaticCallViaInstanceConf();
19
+ }
20
+ getMetadata() {
21
+ return {
22
+ key: "static_call_via_instance",
23
+ title: "Static call via instance variable",
24
+ shortDescription: `Static method call via instance variable`,
25
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#dont-call-static-methods-through-instance-variables`,
26
+ tags: [_irule_1.RuleTag.Styleguide],
27
+ };
28
+ }
29
+ getConfig() {
30
+ return this.conf;
31
+ }
32
+ setConfig(conf) {
33
+ this.conf = conf;
34
+ }
35
+ runParsed(file, obj) {
36
+ const issues = [];
37
+ const staticMethodCalls = this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop());
38
+ const tokens = file.getTokens();
39
+ for (let i = 0; i < tokens.length - 1; i++) {
40
+ const token = tokens[i];
41
+ if (token.getStr() !== "->") {
42
+ continue;
43
+ }
44
+ const next = tokens[i + 1];
45
+ for (const s of staticMethodCalls) {
46
+ if (s.equals(next.getStart())) {
47
+ const message = "Avoid calling static method via instance";
48
+ issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key));
49
+ break;
50
+ }
51
+ }
52
+ }
53
+ return issues;
54
+ }
55
+ listMethodCalls(filename, node) {
56
+ const ret = [];
57
+ for (const r of node.getData().references) {
58
+ if (r.referenceType !== _reference_1.ReferenceType.MethodReference || r.position.getFilename() !== filename) {
59
+ continue;
60
+ }
61
+ if (r.resolved instanceof types_1.MethodDefinition && r.resolved.isStatic() === true) {
62
+ ret.push(r.position.getStart());
63
+ }
64
+ }
65
+ for (const child of node.getChildren()) {
66
+ ret.push(...this.listMethodCalls(filename, child));
67
+ }
68
+ return ret;
69
+ }
70
+ }
71
+ exports.StaticCallViaInstance = StaticCallViaInstance;
72
+ //# sourceMappingURL=static_call_via_instance.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.81.2",
3
+ "version": "2.82.1",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",
@@ -48,9 +48,9 @@
48
48
  "@microsoft/api-extractor": "^7.18.19",
49
49
  "@types/chai": "^4.2.22",
50
50
  "@types/mocha": "^9.0.0",
51
- "@types/node": "^16.11.9",
51
+ "@types/node": "^16.11.10",
52
52
  "chai": "^4.3.4",
53
- "eslint": "^8.2.0",
53
+ "eslint": "^8.3.0",
54
54
  "mocha": "^9.1.3",
55
55
  "c8": "^7.10.0",
56
56
  "source-map-support": "^0.5.21",