UNPKG

@abaplint/core

Version:
68 lines 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CheckAbstract = exports.CheckAbstractConf = void 0; 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"); class CheckAbstractConf extends _basic_rule_config_1.BasicRuleConfig { } exports.CheckAbstractConf = CheckAbstractConf; var IssueType; (function (IssueType) { /** Abstract method defined in non-abstract class */ IssueType[IssueType["NotAbstractClass"] = 0] = "NotAbstractClass"; IssueType[IssueType["AbstractAndFinal"] = 1] = "AbstractAndFinal"; })(IssueType || (IssueType = {})); class CheckAbstract extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new CheckAbstractConf(); } getMetadata() { return { key: "check_abstract", title: "Check abstract methods and classes", shortDescription: `Checks abstract methods and classes: - class defined as abstract and final, - non-abstract class contains abstract methods`, extendedInformation: `If a class defines only constants, use an interface instead`, tags: [_irule_1.RuleTag.SingleFile], }; } getDescription(issueType, name) { switch (issueType) { case IssueType.AbstractAndFinal: return "Classes should not be ABSTRACT and FINAL: " + name; case IssueType.NotAbstractClass: return "Abstract methods require abstract classes: " + name; default: return ""; } } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { const issues = []; for (const classDef of file.getInfo().listClassDefinitions()) { if (classDef.isAbstract === true) { if (classDef.isFinal === true && classDef.isForTesting === false) { issues.push(issue_1.Issue.atIdentifier(classDef.identifier, this.getDescription(IssueType.AbstractAndFinal, classDef.name), this.getMetadata().key, this.conf.severity)); } continue; } for (const methodDef of classDef.methods) { if (methodDef.isAbstract === true) { issues.push(issue_1.Issue.atIdentifier(methodDef.identifier, this.getDescription(IssueType.NotAbstractClass, methodDef.name), this.getMetadata().key, this.conf.severity)); } } } return issues; } } exports.CheckAbstract = CheckAbstract; //# sourceMappingURL=check_abstract.js.map