UNPKG

autouml

Version:

Autogenerate UML diagrams using d2

105 lines (104 loc) 4.16 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Visitor = exports.VisitingMapNotDefinedError = void 0; /** * */ var VisitingMapNotDefinedError = /** @class */ (function (_super) { __extends(VisitingMapNotDefinedError, _super); function VisitingMapNotDefinedError() { return _super.call(this, "Tried visiting the nodes of a null map") || this; } return VisitingMapNotDefinedError; }(Error)); exports.VisitingMapNotDefinedError = VisitingMapNotDefinedError; var Visitor = /** @class */ (function () { function Visitor(map, relations) { if (map) { this.map = map; } else { this.map = null; } if (relations) { this.relations = relations; } else { this.relations = []; } } Visitor.prototype.visit = function (map, relations) { if (map !== undefined) { this.map = map; } if (!this.map) { throw new VisitingMapNotDefinedError(); } if (relations) { this.relations = relations; } return (this._visit(this.map).join("\n") + "\n".concat(this.compileRelations())); }; Visitor.prototype._visit = function (scope) { var childData = []; for (var _i = 0, _a = scope.children; _i < _a.length; _i++) { var c = _a[_i]; childData.push(this._visit(c)); } switch (scope.scopeType) { case 0 /* autouml.mapping.ScopeType.PROGRAM */: return this.visitProgram(scope, childData); case 1 /* autouml.mapping.ScopeType.FILE */: return this.visitFile(scope, childData); case 2 /* autouml.mapping.ScopeType.NAMESPACE */: return this.visitNamespace(scope, childData); case 3 /* autouml.mapping.ScopeType.CLASS */: var fieldData = []; var methodData = []; var cscope = scope; for (var _b = 0, _c = cscope.fields; _b < _c.length; _b++) { var f = _c[_b]; fieldData.push(this.visitClassField(f)); } for (var _d = 0, _e = cscope.methods; _d < _e.length; _d++) { var m = _e[_d]; fieldData.push(this.visitClassMethod(m)); } return this.visitClass(cscope, childData, fieldData, methodData); case 4 /* autouml.mapping.ScopeType.INTERFACE */: var interfaceFields = []; var iscope = scope; for (var _f = 0, _g = iscope.interfaceData; _f < _g.length; _f++) { var f = _g[_f]; interfaceFields.push(this.visitInterfaceField(f)); } return this.visitInterface(scope, childData, interfaceFields); case 5 /* autouml.mapping.ScopeType.ENUM */: var enumFields = []; var escope = scope; for (var _h = 0, _j = escope.enumData; _h < _j.length; _h++) { var e = _j[_h]; enumFields.push(this.visitEnumField(e)); } return this.visitEnum(scope, childData, enumFields); } }; return Visitor; }()); exports.Visitor = Visitor;