all files / dist/structure/ structureDefault.js

82.35% Statements 84/102
67.19% Branches 43/64
93.33% Functions 14/15
82.35% Lines 84/102
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  1× 1× 1× 1× 1× 1× 1× 1×   1× 516×         516×     516× 516×   16× 16× 16×     500×   500×   1× 258×   258× 258× 258× 84× 84×     84× 84×       84×   84×   174×   1×   1× 1× 1×   1× 1421×   1× 3359×     3359×     3359× 3359× 3359×   66×   3293×   81×   3212×   3×   3209×       3209×   309×   2900×   24×   2876×     2876×   1× 3359× 3359×   3359×   1× 1760× 1760× 1438× 322×   1× 1599× 1599× 1438× 161×   1×   1× 1× 1× 1× 1421×   1× 1×                   1× 227×   1× 203× 203× 203× 203×   1×  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var structureImpl = require("./structureImpl");
exports.parser = require("raml-1-parser");
var universes = exports.parser.universes;
var universeHelpers = exports.parser.universeHelpers;
var defaultInterfaces = require("./structureDefaultInterfaces");
var DefaultLabelProvider = (function () {
    function DefaultLabelProvider() {
    }
    DefaultLabelProvider.prototype.getLabelText = function (node) {
        Iif (node.isAttr()) {
            var attr = node;
            if (attr.value())
                return attr.name() + ":" + attr.value();
        }
        else Iif (node.isUnknown()) {
            return "Unknown";
        }
        var hlNode = node;
        if (hlNode.definition().key() === universes.Universe08.DocumentationItem
            || hlNode.definition().key() === universes.Universe10.DocumentationItem) {
            var titleAttribute = hlNode.attr("title");
            Eif (titleAttribute) {
                return titleAttribute.value();
            }
        }
        Iif (!node.lowLevel())
            return "";
        return node.name();
    };
    DefaultLabelProvider.prototype.getTypeText = function (node) {
        Iif (!node.isElement())
            return null;
        var hlNode = node;
        var typeAttribute = hlNode.attr("type");
        if (typeAttribute) {
            var typeValue = typeAttribute.value();
            Iif (typeValue == null) {
                typeValue = "";
            }
            var typeText = "";
            Iif (typeof typeValue === "object") {
                typeText = ":" + typeValue.valueName();
            }
            else {
                typeText = ":" + typeValue;
            }
            return typeText;
        }
        return null;
    };
    return DefaultLabelProvider;
}());
var DefaultDecorator = (function () {
    function DefaultDecorator() {
        this.decorations = {};
    }
    DefaultDecorator.prototype.addDecoration = function (nodeType, decoration) {
        this.decorations[nodeType] = decoration;
    };
    DefaultDecorator.prototype.getNodeType = function (node) {
        Iif (node.isAttr()) {
            return defaultInterfaces.NodeType.ATTRIBUTE;
        }
        else Iif (node.isUnknown()) {
            return defaultInterfaces.NodeType.UNKNOWN;
        }
        var hlNode = node;
        var nodeDefinition = hlNode.definition().key();
        if (nodeDefinition == universes.Universe08.Resource
            || nodeDefinition === universes.Universe10.Resource) {
            return defaultInterfaces.NodeType.RESOURCE;
        }
        else if (nodeDefinition === universes.Universe08.Method
            || nodeDefinition === universes.Universe10.Method) {
            return defaultInterfaces.NodeType.METHOD;
        }
        else if (nodeDefinition === universes.Universe08.AbstractSecurityScheme
            || nodeDefinition === universes.Universe10.AbstractSecurityScheme) {
            return defaultInterfaces.NodeType.SECURITY_SCHEME;
        }
        else Iif (nodeDefinition == universes.Universe10.TypeDeclaration
            && universeHelpers.isAnnotationTypesProperty(node.property())) {
            return defaultInterfaces.NodeType.ANNOTATION_DECLARATION;
        }
        else if (hlNode.definition().isAssignableFrom(universes.Universe10.TypeDeclaration.name) ||
            hlNode.definition().isAssignableFrom(universes.Universe08.Parameter.name)) {
            return defaultInterfaces.NodeType.TYPE_DECLARATION;
        }
        else if (nodeDefinition === universes.Universe08.DocumentationItem
            || nodeDefinition === universes.Universe10.DocumentationItem) {
            return defaultInterfaces.NodeType.DOCUMENTATION_ITEM;
        }
        Iif (node.lowLevel().unit() != node.root().lowLevel().unit()) {
            return defaultInterfaces.NodeType.EXTERNAL_UNIT;
        }
        return defaultInterfaces.NodeType.OTHER;
    };
    DefaultDecorator.prototype.getDecoration = function (node) {
        var nodeType = this.getNodeType(node);
        Iif (!nodeType)
            return null;
        return this.decorations[nodeType];
    };
    DefaultDecorator.prototype.getIcon = function (node) {
        var decoration = this.getDecoration(node);
        if (!decoration)
            return null;
        return decoration.icon;
    };
    DefaultDecorator.prototype.getTextStyle = function (node) {
        var decoration = this.getDecoration(node);
        if (!decoration)
            return null;
        return decoration.textStyle;
    };
    return DefaultDecorator;
}());
exports.DefaultDecorator = DefaultDecorator;
var _defaultDecorator = new DefaultDecorator();
var _defaultLabelProvider = new DefaultLabelProvider();
function addDecoration(nodeType, decoration) {
    _defaultDecorator.addDecoration(nodeType, decoration);
}
exports.addDecoration = addDecoration;
function DefaultKeyProvider(node) {
    if (!node)
        return null;
    if (node && !node.parent()) {
        return node.name();
    }
    else {
        return node.name() + " :: " + DefaultKeyProvider(node.parent());
    }
}
function DefaultVisibilityFilter(node) {
    return true;
}
function initialize() {
    structureImpl.setKeyProvider(DefaultKeyProvider);
    structureImpl.addLabelProvider(_defaultLabelProvider);
    structureImpl.addDecorator(_defaultDecorator);
    structureImpl.setVisibilityFilter(DefaultVisibilityFilter);
}
exports.initialize = initialize;
//# sourceMappingURL=structureDefault.js.map