UNPKG

@abaplint/core

Version:
107 lines 4.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SuperclassFinal = exports.SuperclassFinalConf = void 0; const issue_1 = require("../issue"); const _abap_rule_1 = require("./_abap_rule"); const Objects = require("../objects"); const _basic_rule_config_1 = require("./_basic_rule_config"); const _irule_1 = require("./_irule"); const include_graph_1 = require("../utils/include_graph"); class SuperclassFinalConf extends _basic_rule_config_1.BasicRuleConfig { } exports.SuperclassFinalConf = SuperclassFinalConf; class SuperclassFinal extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new SuperclassFinalConf(); this.graph = undefined; } getMetadata() { return { key: "superclass_final", title: "Super class final", shortDescription: `Checks that classes which are inherited from are not declared as FINAL.`, tags: [_irule_1.RuleTag.Syntax], }; } getMessage() { return "Superclasses cannot be FINAL"; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file, obj) { const output = []; for (const definition of file.getInfo().listClassDefinitions()) { const sup = definition.superClassName; if (sup === undefined) { continue; } let localLookup = true; if (obj instanceof Objects.Class && file.getFilename().match(/\.clas\.abap$/)) { localLookup = false; } let found = undefined; if (localLookup) { for (const f of obj.getABAPFiles()) { found = f.getInfo().getClassDefinitionByName(sup); if (found !== undefined) { break; } } } if (found === undefined && obj instanceof Objects.Program) { found = this.findInRelatedProgramIncludes(file, sup); } if (found === undefined) { const clas = this.reg.getObject("CLAS", sup); if (clas) { found = clas.getClassDefinition(); } } if (found === undefined) { const message = "Super class \"" + sup + "\" not found"; const issue = issue_1.Issue.atIdentifier(definition.identifier, message, this.getMetadata().key, this.conf.severity); output.push(issue); continue; } if (found.isFinal === true) { const issue = issue_1.Issue.atIdentifier(definition.identifier, this.getMessage(), this.getMetadata().key, this.conf.severity); output.push(issue); } } return output; } findInRelatedProgramIncludes(file, superClassName) { if (this.graph === undefined) { this.graph = new include_graph_1.IncludeGraph(this.reg); } const mainFilenames = this.graph.listMainForInclude(file.getFilename()); if (mainFilenames.length === 0) { return undefined; } for (const object of this.reg.getObjectsByType("PROG")) { if (!(object instanceof Objects.Program)) { continue; } const programFile = object.getMainABAPFile(); if (programFile === undefined) { continue; } const programMainFilenames = this.graph.listMainForInclude(programFile.getFilename()); if (mainFilenames.some(filename => programMainFilenames.includes(filename)) === false) { continue; } const found = programFile.getInfo().getClassDefinitionByName(superClassName); if (found !== undefined) { return found; } } return undefined; } } exports.SuperclassFinal = SuperclassFinal; //# sourceMappingURL=superclass_final.js.map