abapmerge
Version:
Merge ABAP INCLUDEs into single file
146 lines • 5.75 kB
JavaScript
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var graph_1 = __importDefault(require("./graph"));
var interface_parser_1 = __importDefault(require("./interface_parser"));
var class_parser_1 = require("./class_parser");
var ClassList = /** @class */ (function () {
function ClassList(list) {
this.interfaces = [];
this.classes = [];
this.exceptions = [];
this.testclasses = [];
this.parseFiles(list);
}
ClassList.prototype.getResult = function () {
return [
this.getDeferred(),
this.getExceptions(),
this.getInterfaces(),
this.getDefinitions(),
this.getImplementations(),
].join("");
};
ClassList.prototype.getDeferred = function () {
var classes = this.classes.reduce(function (a, c) { return "CLASS " + c.getName() + " DEFINITION DEFERRED.\n" + a; }, "");
var interfaces = this.interfaces.reduce(function (a, c) { return "INTERFACE " + c.getName() + " DEFERRED.\n" + a; }, "");
return interfaces + classes;
};
ClassList.prototype.getImplementations = function () {
return this.classes.reduce(function (a, c) { return c.getImplementation() + "\n" + a; }, "");
};
ClassList.prototype.getDefinitions = function () {
var g = this.buildDependenciesGraph(this.classes);
var result = "";
while (g.countNodes() > 0) {
var leaf = g.popLeaf();
result = result + leaf.getDefinition() + "\n";
}
return result;
};
ClassList.prototype.getExceptions = function () {
var g = this.buildDependenciesGraph(this.exceptions);
var result = "";
while (g.countNodes() > 0) {
var leaf = g.popLeaf();
result = result + leaf.getDefinition() + "\n" + leaf.getImplementation() + "\n";
}
return result;
};
ClassList.prototype.getInterfaces = function () {
var g = this.buildDependenciesGraph(this.interfaces);
var result = "";
while (g.countNodes() > 0) {
var leaf = g.popLeaf();
result = result + leaf.getDefinition() + "\n";
}
return result;
};
ClassList.prototype.buildDependenciesGraph = function (list) {
var e_1, _a, e_2, _b;
var g = new graph_1.default();
try {
for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
var c = list_1_1.value;
var className = c.getName();
g.addNode(className, c);
try {
for (var _c = (e_2 = void 0, __values(c.getDependencies())), _d = _c.next(); !_d.done; _d = _c.next()) {
var d = _d.value;
g.addEdge(className, d);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (list_1_1 && !list_1_1.done && (_a = list_1.return)) _a.call(list_1);
}
finally { if (e_1) throw e_1.error; }
}
return g;
};
ClassList.prototype.parseFiles = function (list) {
for (var i = 0; i < list.length(); i++) {
var f = list.get(i);
if (f.getFilename().match(/\.clas\.abap$/)) {
f.markUsed();
this.pushClass(f, list);
}
else if (f.getFilename().match(/\.clas\.testclasses\.abap$/)) {
f.markUsed();
}
else if (f.getFilename().match(/\.intf\.abap$/)) {
f.markUsed();
this.pushInterface(f);
}
}
if (this.testclasses.length) {
// patch after the fact, as we don't know if a class is a test class until we parse it
var remover = class_parser_1.ClassParser.createTestFriendsRemover(this.testclasses);
this.classes = this.classes.map(remover);
this.interfaces = this.interfaces.map(remover);
}
};
ClassList.prototype.pushClass = function (f, list) {
var cls = class_parser_1.ClassParser.parse(f, list);
if (cls.isForTesting() === true) {
this.testclasses.push(cls);
return; // skip global test classes
}
if (cls.getName().match(/^.?CX_/i)) {
// the DEFINITION DEFERRED does not work very well for exception classes
this.exceptions.push(cls);
}
else {
this.classes.push(cls);
}
};
ClassList.prototype.pushInterface = function (f) {
this.interfaces.push(interface_parser_1.default.parse(f));
};
return ClassList;
}());
exports.default = ClassList;
//# sourceMappingURL=class_list.js.map