@abaplint/core 2.120.25 → 2.120.27
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 +4 -0
- package/build/src/abap/5_syntax/expressions/_check_database_fields.js +35 -0
- package/build/src/abap/5_syntax/expressions/select.js +2 -30
- package/build/src/abap/5_syntax/statements/delete_database.js +9 -1
- package/build/src/abap/5_syntax/statements/update_database.js +9 -1
- package/build/src/objects/data_element.js +17 -0
- package/build/src/objects/domain.js +5 -0
- package/build/src/registry.js +1 -1
- package/build/src/rules/cds_check_syntax.js +299 -0
- package/build/src/rules/index.js +1 -0
- package/package.json +1 -1
package/build/abaplint.d.ts
CHANGED
|
@@ -1790,6 +1790,9 @@ declare class DataElement extends AbstractObject {
|
|
|
1790
1790
|
};
|
|
1791
1791
|
setDirty(): void;
|
|
1792
1792
|
getDomainName(): string | undefined;
|
|
1793
|
+
/** parseType() cannot distinguish DEC, CURR, and QUAN because they all become PackedType.
|
|
1794
|
+
* Return the original DDIC datatype instead, resolving domain-backed data elements when possible. */
|
|
1795
|
+
getDataType(reg?: IRegistry): string | undefined;
|
|
1793
1796
|
getTexts(): {
|
|
1794
1797
|
short?: string;
|
|
1795
1798
|
medium?: string;
|
|
@@ -2053,6 +2056,7 @@ declare class Domain extends AbstractObject {
|
|
|
2053
2056
|
getType(): string;
|
|
2054
2057
|
getDescription(): string | undefined;
|
|
2055
2058
|
getConversionExit(): string | undefined;
|
|
2059
|
+
getDataType(): string | undefined;
|
|
2056
2060
|
getAllowedNaming(): {
|
|
2057
2061
|
maxLength: number;
|
|
2058
2062
|
allowNamespace: boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkDatabaseFields = checkDatabaseFields;
|
|
4
|
+
const basic_1 = require("../../types/basic");
|
|
5
|
+
const _syntax_input_1 = require("../_syntax_input");
|
|
6
|
+
function checkDatabaseFields(fields, dbSources, input, token) {
|
|
7
|
+
if (dbSources.length > 1) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const first = dbSources[0];
|
|
11
|
+
if (first === undefined) {
|
|
12
|
+
// then its voided
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const type = first.parseType(input.scope.getRegistry());
|
|
16
|
+
if (type instanceof basic_1.VoidType || type instanceof basic_1.UnknownType) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!(type instanceof basic_1.StructureType)) {
|
|
20
|
+
const message = "checkFields, expected structure, " + type.constructor.name;
|
|
21
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, token, message));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
for (const field of fields) {
|
|
25
|
+
if (field === "*") {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (/^\w+$/.test(field) && type.getComponentByName(field) === undefined) {
|
|
29
|
+
const message = `checkFields, field ${field} not found`;
|
|
30
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, token, message));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=_check_database_fields.js.map
|
|
@@ -48,6 +48,7 @@ const dynamic_1 = require("./dynamic");
|
|
|
48
48
|
const _reference_1 = require("../_reference");
|
|
49
49
|
const _syntax_input_1 = require("../_syntax_input");
|
|
50
50
|
const version_1 = require("../../../version");
|
|
51
|
+
const _check_database_fields_1 = require("./_check_database_fields");
|
|
51
52
|
const isSimple = /^\w+$/;
|
|
52
53
|
class Select {
|
|
53
54
|
static runSyntax(node, input, skipImplicitInto = false, selectLoop = false) {
|
|
@@ -72,7 +73,7 @@ class Select {
|
|
|
72
73
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
(0, _check_database_fields_1.checkDatabaseFields)(fields.map(field => field.code), dbSources, input, node.getFirstToken());
|
|
76
77
|
const intoExpression = this.handleInto(node, input, fields, dbSources);
|
|
77
78
|
const fae = node.findDirectExpression(Expressions.SQLForAllEntries);
|
|
78
79
|
if (fae) {
|
|
@@ -299,35 +300,6 @@ class Select {
|
|
|
299
300
|
}
|
|
300
301
|
return undefined;
|
|
301
302
|
}
|
|
302
|
-
static checkFields(fields, dbSources, input, node) {
|
|
303
|
-
if (dbSources.length > 1) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const first = dbSources[0];
|
|
307
|
-
if (first === undefined) {
|
|
308
|
-
// then its voided
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
const type = first.parseType(input.scope.getRegistry());
|
|
312
|
-
if (type instanceof basic_1.VoidType || type instanceof basic_1.UnknownType) {
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
if (!(type instanceof basic_1.StructureType)) {
|
|
316
|
-
const message = "checkFields, expected structure, " + type.constructor.name;
|
|
317
|
-
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
for (const field of fields) {
|
|
321
|
-
if (field.code === "*") {
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
if (isSimple.test(field.code) && type.getComponentByName(field.code) === undefined) {
|
|
325
|
-
const message = `checkFields, field ${field.code} not found`;
|
|
326
|
-
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
303
|
static countResultType(scope) {
|
|
332
304
|
if ((0, version_1.releaseAtLeast)(scope.getRelease(), version_1.Release.v750)
|
|
333
305
|
|| scope.getOpenABAP()
|
|
@@ -38,6 +38,7 @@ const Expressions = __importStar(require("../../2_statements/expressions"));
|
|
|
38
38
|
const source_1 = require("../expressions/source");
|
|
39
39
|
const dynamic_1 = require("../expressions/dynamic");
|
|
40
40
|
const database_table_1 = require("../expressions/database_table");
|
|
41
|
+
const _check_database_fields_1 = require("../expressions/_check_database_fields");
|
|
41
42
|
class DeleteDatabase {
|
|
42
43
|
runSyntax(node, input) {
|
|
43
44
|
for (const s of node.findAllExpressions(Expressions.Source)) {
|
|
@@ -51,7 +52,14 @@ class DeleteDatabase {
|
|
|
51
52
|
}
|
|
52
53
|
const dbtab = node.findFirstExpression(Expressions.DatabaseTable);
|
|
53
54
|
if (dbtab !== undefined) {
|
|
54
|
-
database_table_1.DatabaseTable.runSyntax(dbtab, input);
|
|
55
|
+
const dbSource = database_table_1.DatabaseTable.runSyntax(dbtab, input);
|
|
56
|
+
const fields = node.findAllExpressions(Expressions.SQLCompare)
|
|
57
|
+
.map(compare => { var _a; return (_a = compare.findDirectExpression(Expressions.SQLFieldName)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase(); })
|
|
58
|
+
.filter(field => field !== undefined);
|
|
59
|
+
for (const orderBy of node.findAllExpressions(Expressions.SQLOrderBy)) {
|
|
60
|
+
fields.push(...orderBy.findAllExpressions(Expressions.SQLFieldName).map(field => field.concatTokens().toUpperCase()));
|
|
61
|
+
}
|
|
62
|
+
(0, _check_database_fields_1.checkDatabaseFields)(fields, [dbSource], input, node.getFirstToken());
|
|
55
63
|
}
|
|
56
64
|
}
|
|
57
65
|
}
|
|
@@ -42,11 +42,19 @@ const _typed_identifier_1 = require("../../types/_typed_identifier");
|
|
|
42
42
|
const identifier_1 = require("../../1_lexer/tokens/identifier");
|
|
43
43
|
const database_table_1 = require("../expressions/database_table");
|
|
44
44
|
const dynamic_1 = require("../expressions/dynamic");
|
|
45
|
+
const _check_database_fields_1 = require("../expressions/_check_database_fields");
|
|
45
46
|
class UpdateDatabase {
|
|
46
47
|
runSyntax(node, input) {
|
|
47
48
|
const dbtab = node.findFirstExpression(Expressions.DatabaseTable);
|
|
48
49
|
if (dbtab !== undefined) {
|
|
49
|
-
database_table_1.DatabaseTable.runSyntax(dbtab, input);
|
|
50
|
+
const dbSource = database_table_1.DatabaseTable.runSyntax(dbtab, input);
|
|
51
|
+
const fields = node.findAllExpressions(Expressions.SQLFieldAndValue)
|
|
52
|
+
.flatMap(fieldAndValue => fieldAndValue.findDirectExpressions(Expressions.SQLFieldName))
|
|
53
|
+
.map(field => field.concatTokens().toUpperCase());
|
|
54
|
+
fields.push(...node.findAllExpressions(Expressions.SQLCompare)
|
|
55
|
+
.map(compare => { var _a; return (_a = compare.findDirectExpression(Expressions.SQLFieldName)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase(); })
|
|
56
|
+
.filter(field => field !== undefined));
|
|
57
|
+
(0, _check_database_fields_1.checkDatabaseFields)(fields, [dbSource], input, node.getFirstToken());
|
|
50
58
|
}
|
|
51
59
|
const tableName = node.findDirectExpression(Expressions.DatabaseTable);
|
|
52
60
|
const tokenName = tableName === null || tableName === void 0 ? void 0 : tableName.getFirstToken();
|
|
@@ -38,6 +38,7 @@ const _abstract_object_1 = require("./_abstract_object");
|
|
|
38
38
|
const ddic_1 = require("../ddic");
|
|
39
39
|
const Types = __importStar(require("../abap/types/basic"));
|
|
40
40
|
const xml_utils_1 = require("../xml_utils");
|
|
41
|
+
const domain_1 = require("./domain");
|
|
41
42
|
class DataElement extends _abstract_object_1.AbstractObject {
|
|
42
43
|
constructor() {
|
|
43
44
|
super(...arguments);
|
|
@@ -68,6 +69,22 @@ class DataElement extends _abstract_object_1.AbstractObject {
|
|
|
68
69
|
this.parse();
|
|
69
70
|
return (_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.domname;
|
|
70
71
|
}
|
|
72
|
+
/** parseType() cannot distinguish DEC, CURR, and QUAN because they all become PackedType.
|
|
73
|
+
* Return the original DDIC datatype instead, resolving domain-backed data elements when possible. */
|
|
74
|
+
getDataType(reg) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
this.parse();
|
|
77
|
+
if ((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype) {
|
|
78
|
+
return this.parsedXML.datatype;
|
|
79
|
+
}
|
|
80
|
+
if (reg && ((_b = this.parsedXML) === null || _b === void 0 ? void 0 : _b.refkind) === "D" && this.parsedXML.domname) {
|
|
81
|
+
const domain = reg.getObject("DOMA", this.parsedXML.domname);
|
|
82
|
+
if (domain instanceof domain_1.Domain) {
|
|
83
|
+
return domain.getDataType();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
71
88
|
getTexts() {
|
|
72
89
|
var _a;
|
|
73
90
|
this.parse();
|
|
@@ -50,6 +50,11 @@ class Domain extends _abstract_object_1.AbstractObject {
|
|
|
50
50
|
var _a;
|
|
51
51
|
return (_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.conversionExit;
|
|
52
52
|
}
|
|
53
|
+
getDataType() {
|
|
54
|
+
var _a;
|
|
55
|
+
this.parse();
|
|
56
|
+
return (_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype;
|
|
57
|
+
}
|
|
53
58
|
getAllowedNaming() {
|
|
54
59
|
return {
|
|
55
60
|
maxLength: 30,
|
package/build/src/registry.js
CHANGED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CDSCheckSyntax = exports.CDSCheckSyntaxConf = void 0;
|
|
4
|
+
const nodes_1 = require("../abap/nodes");
|
|
5
|
+
const basic_1 = require("../abap/types/basic");
|
|
6
|
+
const expressions_1 = require("../cds/expressions");
|
|
7
|
+
const ddic_1 = require("../ddic");
|
|
8
|
+
const issue_1 = require("../issue");
|
|
9
|
+
const objects_1 = require("../objects");
|
|
10
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
11
|
+
const _irule_1 = require("./_irule");
|
|
12
|
+
class CDSCheckSyntaxConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
13
|
+
}
|
|
14
|
+
exports.CDSCheckSyntaxConf = CDSCheckSyntaxConf;
|
|
15
|
+
const KNOWN_QUAN_DATA_ELEMENTS = ["MENGE_D"];
|
|
16
|
+
const KNOWN_CURR_DATA_ELEMENTS = ["BWERT", "DZWERT"];
|
|
17
|
+
class CDSCheckSyntax {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.conf = new CDSCheckSyntaxConf();
|
|
20
|
+
}
|
|
21
|
+
getMetadata() {
|
|
22
|
+
return {
|
|
23
|
+
key: "cds_check_syntax",
|
|
24
|
+
title: "CDS Check Syntax",
|
|
25
|
+
shortDescription: "Checks CDS source, field, type, and semantic annotation references",
|
|
26
|
+
extendedInformation: `Performs semantic checks which require other DDIC objects to be available.
|
|
27
|
+
|
|
28
|
+
Missing objects are only reported when their names match the configured errorNamespace.`,
|
|
29
|
+
tags: [_irule_1.RuleTag.Syntax],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
getConfig() {
|
|
33
|
+
return this.conf;
|
|
34
|
+
}
|
|
35
|
+
setConfig(conf) {
|
|
36
|
+
this.conf = conf;
|
|
37
|
+
}
|
|
38
|
+
initialize(reg) {
|
|
39
|
+
this.reg = reg;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
run(object) {
|
|
43
|
+
if (!(object instanceof objects_1.DataDefinition)) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
const tree = object.getTree();
|
|
47
|
+
const file = object.findSourceFile();
|
|
48
|
+
if (tree === undefined || file === undefined) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
const issues = [];
|
|
52
|
+
const ddic = new ddic_1.DDIC(this.reg);
|
|
53
|
+
const sources = this.findSources(tree, ddic, issues, file);
|
|
54
|
+
this.checkRelations(tree, ddic, issues, file);
|
|
55
|
+
this.checkTypes(tree, ddic, issues, file);
|
|
56
|
+
this.checkRootProjection(tree, ddic, issues, file);
|
|
57
|
+
this.checkFieldAnnotations(tree, ddic, issues, file);
|
|
58
|
+
this.checkFields(tree, sources, object, issues, file);
|
|
59
|
+
return issues;
|
|
60
|
+
}
|
|
61
|
+
findSources(tree, ddic, issues, file) {
|
|
62
|
+
var _a;
|
|
63
|
+
const sources = [];
|
|
64
|
+
for (const node of tree.findAllExpressionsRecursive(expressions_1.CDSSource)) {
|
|
65
|
+
const prefixed = node.findDirectExpression(expressions_1.CDSPrefixedName);
|
|
66
|
+
const entityNode = prefixed === null || prefixed === void 0 ? void 0 : prefixed.findDirectExpression(expressions_1.CDSName);
|
|
67
|
+
if (entityNode === undefined) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const entity = this.name(entityNode);
|
|
71
|
+
const asName = (_a = node.findDirectExpression(expressions_1.CDSAs)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(expressions_1.CDSName);
|
|
72
|
+
const bareAlias = node.findDirectExpression(expressions_1.CDSName);
|
|
73
|
+
const alias = asName === undefined ? bareAlias : asName;
|
|
74
|
+
const lookup = ddic.lookupTableOrView(entity);
|
|
75
|
+
if (lookup.type instanceof basic_1.UnknownType && lookup.object === undefined && this.reg.inErrorNamespace(entity)) {
|
|
76
|
+
issues.push(issue_1.Issue.atToken(file, entityNode.getFirstToken(), `CDS source "${entity}" not found`, this.getMetadata().key, this.conf.severity));
|
|
77
|
+
}
|
|
78
|
+
if (lookup.type instanceof basic_1.StructureType || lookup.type instanceof basic_1.UnknownType || lookup.type instanceof basic_1.VoidType) {
|
|
79
|
+
const names = [entity.toUpperCase()];
|
|
80
|
+
if (alias) {
|
|
81
|
+
names.push(this.name(alias).toUpperCase());
|
|
82
|
+
}
|
|
83
|
+
sources.push({ entity, names, type: lookup.type });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return sources;
|
|
87
|
+
}
|
|
88
|
+
checkRelations(tree, ddic, issues, file) {
|
|
89
|
+
for (const relation of tree.findAllExpressionsRecursive(expressions_1.CDSRelation)) {
|
|
90
|
+
const directTokens = relation.getDirectTokens();
|
|
91
|
+
if (directTokens.length === 0) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const entity = directTokens.map(t => t.getStr()).join("");
|
|
95
|
+
const lookup = ddic.lookupTableOrView(entity);
|
|
96
|
+
if (lookup.type instanceof basic_1.UnknownType && lookup.object === undefined && this.reg.inErrorNamespace(entity)) {
|
|
97
|
+
issues.push(issue_1.Issue.atToken(file, directTokens[0], `CDS source "${entity}" not found`, this.getMetadata().key, this.conf.severity));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
checkTypes(tree, ddic, issues, file) {
|
|
102
|
+
for (const typeNode of tree.findAllExpressionsRecursive(expressions_1.CDSType)) {
|
|
103
|
+
const typeName = typeNode.findDirectExpressions(expressions_1.CDSName).map(n => this.name(n)).join(".");
|
|
104
|
+
if (typeName === "" || typeName.toUpperCase().startsWith("ABAP.")) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const lookup = ddic.lookup(typeName);
|
|
108
|
+
if (lookup.type instanceof basic_1.UnknownType && lookup.object === undefined && this.reg.inErrorNamespace(typeName)) {
|
|
109
|
+
issues.push(issue_1.Issue.atToken(file, typeNode.getFirstToken(), `CDS type "${typeName}" not found`, this.getMetadata().key, this.conf.severity));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
checkRootProjection(tree, ddic, issues, file) {
|
|
114
|
+
var _a;
|
|
115
|
+
const projection = tree.findFirstExpression(expressions_1.CDSDefineProjection);
|
|
116
|
+
const rootToken = projection === null || projection === void 0 ? void 0 : projection.findDirectTokenByText("ROOT");
|
|
117
|
+
if (projection === undefined || rootToken === undefined) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const names = projection.findDirectExpressions(expressions_1.CDSName);
|
|
121
|
+
const projectedEntityNode = names[1];
|
|
122
|
+
if (projectedEntityNode === undefined) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const projectedEntityName = this.name(projectedEntityNode);
|
|
126
|
+
const projectedEntity = ddic.lookupTableOrView(projectedEntityName).object;
|
|
127
|
+
if (projectedEntity instanceof objects_1.DataDefinition
|
|
128
|
+
&& ((_a = projectedEntity.getTree()) === null || _a === void 0 ? void 0 : _a.findDirectTokenByText("ROOT")) === undefined) {
|
|
129
|
+
const message = `ROOT keyword not valid since ${projectedEntityName} is not a root property`;
|
|
130
|
+
issues.push(issue_1.Issue.atToken(file, rootToken, message, this.getMetadata().key, this.conf.severity));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
checkFieldAnnotations(tree, ddic, issues, file) {
|
|
134
|
+
const definition = tree.findFirstExpression(expressions_1.CDSDefineAbstract);
|
|
135
|
+
if (definition === undefined) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
let definitionNameSeen = false;
|
|
139
|
+
let fieldName;
|
|
140
|
+
let annotations = [];
|
|
141
|
+
const fields = [];
|
|
142
|
+
for (const child of definition.getChildren()) {
|
|
143
|
+
if (child instanceof nodes_1.TokenNode) {
|
|
144
|
+
if (child.get().getStr() === ";") {
|
|
145
|
+
fieldName = undefined;
|
|
146
|
+
annotations = [];
|
|
147
|
+
}
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
else if (child.get() instanceof expressions_1.CDSAnnotation) {
|
|
151
|
+
annotations.push(child);
|
|
152
|
+
}
|
|
153
|
+
else if (child.get() instanceof expressions_1.CDSName) {
|
|
154
|
+
if (definitionNameSeen === false) {
|
|
155
|
+
definitionNameSeen = true;
|
|
156
|
+
annotations = [];
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
fieldName = child;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (child.get() instanceof expressions_1.CDSType && fieldName !== undefined) {
|
|
163
|
+
const semanticType = this.determineSemanticType(child, ddic);
|
|
164
|
+
const normalizedAnnotations = annotations.map(a => a.concatTokens().replace(/\s/g, ""));
|
|
165
|
+
fields.push({ name: this.name(fieldName), node: fieldName, annotations: normalizedAnnotations, semanticType });
|
|
166
|
+
fieldName = undefined;
|
|
167
|
+
annotations = [];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const reportedCompanionFields = new Set();
|
|
171
|
+
for (const field of fields) {
|
|
172
|
+
if (field.semanticType === undefined) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const quantity = field.semanticType === "QUAN";
|
|
176
|
+
const referenceAnnotation = quantity ? "@Semantics.quantity.unitOfMeasure" : "@Semantics.amount.currencyCode";
|
|
177
|
+
const companionAnnotation = quantity ? "@Semantics.unitOfMeasure: true" : "@Semantics.currencyCode: true";
|
|
178
|
+
const reference = this.findSemanticReference(field.annotations, field.semanticType);
|
|
179
|
+
if (reference === undefined) {
|
|
180
|
+
const kind = quantity ? "quantity" : "amount";
|
|
181
|
+
const message = `CDS ${kind} field "${field.name}" requires ${referenceAnnotation}`;
|
|
182
|
+
issues.push(issue_1.Issue.atToken(file, field.node.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const companion = fields.find(f => f.name.toUpperCase() === reference.toUpperCase());
|
|
186
|
+
if (companion === undefined) {
|
|
187
|
+
const kind = quantity ? "unit" : "currency";
|
|
188
|
+
const message = `CDS field "${field.name}" references missing ${kind} field "${reference}"`;
|
|
189
|
+
issues.push(issue_1.Issue.atToken(file, field.node.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const companionKey = field.semanticType + ":" + companion.name.toUpperCase();
|
|
193
|
+
if (reportedCompanionFields.has(companionKey) === false
|
|
194
|
+
&& this.hasCompanionAnnotation(companion.annotations, field.semanticType) === false) {
|
|
195
|
+
const message = `CDS field "${companion.name}" requires ${companionAnnotation}`;
|
|
196
|
+
issues.push(issue_1.Issue.atToken(file, companion.node.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
|
|
197
|
+
reportedCompanionFields.add(companionKey);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
determineSemanticType(typeNode, ddic) {
|
|
202
|
+
var _a;
|
|
203
|
+
const typeName = typeNode.findDirectExpressions(expressions_1.CDSName).map(n => this.name(n)).join(".");
|
|
204
|
+
const upper = typeName.toUpperCase();
|
|
205
|
+
if (upper === "ABAP.QUAN" || KNOWN_QUAN_DATA_ELEMENTS.includes(upper)) {
|
|
206
|
+
return "QUAN";
|
|
207
|
+
}
|
|
208
|
+
else if (upper === "ABAP.CURR" || KNOWN_CURR_DATA_ELEMENTS.includes(upper)) {
|
|
209
|
+
return "CURR";
|
|
210
|
+
}
|
|
211
|
+
const object = ddic.lookup(typeName).object;
|
|
212
|
+
if (object instanceof objects_1.DataElement) {
|
|
213
|
+
const dataType = (_a = object.getDataType(this.reg)) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
214
|
+
if (dataType === "QUAN" || dataType === "CURR") {
|
|
215
|
+
return dataType;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
findSemanticReference(annotations, type) {
|
|
221
|
+
const expression = type === "QUAN"
|
|
222
|
+
? /(?:SEMANTICS\.QUANTITY|SEMANTICS:\{QUANTITY:\{)\.?UNITOFMEASURE:'([^']+)'/i
|
|
223
|
+
: /(?:SEMANTICS\.AMOUNT|SEMANTICS:\{AMOUNT:\{)\.?CURRENCYCODE:'([^']+)'/i;
|
|
224
|
+
for (const annotation of annotations) {
|
|
225
|
+
const match = annotation.match(expression);
|
|
226
|
+
if (match) {
|
|
227
|
+
return match[1];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
hasCompanionAnnotation(annotations, type) {
|
|
233
|
+
if (type === "QUAN") {
|
|
234
|
+
return annotations.some(a => a.toUpperCase().includes("@SEMANTICS.UNITOFMEASURE:TRUE")
|
|
235
|
+
|| a.toUpperCase().includes("@SEMANTICS:{UNITOFMEASURE:TRUE"));
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
return annotations.some(a => a.toUpperCase().includes("@SEMANTICS.CURRENCYCODE:TRUE")
|
|
239
|
+
|| a.toUpperCase().includes("@SEMANTICS:{CURRENCYCODE:TRUE"));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
checkFields(tree, sources, object, issues, file) {
|
|
243
|
+
var _a;
|
|
244
|
+
const associationNames = new Set();
|
|
245
|
+
for (const association of ((_a = object.getParsedData()) === null || _a === void 0 ? void 0 : _a.associations) || []) {
|
|
246
|
+
associationNames.add(association.name.toUpperCase());
|
|
247
|
+
if (association.as) {
|
|
248
|
+
associationNames.add(association.as.toUpperCase());
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const element of tree.findAllExpressionsRecursive(expressions_1.CDSElement)) {
|
|
252
|
+
const prefixed = element.findDirectExpression(expressions_1.CDSPrefixedName);
|
|
253
|
+
if (prefixed === undefined) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const names = prefixed.findDirectExpressions(expressions_1.CDSName);
|
|
257
|
+
if (names.length === 0) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const first = this.name(names[0]);
|
|
261
|
+
if (first === "*" || first.startsWith("$") || first.startsWith("#") || associationNames.has(first.toUpperCase())) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (names.length > 1) {
|
|
265
|
+
const matchingSources = sources.filter(s => s.names.includes(first.toUpperCase()));
|
|
266
|
+
if (matchingSources.length !== 1) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const source = matchingSources[0];
|
|
270
|
+
const sourceType = source.type;
|
|
271
|
+
if (!(sourceType instanceof basic_1.StructureType)) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const field = this.name(names[1]);
|
|
275
|
+
if (field !== "*" && sourceType.getComponentByName(field) === undefined) {
|
|
276
|
+
issues.push(issue_1.Issue.atToken(file, names[1].getFirstToken(), `CDS field "${field}" not found in "${source.entity}"`, this.getMetadata().key, this.conf.severity));
|
|
277
|
+
}
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
// Do not guess across joins or when a dependency is absent.
|
|
281
|
+
if (sources.length !== 1) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const source = sources[0];
|
|
285
|
+
const sourceType = source.type;
|
|
286
|
+
if (!(sourceType instanceof basic_1.StructureType)) {
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (sourceType.getComponentByName(first) === undefined) {
|
|
290
|
+
issues.push(issue_1.Issue.atToken(file, names[0].getFirstToken(), `CDS field "${first}" not found in "${source.entity}"`, this.getMetadata().key, this.conf.severity));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
name(node) {
|
|
295
|
+
return node.concatTokens().replace(/ /g, "");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.CDSCheckSyntax = CDSCheckSyntax;
|
|
299
|
+
//# sourceMappingURL=cds_check_syntax.js.map
|
package/build/src/rules/index.js
CHANGED
|
@@ -30,6 +30,7 @@ __exportStar(require("./begin_single_include"), exports);
|
|
|
30
30
|
__exportStar(require("./call_transaction_authority_check"), exports);
|
|
31
31
|
__exportStar(require("./catch_and_raise"), exports);
|
|
32
32
|
__exportStar(require("./cds_association_name"), exports);
|
|
33
|
+
__exportStar(require("./cds_check_syntax"), exports);
|
|
33
34
|
__exportStar(require("./cds_comment_style"), exports);
|
|
34
35
|
__exportStar(require("./cds_field_order"), exports);
|
|
35
36
|
__exportStar(require("./cds_legacy_view"), exports);
|