@abaplint/core 2.79.21 → 2.79.22
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.
|
@@ -14,6 +14,8 @@ const basic_1 = require("../types/basic");
|
|
|
14
14
|
const field_chain_1 = require("./expressions/field_chain");
|
|
15
15
|
const types_1 = require("../types");
|
|
16
16
|
const expressions_1 = require("../2_statements/expressions");
|
|
17
|
+
const _builtin_1 = require("./_builtin");
|
|
18
|
+
const position_1 = require("../../position");
|
|
17
19
|
class BasicTypes {
|
|
18
20
|
constructor(filename, scope) {
|
|
19
21
|
this.filename = filename;
|
|
@@ -45,6 +47,10 @@ class BasicTypes {
|
|
|
45
47
|
if (id && (lookup === null || lookup === void 0 ? void 0 : lookup.type)) {
|
|
46
48
|
return new _typed_identifier_1.TypedIdentifier(id.getToken(), id.getFilename(), lookup.type);
|
|
47
49
|
}
|
|
50
|
+
const builtin = this.scope.getDDIC().lookupBuiltinType(name);
|
|
51
|
+
if (builtin) {
|
|
52
|
+
return new _typed_identifier_1.TypedIdentifier(new identifier_1.Identifier(new position_1.Position(1, 1), name), _builtin_1.BuiltIn.filename, builtin);
|
|
53
|
+
}
|
|
48
54
|
return undefined;
|
|
49
55
|
}
|
|
50
56
|
resolveLikeName(node, headerLogic = true) {
|
package/build/src/registry.js
CHANGED
|
@@ -5,6 +5,7 @@ const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
|
5
5
|
const issue_1 = require("../issue");
|
|
6
6
|
const _irule_1 = require("./_irule");
|
|
7
7
|
const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
8
|
+
const nodes_1 = require("../abap/nodes");
|
|
8
9
|
const Statements = require("../abap/2_statements/statements");
|
|
9
10
|
const Expressions = require("../abap/2_statements/expressions");
|
|
10
11
|
const edit_helper_1 = require("../edit_helper");
|
|
@@ -39,6 +40,7 @@ Current rules:
|
|
|
39
40
|
* DATA() definitions are outlined, opposite of https://rules.abaplint.org/prefer_inline/
|
|
40
41
|
* FIELD-SYMBOL() definitions are outlined
|
|
41
42
|
* CONV is outlined
|
|
43
|
+
* COND is outlined
|
|
42
44
|
* EMPTY KEY is changed to DEFAULT KEY, opposite of DEFAULT KEY in https://rules.abaplint.org/avoid_use/
|
|
43
45
|
* CAST changed to ?=
|
|
44
46
|
* LOOP AT method_call( ) is outlined
|
|
@@ -175,6 +177,10 @@ Only one transformation is applied to a statement at a time, so multiple steps m
|
|
|
175
177
|
if (found) {
|
|
176
178
|
return found;
|
|
177
179
|
}
|
|
180
|
+
found = this.outlineCond(high, lowFile, highSyntax);
|
|
181
|
+
if (found) {
|
|
182
|
+
return found;
|
|
183
|
+
}
|
|
178
184
|
found = this.outlineDataSimple(high, lowFile);
|
|
179
185
|
if (found) {
|
|
180
186
|
return found;
|
|
@@ -424,7 +430,7 @@ ${indentation}`);
|
|
|
424
430
|
}
|
|
425
431
|
i = key;
|
|
426
432
|
const concat = i.concatTokens();
|
|
427
|
-
if (concat.includes("WITH EMPTY KEY") === false) {
|
|
433
|
+
if (concat.toUpperCase().includes("WITH EMPTY KEY") === false) {
|
|
428
434
|
continue;
|
|
429
435
|
}
|
|
430
436
|
const token = i.findDirectTokenByText("EMPTY");
|
|
@@ -669,6 +675,59 @@ ${indentation} output = ${topTarget}.`;
|
|
|
669
675
|
}
|
|
670
676
|
return undefined;
|
|
671
677
|
}
|
|
678
|
+
outlineCond(node, lowFile, highSyntax) {
|
|
679
|
+
for (const i of node.findAllExpressionsRecursive(Expressions.Source)) {
|
|
680
|
+
if (i.getFirstToken().getStr().toUpperCase() !== "COND") {
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
const body = i.findDirectExpression(Expressions.CondBody);
|
|
684
|
+
if (body === undefined) {
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
const uniqueName = this.uniqueName(i.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
|
|
688
|
+
const type = this.findType(i, lowFile, highSyntax);
|
|
689
|
+
const indent = " ".repeat(node.getFirstToken().getStart().getCol() - 1);
|
|
690
|
+
const bodyCode = this.buildCondBody(body, uniqueName, indent);
|
|
691
|
+
const abap = `DATA ${uniqueName} TYPE ${type}.\n` + bodyCode;
|
|
692
|
+
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, node.getFirstToken().getStart(), abap);
|
|
693
|
+
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, i.getFirstToken().getStart(), i.getLastToken().getEnd(), uniqueName);
|
|
694
|
+
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|
|
695
|
+
return issue_1.Issue.atToken(lowFile, i.getFirstToken(), "Downport COND", this.getMetadata().key, this.conf.severity, fix);
|
|
696
|
+
}
|
|
697
|
+
return undefined;
|
|
698
|
+
}
|
|
699
|
+
buildCondBody(body, uniqueName, indent) {
|
|
700
|
+
let code = indent;
|
|
701
|
+
for (const c of body.getChildren()) {
|
|
702
|
+
if (c instanceof nodes_1.TokenNode) {
|
|
703
|
+
switch (c.getFirstToken().getStr().toUpperCase()) {
|
|
704
|
+
case "WHEN":
|
|
705
|
+
code += "IF ";
|
|
706
|
+
break;
|
|
707
|
+
case "THEN":
|
|
708
|
+
code += ".\n";
|
|
709
|
+
break;
|
|
710
|
+
case "ELSE":
|
|
711
|
+
code += indent + "ELSE.\n";
|
|
712
|
+
break;
|
|
713
|
+
default:
|
|
714
|
+
throw "buildCondBody, unexpected token";
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
else if (c.get() instanceof Expressions.Cond) {
|
|
718
|
+
code += c.concatTokens();
|
|
719
|
+
}
|
|
720
|
+
else if (c.get() instanceof Expressions.Source) {
|
|
721
|
+
code += indent + " " + uniqueName + " = " + c.concatTokens() + ".\n";
|
|
722
|
+
}
|
|
723
|
+
else {
|
|
724
|
+
throw "buildCondBody, unexpected expression";
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
code += indent + "ENDIF.\n";
|
|
728
|
+
code += indent;
|
|
729
|
+
return code;
|
|
730
|
+
}
|
|
672
731
|
outlineConv(node, lowFile, highSyntax) {
|
|
673
732
|
var _a;
|
|
674
733
|
for (const i of node.findAllExpressionsRecursive(Expressions.Source)) {
|
|
@@ -681,10 +740,10 @@ ${indentation} output = ${topTarget}.`;
|
|
|
681
740
|
}
|
|
682
741
|
const uniqueName = this.uniqueName(i.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
|
|
683
742
|
const type = this.findType(i, lowFile, highSyntax);
|
|
743
|
+
const indent = " ".repeat(node.getFirstToken().getStart().getCol() - 1);
|
|
684
744
|
const abap = `DATA ${uniqueName} TYPE ${type}.\n` +
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
" ".repeat(node.getFirstToken().getStart().getCol() - 1);
|
|
745
|
+
indent + `${uniqueName} = ${body}.\n` +
|
|
746
|
+
indent;
|
|
688
747
|
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, node.getFirstToken().getStart(), abap);
|
|
689
748
|
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, i.getFirstToken().getStart(), i.getLastToken().getEnd(), uniqueName);
|
|
690
749
|
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|