UNPKG

@abaplint/core

Version:
71 lines 3.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParserBadExceptions = exports.ParserBadExceptionsConf = void 0; const Statements = require("../abap/2_statements/statements"); 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"); // todo: this rule needs refactoring class ParserBadExceptionsConf extends _basic_rule_config_1.BasicRuleConfig { } exports.ParserBadExceptionsConf = ParserBadExceptionsConf; class ParserBadExceptions extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new ParserBadExceptionsConf(); } getMetadata() { return { key: "parser_bad_exceptions", title: "Parser Error, bad EXCEPTIONS in CALL FUNCTION", shortDescription: `Checks for syntax not recognized by abaplint, related to EXCEPTIONS in CALL FUNCTION.`, tags: [_irule_1.RuleTag.Syntax, _irule_1.RuleTag.SingleFile], }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { const issues = []; for (const statement of file.getStatements()) { if (!(statement.get() instanceof Statements.CallFunction)) { continue; } const exceptionTokens = this.findExceptionTokens(statement); if (exceptionTokens !== undefined && this.containsMixedExceptionSyntax(statement.findAllExpressions(Expressions.ParameterException))) { const message = "Bad EXCEPTIONS syntax in CALL FUNCTION"; for (const token of exceptionTokens) { issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity)); } continue; } for (const e of statement.findAllExpressions(Expressions.ParameterException)) { if (e.findDirectTokenByText("=") === undefined) { const message = "Bad EXCEPTIONS syntax in CALL FUNCTION"; issues.push(issue_1.Issue.atToken(file, e.getFirstToken(), message, this.getMetadata().key, this.conf.severity)); } } } return issues; } containsMixedExceptionSyntax(exceptions) { return exceptions.some(e => e.findDirectTokenByText("=") === undefined) && exceptions.some(e => e.findDirectTokenByText("=") !== undefined); } findExceptionTokens(statement) { const tokens = statement.getTokens(); const index = tokens.findIndex(t => t.getStr().toUpperCase() === "EXCEPTIONS"); if (index === -1) { return undefined; } return tokens.slice(index).filter(t => t.getStr() !== "."); } } exports.ParserBadExceptions = ParserBadExceptions; //# sourceMappingURL=parser_bad_exceptions.js.map