UNPKG

@abaplint/core

Version:
179 lines 5.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FunctionGroup = void 0; const _abap_object_1 = require("./_abap_object"); const types_1 = require("../abap/types"); const xml_utils_1 = require("../xml_utils"); const fast_xml_parser_1 = require("fast-xml-parser"); const _dynpros_1 = require("./_dynpros"); class FunctionGroup extends _abap_object_1.ABAPObject { constructor() { super(...arguments); this.includes = undefined; this.modules = undefined; this.description = undefined; this.dynpros = undefined; } getType() { return "FUGR"; } getDescription() { if (this.description === undefined) { this.parseXML(); } return this.description; } setDirty() { super.setDirty(); this.includes = undefined; this.modules = undefined; } getAllowedNaming() { return { maxLength: 26, allowNamespace: true, }; } getDynpros() { if (this.dynpros === undefined) { this.parseXML(); } return this.dynpros || []; } getSequencedFiles() { const main = this.getMainABAPFile(); if (main === undefined) { return []; } const sequence = [main]; for (const m of this.getModules()) { const search = "." + m.getName().toLocaleLowerCase().replace(/\//g, "#") + ".abap"; for (const f of this.getABAPFiles()) { if (f.getFilename().toLocaleLowerCase().endsWith(search)) { if (sequence.indexOf(f) < 0) { sequence.push(f); } break; } } } return sequence; } getModules() { if (this.modules === undefined) { this.parseXML(); } if (this.modules === undefined) { throw new Error("getIncludes, undefined"); } return this.modules; } getIncludeFiles() { const ret = []; const includes = this.getIncludes(); for (const f of this.getABAPFiles()) { for (const i of includes) { const namespaced = i.startsWith("/") && i.includes("/L"); let search = i; if (namespaced) { search = search.replace(/\//g, "#"); } if ((i.startsWith("L") || namespaced) && f.getFilename().includes(search.toLowerCase() + ".")) { ret.push({ file: f, name: i }); break; } // fix for URL encoded? Uris if (namespaced) { search = i.replace(/\//g, "%23"); if (f.getFilename().includes(search.toLowerCase() + ".")) { ret.push({ file: f, name: i }); break; } } } } return ret; } getInclude(name) { const upper = name.toUpperCase(); const includes = this.getIncludeFiles(); for (const i of includes) { if (i.name.toUpperCase() === upper) { return i.file; } } return undefined; } getMainABAPFile() { const regex = new RegExp(/\.fugr\.(#\w+#)?sapl/, "i"); for (const f of this.getABAPFiles()) { if (regex.test(f.getFilename())) { return f; } } return undefined; } getIncludes() { if (this.includes === undefined) { this.parseXML(); } if (this.includes === undefined) { throw new Error("getIncludes, undefined"); } return this.includes; } getModule(name) { for (const mod of this.getModules()) { if (mod.getName().toUpperCase() === name.toUpperCase()) { return mod; } } return undefined; } getTexts() { if (this.texts === undefined) { const found = this.findTextFile(); if (found === undefined) { return {}; } const parsed = new fast_xml_parser_1.XMLParser({ parseTagValue: false, ignoreAttributes: true, trimValues: false }).parse(found.getRaw()); this.findTexts(parsed); } return this.texts; } ///////////////////////////////// parseXML() { var _a, _b, _c; this.includes = []; this.modules = []; const parsed = this.parseRaw2(); if (parsed === undefined) { return; } this.description = (_a = parsed.abapGit["asx:abap"]["asx:values"]) === null || _a === void 0 ? void 0 : _a.AREAT; this.dynpros = (0, _dynpros_1.parseDynpros)(parsed); // INCLUDES const includes = (_b = parsed.abapGit["asx:abap"]["asx:values"]) === null || _b === void 0 ? void 0 : _b.INCLUDES; if (includes !== undefined) { for (const i of (0, xml_utils_1.xmlToArray)(includes.SOBJ_NAME)) { this.includes.push(i); } } // FUNCTION MODULES const functions = (_c = parsed.abapGit["asx:abap"]["asx:values"]) === null || _c === void 0 ? void 0 : _c.FUNCTIONS; for (const module of (0, xml_utils_1.xmlToArray)(functions === null || functions === void 0 ? void 0 : functions.item)) { this.modules.push(new types_1.FunctionModuleDefinition(module)); } } findTextFile() { const search = this.getName() + ".fugr.sapl" + this.getName() + ".xml"; for (const f of this.getFiles()) { if (f.getFilename().includes(search.toLowerCase())) { return f; } } return undefined; } } exports.FunctionGroup = FunctionGroup; //# sourceMappingURL=function_group.js.map