UNPKG

@abaplint/core

Version:
71 lines 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClassicExceptionsOverlap = exports.ClassicExceptionsOverlapConf = void 0; const issue_1 = require("../issue"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const Expressions = require("../abap/2_statements/expressions"); const _irule_1 = require("./_irule"); class ClassicExceptionsOverlapConf extends _basic_rule_config_1.BasicRuleConfig { } exports.ClassicExceptionsOverlapConf = ClassicExceptionsOverlapConf; class ClassicExceptionsOverlap extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new ClassicExceptionsOverlapConf(); } getMetadata() { return { key: "classic_exceptions_overlap", title: "Classic exceptions overlap when catching", shortDescription: `Find overlapping classic exceptions`, extendedInformation: `When debugging its typically good to know exactly which exception is caught`, tags: [_irule_1.RuleTag.SingleFile], badExample: `CALL FUNCTION 'SOMETHING' EXCEPTIONS system_failure = 1 MESSAGE lv_message communication_failure = 1 MESSAGE lv_message resource_failure = 1 OTHERS = 1.`, goodExample: `CALL FUNCTION 'SOMETHING' EXCEPTIONS system_failure = 1 MESSAGE lv_message communication_failure = 2 MESSAGE lv_message resource_failure = 3 OTHERS = 4.`, }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { var _a; const output = []; const struc = file.getStructure(); if (struc === undefined) { return []; // syntax error } for (const p of struc.findAllExpressions(Expressions.ParameterListExceptions)) { const set = new Set(); for (const e of p.findAllExpressions(Expressions.ParameterException)) { const text = (_a = e.findDirectExpression(Expressions.Integer)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase(); if (text === undefined) { continue; } if (set.has(text)) { const message = "Exception overlap, " + text; const issue = issue_1.Issue.atToken(file, e.getFirstToken(), message, this.getMetadata().key, this.getConfig().severity); output.push(issue); break; } set.add(text); } } return output; } } exports.ClassicExceptionsOverlap = ClassicExceptionsOverlap; //# sourceMappingURL=classic_exceptions_overlap.js.map