ern-api-gen
Version:
Electrode Native API generator
62 lines • 2.15 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* tslint:disable:variable-name */
const ObjectUtils_1 = __importDefault(require("./java/ObjectUtils"));
const ComposedModel_1 = __importDefault(require("./models/ComposedModel"));
class InheritanceTreeSorter {
constructor(__parent, definitions) {
this.definitions = definitions;
this.__parent = __parent;
}
compare(o1, o2) {
const model1 = this.definitions.get(o1);
const model2 = this.definitions.get(o2);
const model1InheritanceDepth = this.getInheritanceDepth(model1);
const model2InheritanceDepth = this.getInheritanceDepth(model2);
if (model1InheritanceDepth === model2InheritanceDepth) {
const cmp = ObjectUtils_1.default.compare(this.__parent.config.toModelName(o1), this.__parent.config.toModelName(o2));
if (cmp === -1) {
return -1;
}
if (cmp === 1) {
return 1;
}
if (cmp === true) {
return -1;
}
if (cmp === false) {
return 1;
}
return cmp;
}
else if (model1InheritanceDepth > model2InheritanceDepth) {
return 1;
}
else {
return -1;
}
}
getInheritanceDepth(model) {
let inheritanceDepth = 0;
let parent = this.getParent(model);
while (parent != null) {
inheritanceDepth++;
parent = this.getParent(parent);
}
return inheritanceDepth;
}
getParent(model) {
if (model != null && model instanceof ComposedModel_1.default) {
const parent = model.getParent();
if (parent != null) {
return this.definitions.get(parent.getReference());
}
}
return null;
}
}
exports.InheritanceTreeSorter = InheritanceTreeSorter;
//# sourceMappingURL=InheritanceTreeSorter.js.map