@abaplint/core
Version:
abaplint - Core API
110 lines • 4.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProxyObject = void 0;
const xml_utils_1 = require("../xml_utils");
const _abstract_object_1 = require("./_abstract_object");
const interface_1 = require("./interface");
const memory_file_1 = require("../files/memory_file");
class ProxyObject extends _abstract_object_1.AbstractObject {
getType() {
return "SPRX";
}
getAllowedNaming() {
return {
maxLength: 34,
allowNamespace: true,
};
}
getDescription() {
var _a;
this.parse();
const intfItem = (_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.proxyData.find(i => i.R3_TYPE === "INTF");
return intfItem === null || intfItem === void 0 ? void 0 : intfItem.R3_TEXT;
}
setDirty() {
this.parsedXML = undefined;
super.setDirty();
}
parse(_version, _globalMacros, reg) {
if (this.parsedXML) {
return { updated: false, runtime: 0 };
}
const start = Date.now();
this.parsedXML = this.parseXML();
const end = Date.now();
const objects = this.generateABAPObjects();
for (const obj of objects) {
reg === null || reg === void 0 ? void 0 : reg.addDependencies(obj.getFiles());
}
return { updated: true, runtime: end - start };
}
parseXML() {
var _a, _b;
const result = { proxyData: [] };
const parsed = super.parseRaw2();
if (parsed === undefined
|| parsed.abapGit === undefined
|| ((_a = parsed.abapGit["asx:abap"]) === null || _a === void 0 ? void 0 : _a["asx:values"]) === undefined) {
return result;
}
const values = parsed.abapGit["asx:abap"]["asx:values"];
result.proxyData = (0, xml_utils_1.xmlToArray)((_b = values.PROXY_DATA) === null || _b === void 0 ? void 0 : _b.item);
return result;
}
generateABAPObjects() {
var _a, _b, _c, _d, _e;
this.parse();
const result = [];
if (!this.parsedXML) {
return result;
}
// Find interface definition
const intfItem = this.parsedXML.proxyData.find(i => i.R3_TYPE === "INTF");
if (!intfItem || !intfItem.R3_NAME) {
return result;
}
const intfName = intfItem.R3_NAME.toLowerCase();
// Find methods
const methods = this.parsedXML.proxyData.filter(i => i.R3_TYPE === "METH");
// Build interface code
let code = `INTERFACE ${intfName} PUBLIC.\n`;
for (const method of methods) {
const methodName = (_a = method.R3_NAME) === null || _a === void 0 ? void 0 : _a.toLowerCase();
if (!methodName) {
continue;
}
// Find parameters for this method
const importingParameters = this.parsedXML.proxyData.filter(i => i.R3_TYPE === "PAIM" && i.OBJ_NAME1 === method.OBJ_NAME1);
const exportingParameters = this.parsedXML.proxyData.filter(i => i.R3_TYPE === "PAEX" && i.OBJ_NAME1 === method.OBJ_NAME1);
code += ` METHODS ${methodName}\n`;
if (importingParameters.length > 0) {
code += ` IMPORTING\n`;
for (let i = 0; i < importingParameters.length; i++) {
const param = importingParameters[i];
const paramName = (_b = param.OBJ_NAME2) === null || _b === void 0 ? void 0 : _b.toLowerCase();
const paramType = (_c = param.OBJ_NAME_R) === null || _c === void 0 ? void 0 : _c.toLowerCase();
const isLast = i === importingParameters.length - 1 && exportingParameters.length === 0;
code += ` ${paramName} TYPE ${paramType}${isLast ? "." : ""}\n`;
}
}
if (exportingParameters.length > 0) {
code += ` EXPORTING\n`;
for (let i = 0; i < exportingParameters.length; i++) {
const param = exportingParameters[i];
const paramName = (_d = param.OBJ_NAME2) === null || _d === void 0 ? void 0 : _d.toLowerCase();
const paramType = (_e = param.OBJ_NAME_R) === null || _e === void 0 ? void 0 : _e.toLowerCase();
const isLast = i === exportingParameters.length - 1;
code += ` ${paramName} TYPE ${paramType}${isLast ? "." : ""}\n`;
}
}
}
code += `ENDINTERFACE.`;
// Create the interface object
const intf = new interface_1.Interface(intfName.toUpperCase());
intf.addFile(new memory_file_1.MemoryFile(`${intfName}.intf.abap`, code));
result.push(intf);
return result;
}
}
exports.ProxyObject = ProxyObject;
//# sourceMappingURL=proxy_object.js.map