@abaplint/core
Version:
abaplint - Core API
156 lines • 5.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.View = void 0;
const Types = require("../abap/types/basic");
const _abstract_object_1 = require("./_abstract_object");
const xml_utils_1 = require("../xml_utils");
const ddic_1 = require("../ddic");
var ViewClass;
(function (ViewClass) {
ViewClass["ExternalView"] = "X";
})(ViewClass || (ViewClass = {}));
class View extends _abstract_object_1.AbstractObject {
getType() {
return "VIEW";
}
getAllowedNaming() {
return {
maxLength: 16,
allowNamespace: true,
};
}
getFields() {
var _a;
if (this.parsedData === undefined) {
this.parseXML();
}
return (_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.fields;
}
getJoin() {
var _a;
if (this.parsedData === undefined) {
this.parseXML();
}
return (_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.join;
}
setDirty() {
this.parsedData = undefined;
super.setDirty();
}
parseType(reg) {
if (this.parsedData === undefined) {
this.parseXML();
}
if (this.parsedData === undefined) {
return new Types.UnknownType("View, parser error", this.getName());
}
const components = [];
const references = [];
const ddic = new ddic_1.DDIC(reg);
for (const field of this.parsedData.fields) {
if (field.VIEWFIELD === "*" || field.VIEWFIELD === "-") {
// ignore, this is a special case of old style .INCLUDE
continue;
}
else if (this.parsedData.header.VIEWCLASS === ViewClass.ExternalView) {
components.push({
name: field.VIEWFIELD,
type: Types.VoidType.get("ExternalView")
});
continue;
}
else if (field.TABNAME === this.getName()) {
throw new Error("Unexpected self reference in view " + this.getName() + ", " + field.FIELDNAME + " " + field.FIELDNAME);
}
const lookup = ddic.lookupTableOrView(field.TABNAME);
let found = lookup.type;
if (lookup.object) {
references.push({ object: lookup.object });
}
if (field.VIEWFIELD === ".APPEND") {
// it is already expanded in the abapGit xml
continue;
}
if (found instanceof Types.StructureType) {
const s = found.getComponentByName(field.FIELDNAME);
if (s === undefined) {
found = new Types.UnknownType(field.FIELDNAME + " not found in " + field.TABNAME + ", VIEW parse type");
}
else {
found = s;
}
}
components.push({
name: field.VIEWFIELD,
type: found
});
}
reg.getDDICReferences().setUsing(this, references);
if (components.length === 0) {
return new Types.UnknownType("View " + this.getName() + " does not contain any components");
}
return new Types.StructureType(components, this.getName());
}
listKeys() {
var _a;
if (this.parsedData === undefined) {
this.parseXML();
}
const ret = [];
for (const p of ((_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.fields) || []) {
if (p.KEYFLAG === "X") {
ret.push(p.FIELDNAME);
}
}
return ret;
}
getDescription() {
var _a;
if (this.parsedData === undefined) {
this.parseXML();
}
return (_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.header.DDTEXT;
}
///////////////
parseXML() {
var _a, _b, _c;
this.parsedData = {
header: {
VIEWCLASS: "",
DDTEXT: "",
},
fields: [],
join: [],
};
const parsed = super.parseRaw2();
if (parsed === undefined || parsed.abapGit === undefined) {
return;
}
const header = (_a = parsed.abapGit["asx:abap"]["asx:values"]) === null || _a === void 0 ? void 0 : _a.DD25V;
this.parsedData.header = {
VIEWCLASS: (header === null || header === void 0 ? void 0 : header.VIEWCLASS) || "",
DDTEXT: (header === null || header === void 0 ? void 0 : header.DDTEXT) || "",
};
const fields = (_b = parsed.abapGit["asx:abap"]["asx:values"]) === null || _b === void 0 ? void 0 : _b.DD27P_TABLE;
for (const field of (0, xml_utils_1.xmlToArray)(fields === null || fields === void 0 ? void 0 : fields.DD27P)) {
this.parsedData.fields.push({
VIEWFIELD: field.VIEWFIELD,
TABNAME: field.TABNAME,
FIELDNAME: field.FIELDNAME,
KEYFLAG: field.KEYFLAG,
});
}
const join = (_c = parsed.abapGit["asx:abap"]["asx:values"]) === null || _c === void 0 ? void 0 : _c.DD28J_TABLE;
for (const j of (0, xml_utils_1.xmlToArray)(join === null || join === void 0 ? void 0 : join.DD28J)) {
this.parsedData.join.push({
LTAB: j.LTAB,
LFIELD: j.LFIELD,
OPERATOR: j.OPERATOR,
RTAB: j.RTAB,
RFIELD: j.RFIELD,
});
}
}
}
exports.View = View;
//# sourceMappingURL=view.js.map