UNPKG

@abaplint/core

Version:
106 lines 4.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Parser702Chaining = exports.Parser702ChainingConf = void 0; const Expressions = require("../abap/2_statements/expressions"); const issue_1 = require("../issue"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const _irule_1 = require("./_irule"); const version_1 = require("../version"); const __1 = require(".."); class Parser702ChainingConf extends _basic_rule_config_1.BasicRuleConfig { } exports.Parser702ChainingConf = Parser702ChainingConf; class Parser702Chaining extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new Parser702ChainingConf(); } getMetadata() { return { key: "parser_702_chaining", title: "Parser Error, bad chaining on 702", shortDescription: `ABAP on 702 does not allow for method chaining with IMPORTING/EXPORTING/CHANGING keywords, this rule finds these and reports errors. Only active on target version 702 and below.`, tags: [_irule_1.RuleTag.Syntax, _irule_1.RuleTag.SingleFile], }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { const issues = []; if (this.reg.getConfig().getVersion() !== version_1.Version.v702 && this.reg.getConfig().getVersion() !== version_1.Version.v700) { return []; } const stru = file.getStructure(); if (stru === undefined) { return []; } for (const chain of stru.findAllExpressions(Expressions.MethodCallChain)) { const calls = chain.findDirectExpressions(Expressions.MethodCall); if (calls.length < 2) { continue; } for (const call of calls) { const callParam = call.findDirectExpression(Expressions.MethodCallParam); if (callParam === undefined) { continue; } const param = callParam.findDirectExpression(Expressions.MethodParameters); if (param === undefined) { continue; } if (param.findDirectTokenByText("IMPORTING") || param.findDirectTokenByText("CHANGING") || param.findDirectTokenByText("EXCEPTIONS")) { const message = "This kind of method chaining not possible in 702"; this.pushIssue(message, file, param, issues); } } } // after a value assignment (move statement whose source is a method call, or method parameter assignment), // there can't be any EXPORTING/IMPORTING/CHANGING/EXCEPTIONS for (const statement of file.getStatements()) { if (!(statement.get() instanceof __1.Statements.Move)) { continue; } const source = statement.findDirectExpression(Expressions.Source); if (source === undefined) { continue; } this.ensureSourceHasNoProceduralKeywords(source, file, issues); } for (const methodParameters of stru.findAllExpressions(Expressions.MethodParameters)) { for (const params of methodParameters.findAllExpressions(Expressions.ParameterS)) { const source = params.findDirectExpression(Expressions.Source); if (source === undefined) { continue; } this.ensureSourceHasNoProceduralKeywords(source, file, issues); } } return issues; } ensureSourceHasNoProceduralKeywords(source, file, issues) { const forbiddenTokens = ["EXPORTING", "IMPORTING", "CHANGING", "EXCEPTIONS"]; for (const param of source.findAllExpressions(Expressions.MethodParameters)) { const usedForbiddenToken = forbiddenTokens.find(text => param.findDirectTokenByText(text)); if (usedForbiddenToken) { const message = `Unexpected word ${usedForbiddenToken} in functional method call`; this.pushIssue(message, file, param, issues); } } } pushIssue(message, file, node, issues) { const issue = issue_1.Issue.atPosition(file, node.getFirstToken().getStart(), message, this.getMetadata().key, this.conf.severity); issues.push(issue); } } exports.Parser702Chaining = Parser702Chaining; //# sourceMappingURL=parser_702_chaining.js.map