all files / dist/definitions/base/ ModuledDefinition.js

99.11% Statements 111/112
96% Branches 24/25
100% Functions 32/32
99.03% Lines 102/103
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149  85× 85× 85× 85× 85× 85× 85×               13× 13× 13× 13×                   13×   17×   16×   15×   14×   13×   12×   11× 11×                       32×   71×   10×                    
"use strict";
var factories_1 = require("./../../factories");
var utils_1 = require("./../../utils");
var ModuledDefinition = (function () {
    function ModuledDefinition() {
        this.namespaces = [];
        this.classes = [];
        this.interfaces = [];
        this.enums = [];
        this.functions = [];
        this.variables = [];
        this.typeAliases = [];
    }
    // need to pass these in after initializing in order to prevent circular dependencies
    ModuledDefinition.initialize = function (instanceContainer) {
        this.instanceContainer = instanceContainer;
    };
    ModuledDefinition.prototype.addClass = function (structure) {
        var def = new factories_1.StructureFactory().getClass(structure);
        def.order = utils_1.DefinitionUtils.getNextOrderOfModule(this);
        this.classes.push(def);
        return def;
    };
    ModuledDefinition.prototype.addEnum = function (structure) {
        var def = new factories_1.StructureFactory().getEnum(structure);
        def.order = utils_1.DefinitionUtils.getNextOrderOfModule(this);
        this.enums.push(def);
        return def;
    };
    ModuledDefinition.prototype.addFunction = function (structure) {
        var def = new factories_1.StructureFactory().getFunction(structure);
        def.order = utils_1.DefinitionUtils.getNextOrderOfModule(this);
        this.functions.push(def);
        return def;
    };
    ModuledDefinition.prototype.addInterface = function (structure) {
        var def = new factories_1.StructureFactory().getInterface(structure);
        def.order = utils_1.DefinitionUtils.getNextOrderOfModule(this);
        this.interfaces.push(def);
        return def;
    };
    ModuledDefinition.prototype.addNamespace = function (structure) {
        var def = new factories_1.StructureFactory().getNamespace(structure);
        def.order = utils_1.DefinitionUtils.getNextOrderOfModule(this);
        this.namespaces.push(def);
        return def;
    };
    ModuledDefinition.prototype.addTypeAlias = function (structure) {
        var def = new factories_1.StructureFactory().getTypeAlias(structure);
        def.order = utils_1.DefinitionUtils.getNextOrderOfModule(this);
        this.typeAliases.push(def);
        return def;
    };
    ModuledDefinition.prototype.addVariable = function (structure) {
        var def = new factories_1.StructureFactory().getVariable(structure);
        def.order = utils_1.DefinitionUtils.getNextOrderOfModule(this);
        this.variables.push(def);
        return def;
    };
    ModuledDefinition.prototype.getClass = function (nameOrSearchFunction) {
        return utils_1.DefinitionUtils.getDefinitionFromListByNameOrFunc(this.classes, nameOrSearchFunction);
    };
    ModuledDefinition.prototype.getEnum = function (nameOrSearchFunction) {
        return utils_1.DefinitionUtils.getDefinitionFromListByNameOrFunc(this.enums, nameOrSearchFunction);
    };
    ModuledDefinition.prototype.getFunction = function (nameOrSearchFunction) {
        return utils_1.DefinitionUtils.getDefinitionFromListByNameOrFunc(this.functions, nameOrSearchFunction);
    };
    ModuledDefinition.prototype.getInterface = function (nameOrSearchFunction) {
        return utils_1.DefinitionUtils.getDefinitionFromListByNameOrFunc(this.interfaces, nameOrSearchFunction);
    };
    ModuledDefinition.prototype.getNamespace = function (nameOrSearchFunction) {
        return utils_1.DefinitionUtils.getDefinitionFromListByNameOrFunc(this.namespaces, nameOrSearchFunction);
    };
    ModuledDefinition.prototype.getTypeAlias = function (nameOrSearchFunction) {
        return utils_1.DefinitionUtils.getDefinitionFromListByNameOrFunc(this.typeAliases, nameOrSearchFunction);
    };
    ModuledDefinition.prototype.getVariable = function (nameOrSearchFunction) {
        return utils_1.DefinitionUtils.getDefinitionFromListByNameOrFunc(this.variables, nameOrSearchFunction);
    };
    ModuledDefinition.prototype.directlyContains = function (def) {
        if (def instanceof ModuledDefinition.instanceContainer.classType) {
            return this.getClass(function (d) { return d === def; }) != null;
        }
        else if (def instanceof ModuledDefinition.instanceContainer.functionType) {
            return this.getFunction(function (d) { return d === def; }) != null;
        }
        else if (def instanceof ModuledDefinition.instanceContainer.interfaceType) {
            return this.getInterface(function (d) { return d === def; }) != null;
        }
        else if (def instanceof ModuledDefinition.instanceContainer.namespaceType) {
            return this.getNamespace(function (d) { return d === def; }) != null;
        }
        else if (def instanceof ModuledDefinition.instanceContainer.enumType) {
            return this.getEnum(function (d) { return d === def; }) != null;
        }
        else if (def instanceof ModuledDefinition.instanceContainer.typeAliasType) {
            return this.getTypeAlias(function (d) { return d === def; }) != null;
        }
        else Eif (def instanceof ModuledDefinition.instanceContainer.variableType) {
            return this.getVariable(function (d) { return d === def; }) != null;
        }
        else {
            return false;
        }
    };
    ModuledDefinition.prototype.getNamespacesToDefinition = function (searchDef) {
        var foundInModule = this.directlyContains(searchDef);
        if (foundInModule) {
            return [];
        }
        else {
            for (var i = 0; i < this.namespaces.length; i++) {
                var path = this.namespaces[i].getNamespacesToDefinition(searchDef);
                if (path != null) {
                    return [this.namespaces[i]].concat(path);
                }
            }
            return null;
        }
    };
    ModuledDefinition.prototype.getExports = function () {
        return this.getMembers().filter(function (d) { return d.isNamedExportOfFile || d.isExported && !d.isDefaultExportOfFile; });
    };
    ModuledDefinition.prototype.getMembers = function () {
        return this.namespaces.concat(this.classes, this.interfaces, this.enums, this.functions, this.variables, this.typeAliases);
    };
    ModuledDefinition.prototype.setOrderOfMember = function (order, member) {
        var members = this.getMembers();
        order = Math.max(order, 0);
        if (!members.some(function (m) { return m === member; })) {
            throw new Error("The member '" + member.name + "' does not exist in this module.");
        }
        else {
            members.forEach(function (m) {
                if (m.order >= order) {
                    m.order++;
                }
            });
            member.order = order;
        }
        return this;
    };
    return ModuledDefinition;
}());
exports.ModuledDefinition = ModuledDefinition;
 
//# sourceMappingURL=ModuledDefinition.js.map