@yellicode/elements
Version:
The meta model API for Yellicode - an extensible code generator.
127 lines (126 loc) • 6.95 kB
JavaScript
/*
* Copyright (c) 2020 Yellicode
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/**
* This code was generated by a tool.
*
* Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
*/
import * as elements from './interfaces';
var enumKeys = ['elementType', 'visibility', 'aggregation', 'direction'];
var regularKeys = ['id', 'ownedComments', 'taggedValues', 'name', 'isInferred', 'isLeaf', 'generalizations', 'isAbstract', 'isFinalSpecialization', 'isOrdered', 'isUnique', 'lowerValue', 'upperValue', 'order', 'isStatic', 'isReadOnly', 'ownedAttributes', 'ownedOperations', 'interfaceRealizations', 'isActive', 'extends', 'safeName', 'defaultValue', 'isDerived', 'isDerivedUnion', 'isID', 'isNavigable', 'isNamespaceRoot', 'packagedElements', 'isException', 'isStream', 'ownedParameters', 'isConstructor', 'isQuery', 'value', 'isSubstitutable', 'specification', 'ownedLiterals', 'body', 'ownedEnds'];
var referenceKeys = ['appliedStereotypes', 'type', 'appliedProfiles', 'contract', 'general', 'baseType', 'memberEnds'];
var ElementJsonTransformer = /** @class */ (function () {
function ElementJsonTransformer() {
}
/**
* Creates a persistable string representation of the specified VisibilityKind value.
* @param {elements.VisibilityKind} value The value being stringified.
*/
ElementJsonTransformer.stringifyVisibilityKind = function (value) {
switch (value) {
case elements.VisibilityKind.public: return 'public';
case elements.VisibilityKind.private: return 'private';
case elements.VisibilityKind.protected: return 'protected';
case elements.VisibilityKind.package: return 'package';
}
};
/**
* Creates a persistable string representation of the specified ParameterDirectionKind value.
* @param {elements.ParameterDirectionKind} value The value being stringified.
*/
ElementJsonTransformer.stringifyParameterDirectionKind = function (value) {
switch (value) {
case elements.ParameterDirectionKind.in: return 'in';
case elements.ParameterDirectionKind.inout: return 'inout';
case elements.ParameterDirectionKind.out: return 'out';
case elements.ParameterDirectionKind.return: return 'return';
}
};
/**
* Creates a persistable string representation of the specified ElementType value.
* @param {elements.ElementType} value The value being stringified.
*/
ElementJsonTransformer.stringifyElementType = function (value) {
switch (value) {
case elements.ElementType.class: return 'class';
case elements.ElementType.stereotype: return 'stereotype';
case elements.ElementType.property: return 'property';
case elements.ElementType.package: return 'package';
case elements.ElementType.profile: return 'profile';
case elements.ElementType.dataType: return 'dataType';
case elements.ElementType.primitiveType: return 'primitiveType';
case elements.ElementType.parameter: return 'parameter';
case elements.ElementType.operation: return 'operation';
case elements.ElementType.model: return 'model';
case elements.ElementType.literalUnlimitedNatural: return 'literalUnlimitedNatural';
case elements.ElementType.literalString: return 'literalString';
case elements.ElementType.literalReal: return 'literalReal';
case elements.ElementType.literalNull: return 'literalNull';
case elements.ElementType.literalInteger: return 'literalInteger';
case elements.ElementType.literalBoolean: return 'literalBoolean';
case elements.ElementType.interfaceRealization: return 'interfaceRealization';
case elements.ElementType.interface: return 'interface';
case elements.ElementType.generalization: return 'generalization';
case elements.ElementType.enumerationLiteral: return 'enumerationLiteral';
case elements.ElementType.enumeration: return 'enumeration';
case elements.ElementType.comment: return 'comment';
case elements.ElementType.association: return 'association';
}
};
/**
* Creates a persistable string representation of the specified DocumentLocationKind value.
* @param {elements.DocumentLocationKind} value The value being stringified.
*/
ElementJsonTransformer.stringifyDocumentLocationKind = function (value) {
switch (value) {
case elements.DocumentLocationKind.local: return 'local';
case elements.DocumentLocationKind.npm: return 'npm';
}
};
/**
* Creates a persistable string representation of the specified AggregationKind value.
* @param {elements.AggregationKind} value The value being stringified.
*/
ElementJsonTransformer.stringifyAggregationKind = function (value) {
switch (value) {
case elements.AggregationKind.none: return 'none';
case elements.AggregationKind.shared: return 'shared';
case elements.AggregationKind.composite: return 'composite';
}
};
/**
* A custom replacer function that is used as a replacer callback using JSON.stringify.
* @param {elements.Element} element The model element in which the key was found.
* @param {any} key The key being stringified.
* @param {any} value The value being stringified.
* @param {boolean} valueIsArray True if the value being stringified is an array.
*/
ElementJsonTransformer.replace = function (element, key, value, valueIsArray) {
if (value == null)
return undefined;
if (regularKeys.indexOf(key) > -1)
return (key === 'value') ? element.getStringValue() : value;
if (referenceKeys.indexOf(key) > -1) {
if (valueIsArray) {
return value.map(function (e) { return e.id; });
}
else
return value.id;
}
if (enumKeys.indexOf(key) > -1) {
switch (key) {
case 'elementType': return ElementJsonTransformer.stringifyElementType(value);
case 'visibility': return ElementJsonTransformer.stringifyVisibilityKind(value);
case 'aggregation': return ElementJsonTransformer.stringifyAggregationKind(value);
case 'direction': return ElementJsonTransformer.stringifyParameterDirectionKind(value);
}
}
};
return ElementJsonTransformer;
}());
export { ElementJsonTransformer };