UNPKG

@abaplint/core

Version:
111 lines 3.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractObject = void 0; const fast_xml_parser_1 = require("fast-xml-parser"); const _identifier_1 = require("../abap/4_file_information/_identifier"); const identifier_1 = require("../abap/1_lexer/tokens/identifier"); const position_1 = require("../position"); class AbstractObject { constructor(name) { this.name = name; this.files = []; this.old = []; this.dirty = false; } getParsingIssues() { return this.old; } parse(_version, _globalMacros, _reg) { return { updated: false, runtime: 0 }; } getName() { return this.name; } setDirty() { this.dirty = true; } addFile(file) { this.setDirty(); this.files.push(file); } getFiles() { return this.files; } containsFile(filename) { for (const f of this.files) { if (f.getFilename() === filename) { return true; } } return false; } removeFile(file) { this.setDirty(); for (let i = 0; i < this.files.length; i++) { if (this.files[i].getFilename() === file.getFilename()) { this.files.splice(i, 1); return; } } throw new Error("removeFile: file not found"); } isDirty() { return this.dirty; } getIdentifier() { // this method can be redefined in each object type to give a better result const file = this.getXMLFile(); if (file === undefined) { return undefined; } return new _identifier_1.Identifier(new identifier_1.Identifier(new position_1.Position(1, 1), this.getName()), file.getFilename()); } getXMLFile() { // todo, https://github.com/abaplint/abaplint/issues/673 uris const expected1 = this.getName().toLowerCase().replace(/\//g, "#") + "." + this.getType().toLowerCase() + ".xml"; const expected2 = this.getName().toLowerCase().replace(/\//g, "%23") + "." + this.getType().toLowerCase() + ".xml"; for (const file of this.getFiles()) { if (file.getFilename().endsWith(expected1) || file.getFilename().endsWith(expected2)) { return file; } } // uri fallback, assume there is only one xml file for (const file of this.getFiles()) { if (file.getFilename().endsWith(".xml")) { return file; } } return undefined; } getXML() { const file = this.getXMLFile(); if (file) { return file.getRaw(); } return undefined; } updateFile(file) { this.setDirty(); for (let i = 0; i < this.files.length; i++) { if (this.files[i].getFilename() === file.getFilename()) { this.files[i] = file; return; } } throw new Error("updateFile: file not found"); } parseRaw2() { const xml = this.getXML(); if (xml === undefined) { return undefined; } try { return new fast_xml_parser_1.XMLParser({ parseTagValue: false, ignoreAttributes: true, trimValues: false }).parse(xml); } catch (_a) { return undefined; } } } exports.AbstractObject = AbstractObject; //# sourceMappingURL=_abstract_object.js.map