UNPKG

@abaplint/core

Version:
89 lines 3.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DynproChecks = exports.DynproChecksConf = void 0; const issue_1 = require("../issue"); const _irule_1 = require("./_irule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const objects_1 = require("../objects"); const position_1 = require("../position"); class DynproChecksConf extends _basic_rule_config_1.BasicRuleConfig { } exports.DynproChecksConf = DynproChecksConf; class DynproChecks { constructor() { this.conf = new DynproChecksConf(); } getMetadata() { return { key: "dynpro_checks", title: "Dynpro Checks", shortDescription: `Various Dynpro checks`, extendedInformation: `* Check length of PUSH elements less than 132\n* Check for overlapping screen elements`, tags: [_irule_1.RuleTag.Syntax], }; } initialize(_reg) { return this; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } run(obj) { const ret = []; if (!(obj instanceof objects_1.Program)) { return []; } const file = obj.getXMLFile(); if (file === undefined) { return []; } for (const dynpro of obj.getDynpros()) { for (const field of dynpro.fields) { if (field.type === "PUSH" && field.length > 132) { const message = `Screen ${dynpro.number}, field ${field.name} LENGTH longer than 132`; ret.push(issue_1.Issue.atPosition(file, new position_1.Position(1, 1), message, this.getMetadata().key, this.getConfig().severity)); } } ret.push(...this.findOverlappingFields(dynpro, file)); } return ret; } findOverlappingFields(dynpro, file) { const ret = []; for (let index = 0; index < dynpro.fields.length; index++) { const current = dynpro.fields[index]; if (current.name === undefined || current.type === "FRAME") { continue; } for (let compare = index + 1; compare < dynpro.fields.length; compare++) { const other = dynpro.fields[compare]; if (other.name === undefined || other.type === "FRAME" || this.overlaps(current, other) === false) { continue; } const message = `Screen ${dynpro.number}, ${current.type} ${current.name} and ${other.type} ${other.name} are overlapping`; ret.push(issue_1.Issue.atPosition(file, new position_1.Position(1, 1), message, this.getMetadata().key, this.getConfig().severity)); } } return ret; } overlaps(first, second) { if (first.line === 0 || second.line === 0 || first.column === 0 || second.column === 0) { return false; } const firstHeight = Math.max(first.height, 1); const secondHeight = Math.max(second.height, 1); const firstLastLine = first.line + firstHeight - 1; const secondLastLine = second.line + secondHeight - 1; if (firstLastLine < second.line || secondLastLine < first.line) { return false; } const firstLastColumn = first.column + Math.max(first.vislength || first.length, 1) - 1; const secondLastColumn = second.column + Math.max(second.vislength || second.length, 1) - 1; return first.column <= secondLastColumn && second.column <= firstLastColumn; } } exports.DynproChecks = DynproChecks; //# sourceMappingURL=dynpro_checks.js.map