@abaplint/core
Version:
abaplint - Core API
143 lines • 5.89 kB
JavaScript
"use strict";
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;
this.rawXMLCache = 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;
this.textsTranslations = undefined;
this.rawXMLCache = undefined;
this.parsed = [];
super.setDirty();
}
getParsedXML() {
var _a, _b;
if (this.rawXMLCache === undefined) {
this.rawXMLCache = (_a = this.parseRaw2()) !== null && _a !== void 0 ? _a : null;
}
return (_b = this.rawXMLCache) !== null && _b !== void 0 ? _b : undefined;
}
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;
}
getTextSymbols() {
var _a;
if (this.texts === undefined) {
this.findTexts(this.getParsedXML());
}
return (_a = this.texts["I"]) !== null && _a !== void 0 ? _a : {};
}
getTextElements() {
if (this.texts === undefined) {
this.findTexts(this.getParsedXML());
}
const result = {};
for (const elements of Object.values(this.texts)) {
Object.assign(result, elements);
}
return result;
}
getTextElementsTranslations() {
if (this.textsTranslations === undefined) {
this.findTextsTranslations(this.getParsedXML());
}
return this.textsTranslations;
}
findTexts(parsed) {
var _a, _b, _c, _d, _e, _f, _g;
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)) {
const id = (_e = t.ID) === null || _e === void 0 ? void 0 : _e.toUpperCase();
if (id === undefined) {
continue;
}
if (id !== "R" && t.KEY === undefined) {
continue;
}
const key = (_g = ((_f = t.KEY) !== null && _f !== void 0 ? _f : t.ID)) === null || _g === void 0 ? void 0 : _g.toUpperCase();
if (key === undefined) {
continue;
}
if (this.texts[id] === undefined) {
this.texts[id] = {};
}
this.texts[id][key] = { entry: t.ENTRY ? (0, xml_utils_1.unescape)(t.ENTRY) : "", maxLength: parseInt(t.LENGTH, 10) };
}
}
findTextsTranslations(parsed) {
var _a, _b, _c, _d, _e, _f, _g;
this.textsTranslations = [];
const values = (_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.I18N_TPOOL) === null || _d === void 0 ? void 0 : _d.item;
if (values === undefined) {
return;
}
for (const langItem of (0, xml_utils_1.xmlToArray)(values)) {
const textElements = {};
for (const item of (0, xml_utils_1.xmlToArray)((_e = langItem.TEXTPOOL) === null || _e === void 0 ? void 0 : _e.item)) {
const key = (_g = ((_f = item.KEY) !== null && _f !== void 0 ? _f : item.ID)) === null || _g === void 0 ? void 0 : _g.toUpperCase();
if (key !== undefined) {
textElements[key] = { entry: (0, xml_utils_1.unescape)(item.ENTRY), maxLength: parseInt(item.LENGTH, 10) };
}
}
this.textsTranslations.push({ language: langItem.LANGUAGE, textElements });
}
}
}
exports.ABAPObject = ABAPObject;
//# sourceMappingURL=_abap_object.js.map