@abaplint/core
Version:
abaplint - Core API
92 lines • 3.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ABAPObject = void 0;
const _abstract_object_1 = require("./_abstract_object");
const xml_utils_1 = require("../xml_utils");
const abap_parser_1 = require("../abap/abap_parser");
class ABAPObject extends _abstract_object_1.AbstractObject {
[Symbol.for("debug.description")]() {
return `${this.constructor.name} ${this.getName()}`;
}
constructor(name) {
super(name);
this.parsed = [];
this.texts = undefined;
}
static is(x) {
return !!x && x instanceof ABAPObject;
}
parse(version, globalMacros, reg) {
if (this.isDirty() === false) {
return { updated: false, runtime: 0 };
}
const abapFiles = this.getFiles().filter(f => f.getFilename().endsWith(".abap"));
const result = new abap_parser_1.ABAPParser(version, globalMacros, reg).parse(abapFiles);
this.parsed = result.output;
this.old = result.issues;
this.dirty = false;
return { updated: true, runtime: result.runtime, runtimeExtra: result.runtimeExtra };
}
setDirty() {
this.syntaxResult = undefined;
this.texts = undefined;
super.setDirty();
}
getABAPFiles() {
return this.parsed;
}
getABAPFileByName(filename) {
for (const p of this.parsed) {
if (p.getFilename() === filename) {
return p;
}
}
return undefined;
}
getMainABAPFile() {
// todo, uris, https://github.com/abaplint/abaplint/issues/673
const search = this.getName().replace(/\//g, "#").toLowerCase() + "." + this.getType().toLowerCase() + ".abap";
for (const file of this.getABAPFiles()) {
if (file.getFilename().endsWith(search)) {
return file;
}
}
// uri fallback,
for (const file of this.getABAPFiles()) {
if (file.getFilename().includes(".prog.screen_")) {
continue;
}
else if (file.getFilename().endsWith(".abap")) {
return file;
}
}
return undefined;
}
getTexts() {
if (this.texts === undefined) {
this.findTexts(this.parseRaw2());
}
return this.texts;
}
findTexts(parsed) {
var _a, _b, _c, _d;
this.texts = {};
if (((_d = (_c = (_b = (_a = parsed === null || parsed === void 0 ? void 0 : parsed.abapGit) === null || _a === void 0 ? void 0 : _a["asx:abap"]) === null || _b === void 0 ? void 0 : _b["asx:values"]) === null || _c === void 0 ? void 0 : _c.TPOOL) === null || _d === void 0 ? void 0 : _d.item) === undefined) {
return;
}
for (const t of (0, xml_utils_1.xmlToArray)(parsed.abapGit["asx:abap"]["asx:values"].TPOOL.item)) {
if ((t === null || t === void 0 ? void 0 : t.ID) === "I") {
if (t.KEY === undefined) {
throw new Error("findTexts, undefined");
}
const key = t.KEY;
if (key === undefined) {
continue;
}
this.texts[key.toUpperCase()] = t.ENTRY ? (0, xml_utils_1.unescape)(t.ENTRY) : "";
}
}
}
}
exports.ABAPObject = ABAPObject;
//# sourceMappingURL=_abap_object.js.map