UNPKG

@yellicode/elements

Version:

The meta model API for Yellicode - an extensible code generator.

1,205 lines (1,199 loc) 321 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@yellicode/core'), require('toposort')) : typeof define === 'function' && define.amd ? define(['exports', '@yellicode/core', 'toposort'], factory) : (factory((global['@yellicode/elements'] = {}),global.core,global.toposort)); }(this, (function (exports,core,toposort) { 'use strict'; /* * 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. */ /** * Contains the current version of this meta model. Note that the meta model version is independent * from versions of packages that depend on the meta model. */ const MetaVersion = '0.1.1'; (function (ElementType) { /** * The element is a Association. Associations represent relationships between classes. */ ElementType[ElementType["association"] = 1] = "association"; /** * Alias for ElementType.class in case the reserved 'class' is not allowed. */ ElementType[ElementType["_class"] = 2] = "_class"; /** * The element is a Class. A Class classifies a set of objects and specifies the features that * characterize the structure and behavior of those objects. A Class may have an internal structure and * Ports. */ ElementType[ElementType["class"] = 2] = "class"; /** * The element is a Comment. A Comment is a textual annotation that can be attached to a set of * Elements. */ ElementType[ElementType["comment"] = 3] = "comment"; /** * The element is a DataType. A DataType is similar to a Class; however, instances of data type are * identified only by their value. If two data types have the same value, the instances are considered * identical. */ ElementType[ElementType["dataType"] = 4] = "dataType"; /** * The element is a Enumeration. An Enumeration is a DataType whose values are enumerated in the model * as EnumerationLiterals. */ ElementType[ElementType["enumeration"] = 5] = "enumeration"; /** * The element is a EnumerationLiteral. An EnumerationLiteral is a user-defined data value for an * Enumeration. */ ElementType[ElementType["enumerationLiteral"] = 6] = "enumerationLiteral"; /** * The element is a Generalization. A Generalization is a taxonomic relationship between a more general * Classifier and a more specific Classifier. Each instance of the specific Classifier is also an * instance of the general Classifier.The specific Classifier inherits the features of the more general * Classifier. A Generalization is owned by the specific Classifier. */ ElementType[ElementType["generalization"] = 7] = "generalization"; /** * Alias for ElementType.interface in case the reserved 'interface' is not allowed. */ ElementType[ElementType["_interface"] = 8] = "_interface"; /** * The element is a Interface. Interfaces declare coherent services that are implemented by * BehavioredClassifiers that implement the Interfaces via InterfaceRealizations. */ ElementType[ElementType["interface"] = 8] = "interface"; /** * The element is a InterfaceRealization. An InterfaceRealization is a specialized realization * relationship between a BehavioredClassifier and an Interface. This relationship signifies that the * realizing BehavioredClassifier conforms to the contract specified by the Interface. */ ElementType[ElementType["interfaceRealization"] = 9] = "interfaceRealization"; /** * The element is a LiteralBoolean. A LiteralBoolean is a specification of a Boolean value. */ ElementType[ElementType["literalBoolean"] = 10] = "literalBoolean"; /** * The element is a LiteralInteger. A LiteralInteger is a specification of an Integer value. */ ElementType[ElementType["literalInteger"] = 11] = "literalInteger"; /** * The element is a LiteralNull. A LiteralNull specifies the lack of a value. */ ElementType[ElementType["literalNull"] = 12] = "literalNull"; /** * The element is a LiteralReal. A LiteralReal is a specification of a Real value. */ ElementType[ElementType["literalReal"] = 13] = "literalReal"; /** * The element is a LiteralString. A LiteralString is a specification of a String value. */ ElementType[ElementType["literalString"] = 14] = "literalString"; /** * The element is a LiteralUnlimitedNatural. A LiteralUnlimitedNatural is a specification of an * UnlimitedNatural number. */ ElementType[ElementType["literalUnlimitedNatural"] = 15] = "literalUnlimitedNatural"; /** * The element is a Model. Represents the top-level package. */ ElementType[ElementType["model"] = 16] = "model"; /** * The element is a Operation. An Operation is a BehavioralFeature of a Classifier that specifies the * name, type, parameters, and constraints for invoking an associated Behavior. An Operation may invoke * both the execution of method behaviors as well as other behavioral responses. */ ElementType[ElementType["operation"] = 17] = "operation"; /** * The element is a Package. A package is used to group elements, and provides a namespace for the * grouped elements. * A package can have one or more profile applications to indicate which profiles have been applied. * Because a profile is a package, it is possible to apply a profile not only to packages, but also to * profiles. */ ElementType[ElementType["package"] = 18] = "package"; /** * The element is a Parameter. A Parameter is a specification of an argument used to pass information * into or out of an invocation of a BehavioralFeature. Parameters can be treated as * ConnectableElements within Collaborations. */ ElementType[ElementType["parameter"] = 19] = "parameter"; /** * The element is a PrimitiveType. A PrimitiveType defines a predefined DataType, without any * substructure. A PrimitiveType may have an algebra and operations defined outside of UML, for * example, mathematically. */ ElementType[ElementType["primitiveType"] = 20] = "primitiveType"; /** * The element is a Profile. Metamodel customizations are defined in a profile, which is then applied * to a package. A profile can define classes, stereotypes, data types, primitive types, enumerations. * Stereotypes are specific metaclasses, tagged values are standard metaattributes, and profiles are * specific kinds of packages. */ ElementType[ElementType["profile"] = 21] = "profile"; /** * The element is a Property. A Property is a StructuralFeature. A Property related by ownedAttribute * to a Classifier (other than an association) represents an attribute and might also represent an * association end. It relates an instance of the Classifier to a value or set of values of the type of * the attribute. A Property related by memberEnd to an Association represents an end of the * Association. The type of the Property is the type of the end of the Association. */ ElementType[ElementType["property"] = 22] = "property"; /** * The element is a Stereotype. Stereotype is a profile class which defines how an existing metaclass * may be extended as part of a profile. It enables the use of a platform or domain specific * terminology or notation in place of, or in addition to, the ones used for the extended metaclass. */ ElementType[ElementType["stereotype"] = 23] = "stereotype"; })(exports.ElementType || (exports.ElementType = {})); /** * UnlimitedNatural is a primitive type representing unlimited natural values. */ class UnlimitedNatural { constructor(value) { /** * Contains the known numeric value of this UnlimitedNatural. This is only a valid value if IsInfinity is false. */ this.Value = null; if (typeof value == 'string') { if (value === "*") this.IsInfinity = true; else { this.IsInfinity = false; this.Value = Number.parseInt(value); } } else { // value is a number this.IsInfinity = false; this.Value = value; } } stringValue() { if (this.IsInfinity) return "*"; return this.Value ? this.Value.toString() : null; } equals(other) { return (other != null) && (other.IsInfinity == this.IsInfinity) && (other.Value === this.Value); } } (function (VisibilityKind) { /** * A Named Element with public visibility is visible to all elements that can access the contents of * the Namespace that owns it. */ VisibilityKind[VisibilityKind["public"] = 1] = "public"; /** * A NamedElement with private visibility is only visible inside the Namespace that owns it. */ VisibilityKind[VisibilityKind["private"] = 2] = "private"; /** * A NamedElement with protected visibility is visible to Elements that have a generalization * relationship to the Namespace that owns it. */ VisibilityKind[VisibilityKind["protected"] = 3] = "protected"; /** * A NamedElement with package visibility is visible to all Elements within the nearest enclosing * Package (given that other owning Elements have proper visibility). Outside the nearest enclosing * Package, a NamedElement marked as having package visibility is not visible. Only NamedElements that * are not owned by Packages can be marked as having package visibility. */ VisibilityKind[VisibilityKind["package"] = 4] = "package"; })(exports.VisibilityKind || (exports.VisibilityKind = {})); (function (ParameterDirectionKind) { /** * Indicates that Parameter values are passed in by the caller. */ ParameterDirectionKind[ParameterDirectionKind["in"] = 1] = "in"; /** * Indicates that Parameter values are passed in by the caller and (possibly different) values passed * out to the caller. */ ParameterDirectionKind[ParameterDirectionKind["inout"] = 2] = "inout"; /** * Indicates that Parameter values are passed out to the caller. */ ParameterDirectionKind[ParameterDirectionKind["out"] = 3] = "out"; /** * Indicates that Parameter values are passed as return values back to the caller. */ ParameterDirectionKind[ParameterDirectionKind["return"] = 4] = "return"; })(exports.ParameterDirectionKind || (exports.ParameterDirectionKind = {})); (function (DocumentLocationKind) { DocumentLocationKind[DocumentLocationKind["local"] = 1] = "local"; DocumentLocationKind[DocumentLocationKind["npm"] = 2] = "npm"; })(exports.DocumentLocationKind || (exports.DocumentLocationKind = {})); (function (AggregationKind) { /** * Indicates that the Property has no aggregation. */ AggregationKind[AggregationKind["none"] = 1] = "none"; /** * Indicates that the Property has shared aggregation. */ AggregationKind[AggregationKind["shared"] = 2] = "shared"; /** * Indicates that the Property is aggregated compositely, i.e., the composite object has responsibility * for the existence and storage of the composed objects (parts). */ AggregationKind[AggregationKind["composite"] = 3] = "composite"; })(exports.AggregationKind || (exports.AggregationKind = {})); /** * Implements a simple data type that has no behavior. */ class SimpleDataType { constructor(id, name, elementType) { this.id = id; this.name = name; this.elementType = elementType; this.visibility = null; this.ownedAttributes = []; this.ownedOperations = []; this.generalizations = []; this.isAbstract = false; this.isFinalSpecialization = false; this.appliedStereotypes = []; this.ownedComments = []; this.owner = null; this.taggedValues = []; this.isLeaf = false; this.isInferred = false; this.isDeprecated = false; } isOrphaned() { // this type has no owner, so keep it simple return !!this.isDeleted; } get package() { throw `The ${this.name} data type has no package.`; } getFirstCommentBody() { return ''; } getAllParents() { throw new Error('Method not implemented.'); } getAllSpecializations() { throw new Error('Method not implemented.'); } getFirstGeneralization() { return null; } getFirstParent() { return null; } getParents() { return []; } getSpecializations() { return []; } getNamespaceName(separator) { return ''; } getNestingPackages() { return []; } getQualifiedName(separator) { return this.name; } getAllAttributes() { return []; } getAllOperations() { return []; } getSuperTypes() { throw new Error('Method not implemented.'); } } /* * 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/. */ const PRIMITIVE_BOOLEAN_ID = "boolean_id"; const PRIMITIVE_INTEGER_ID = "integer_id"; const PRIMITIVE_REAL_ID = "real_id"; const PRIMITIVE_STRING_ID = "string_id"; const PRIMITIVE_OBJECT_ID = "object_id"; /** * Represents the built-in primitive boolean type. */ const primitiveBooleanType = new SimpleDataType(PRIMITIVE_BOOLEAN_ID, 'boolean', exports.ElementType.primitiveType); /** * Represents the built-in primitive integer type. */ const primitiveIntegerType = new SimpleDataType(PRIMITIVE_INTEGER_ID, 'integer', exports.ElementType.primitiveType); /** * Represents the built-in primitive real type. */ const primitiveRealType = new SimpleDataType(PRIMITIVE_REAL_ID, 'real', exports.ElementType.primitiveType); /** * Represents the built-in primitive string type. */ const primitiveStringType = new SimpleDataType(PRIMITIVE_STRING_ID, 'string', exports.ElementType.primitiveType); /** * Represents the built-in primitive object type. */ const primitiveObjectType = new SimpleDataType(PRIMITIVE_OBJECT_ID, 'object', exports.ElementType.primitiveType); /** * Asserts that the element is a built in primitive boolean. */ function isPrimitiveBoolean(element) { if (!element) return false; return element.id === PRIMITIVE_BOOLEAN_ID; } /** * Asserts that the element is a built in primitive integer. */ function isPrimitiveInteger(element) { if (!element) return false; return element.id === PRIMITIVE_INTEGER_ID; } /** * Asserts that the element is a built in primitive real. */ function isPrimitiveReal(element) { if (!element) return false; return element.id === PRIMITIVE_REAL_ID; } /** * Asserts that the element is a built in primitive string. */ function isPrimitiveString(element) { if (!element) return false; return element.id === PRIMITIVE_STRING_ID; } /** * Asserts that the element is a built in primitive object. */ function isPrimitiveObject(element) { if (!element) return false; return element.id === PRIMITIVE_OBJECT_ID; } /* * 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/. */ class ElementTypeUtility { /** * Returns true if the elementType is a NamedElement or one of its descendants. */ static isNamedElement(elementType) { switch (elementType) { case exports.ElementType.association: return true; case exports.ElementType.class: return true; case exports.ElementType.dataType: return true; case exports.ElementType.enumeration: return true; case exports.ElementType.enumerationLiteral: return true; case exports.ElementType.interface: return true; case exports.ElementType.literalBoolean: return true; case exports.ElementType.literalInteger: return true; case exports.ElementType.literalNull: return true; case exports.ElementType.literalReal: return true; case exports.ElementType.literalString: return true; case exports.ElementType.literalUnlimitedNatural: return true; case exports.ElementType.model: return true; case exports.ElementType.operation: return true; case exports.ElementType.package: return true; case exports.ElementType.parameter: return true; case exports.ElementType.primitiveType: return true; case exports.ElementType.profile: return true; case exports.ElementType.property: return true; case exports.ElementType.stereotype: return true; default: return false; } } /** * Returns true if the elementType is a TypedElement or one of its descendants. */ static isTypedElement(elementType) { switch (elementType) { case exports.ElementType.literalBoolean: return true; case exports.ElementType.literalInteger: return true; case exports.ElementType.literalNull: return true; case exports.ElementType.literalReal: return true; case exports.ElementType.literalString: return true; case exports.ElementType.literalUnlimitedNatural: return true; case exports.ElementType.parameter: return true; case exports.ElementType.property: return true; default: return false; } } /** * Returns true if the elementType is a ValueSpecification or one of its descendants. */ static isValueSpecification(elementType) { switch (elementType) { case exports.ElementType.literalBoolean: return true; case exports.ElementType.literalInteger: return true; case exports.ElementType.literalNull: return true; case exports.ElementType.literalReal: return true; case exports.ElementType.literalString: return true; case exports.ElementType.literalUnlimitedNatural: return true; default: return false; } } /** * Returns true if the elementType is a PackageableElement or one of its descendants. */ static isPackageableElement(elementType) { switch (elementType) { case exports.ElementType.association: return true; case exports.ElementType.class: return true; case exports.ElementType.dataType: return true; case exports.ElementType.enumeration: return true; case exports.ElementType.interface: return true; case exports.ElementType.model: return true; case exports.ElementType.package: return true; case exports.ElementType.primitiveType: return true; case exports.ElementType.profile: return true; case exports.ElementType.stereotype: return true; default: return false; } } /** * Returns true if the elementType is a Type or one of its descendants. */ static isType(elementType) { switch (elementType) { case exports.ElementType.association: return true; case exports.ElementType.class: return true; case exports.ElementType.dataType: return true; case exports.ElementType.enumeration: return true; case exports.ElementType.interface: return true; case exports.ElementType.primitiveType: return true; case exports.ElementType.stereotype: return true; default: return false; } } /** * Returns true if the elementType is a RedefinableElement or one of its descendants. */ static isRedefinableElement(elementType) { switch (elementType) { case exports.ElementType.association: return true; case exports.ElementType.class: return true; case exports.ElementType.dataType: return true; case exports.ElementType.enumeration: return true; case exports.ElementType.interface: return true; case exports.ElementType.operation: return true; case exports.ElementType.primitiveType: return true; case exports.ElementType.property: return true; case exports.ElementType.stereotype: return true; default: return false; } } /** * Returns true if the elementType is a Classifier or one of its descendants. */ static isClassifier(elementType) { switch (elementType) { case exports.ElementType.association: return true; case exports.ElementType.class: return true; case exports.ElementType.dataType: return true; case exports.ElementType.enumeration: return true; case exports.ElementType.interface: return true; case exports.ElementType.primitiveType: return true; case exports.ElementType.stereotype: return true; default: return false; } } /** * Returns true if the elementType is a StructuredClassifier or one of its descendants. */ static isStructuredClassifier(elementType) { switch (elementType) { case exports.ElementType.class: return true; case exports.ElementType.stereotype: return true; default: return false; } } /** * Returns true if the elementType is a MultiplicityElement or one of its descendants. */ static isMultiplicityElement(elementType) { switch (elementType) { case exports.ElementType.parameter: return true; case exports.ElementType.property: return true; default: return false; } } /** * Returns true if the elementType is a OrderedElement or one of its descendants. */ static isOrderedElement(elementType) { switch (elementType) { case exports.ElementType.enumerationLiteral: return true; case exports.ElementType.operation: return true; case exports.ElementType.parameter: return true; case exports.ElementType.property: return true; default: return false; } } /** * Returns true if the elementType is a Feature or one of its descendants. */ static isFeature(elementType) { switch (elementType) { case exports.ElementType.operation: return true; case exports.ElementType.property: return true; default: return false; } } /** * Returns true if the elementType is a StructuralFeature or one of its descendants. */ static isStructuralFeature(elementType) { return elementType === exports.ElementType.property; } /** * Returns true if the elementType is a MemberedClassifier or one of its descendants. */ static isMemberedClassifier(elementType) { switch (elementType) { case exports.ElementType.class: return true; case exports.ElementType.dataType: return true; case exports.ElementType.enumeration: return true; case exports.ElementType.interface: return true; case exports.ElementType.primitiveType: return true; case exports.ElementType.stereotype: return true; default: return false; } } /** * Returns true if the elementType is a BehavioredClassifier or one of its descendants. */ static isBehavioredClassifier(elementType) { switch (elementType) { case exports.ElementType.class: return true; case exports.ElementType.stereotype: return true; default: return false; } } /** * Returns true if the elementType is a Class or one of its descendants. */ static isClass(elementType) { switch (elementType) { case exports.ElementType.class: return true; case exports.ElementType.stereotype: return true; default: return false; } } /** * Returns true if the elementType is a Stereotype or one of its descendants. */ static isStereotype(elementType) { return elementType === exports.ElementType.stereotype; } /** * Returns true if the elementType is a Relationship or one of its descendants. */ static isRelationship(elementType) { switch (elementType) { case exports.ElementType.association: return true; case exports.ElementType.generalization: return true; case exports.ElementType.interfaceRealization: return true; default: return false; } } /** * Returns true if the elementType is a Property or one of its descendants. */ static isProperty(elementType) { return elementType === exports.ElementType.property; } /** * Returns true if the elementType is a Package or one of its descendants. */ static isPackage(elementType) { switch (elementType) { case exports.ElementType.package: return true; case exports.ElementType.model: return true; case exports.ElementType.profile: return true; default: return false; } } /** * Returns true if the elementType is a Profile or one of its descendants. */ static isProfile(elementType) { return elementType === exports.ElementType.profile; } /** * Returns true if the elementType is a DataType or one of its descendants. */ static isDataType(elementType) { switch (elementType) { case exports.ElementType.dataType: return true; case exports.ElementType.enumeration: return true; case exports.ElementType.primitiveType: return true; default: return false; } } /** * Returns true if the elementType is a PrimitiveType or one of its descendants. */ static isPrimitiveType(elementType) { return elementType === exports.ElementType.primitiveType; } /** * Returns true if the elementType is a Parameter or one of its descendants. */ static isParameter(elementType) { return elementType === exports.ElementType.parameter; } /** * Returns true if the elementType is a BehavioralFeature or one of its descendants. */ static isBehavioralFeature(elementType) { return elementType === exports.ElementType.operation; } /** * Returns true if the elementType is a Operation or one of its descendants. */ static isOperation(elementType) { return elementType === exports.ElementType.operation; } /** * Returns true if the elementType is a Model or one of its descendants. */ static isModel(elementType) { return elementType === exports.ElementType.model; } /** * Returns true if the elementType is a LiteralSpecification or one of its descendants. */ static isLiteralSpecification(elementType) { switch (elementType) { case exports.ElementType.literalBoolean: return true; case exports.ElementType.literalInteger: return true; case exports.ElementType.literalNull: return true; case exports.ElementType.literalReal: return true; case exports.ElementType.literalString: return true; case exports.ElementType.literalUnlimitedNatural: return true; default: return false; } } /** * Returns true if the elementType is a LiteralUnlimitedNatural or one of its descendants. */ static isLiteralUnlimitedNatural(elementType) { return elementType === exports.ElementType.literalUnlimitedNatural; } /** * Returns true if the elementType is a LiteralString or one of its descendants. */ static isLiteralString(elementType) { return elementType === exports.ElementType.literalString; } /** * Returns true if the elementType is a LiteralReal or one of its descendants. */ static isLiteralReal(elementType) { return elementType === exports.ElementType.literalReal; } /** * Returns true if the elementType is a LiteralNull or one of its descendants. */ static isLiteralNull(elementType) { return elementType === exports.ElementType.literalNull; } /** * Returns true if the elementType is a LiteralInteger or one of its descendants. */ static isLiteralInteger(elementType) { return elementType === exports.ElementType.literalInteger; } /** * Returns true if the elementType is a LiteralBoolean or one of its descendants. */ static isLiteralBoolean(elementType) { return elementType === exports.ElementType.literalBoolean; } /** * Returns true if the elementType is a DirectedRelationship or one of its descendants. */ static isDirectedRelationship(elementType) { switch (elementType) { case exports.ElementType.generalization: return true; case exports.ElementType.interfaceRealization: return true; default: return false; } } /** * Returns true if the elementType is a InterfaceRealization or one of its descendants. */ static isInterfaceRealization(elementType) { return elementType === exports.ElementType.interfaceRealization; } /** * Returns true if the elementType is a Interface or one of its descendants. */ static isInterface(elementType) { return elementType === exports.ElementType.interface; } /** * Returns true if the elementType is a Generalization or one of its descendants. */ static isGeneralization(elementType) { return elementType === exports.ElementType.generalization; } /** * Returns true if the elementType is a EnumerationLiteral or one of its descendants. */ static isEnumerationLiteral(elementType) { return elementType === exports.ElementType.enumerationLiteral; } /** * Returns true if the elementType is a Enumeration or one of its descendants. */ static isEnumeration(elementType) { return elementType === exports.ElementType.enumeration; } /** * Returns true if the elementType is a Comment or one of its descendants. */ static isComment(elementType) { return elementType === exports.ElementType.comment; } /** * Returns true if the elementType is a Association or one of its descendants. */ static isAssociation(elementType) { return elementType === exports.ElementType.association; } } /** * Asserts that the element is a NamedElement or one of its descendants. */ function isNamedElement(element) { if (!element) return false; return ElementTypeUtility.isNamedElement(element.elementType); } /** * Asserts that the element is a TypedElement or one of its descendants. */ function isTypedElement(element) { if (!element) return false; return ElementTypeUtility.isTypedElement(element.elementType); } /** * Asserts that the element is a ValueSpecification or one of its descendants. */ function isValueSpecification(element) { if (!element) return false; return ElementTypeUtility.isValueSpecification(element.elementType); } /** * Asserts that the element is a PackageableElement or one of its descendants. */ function isPackageableElement(element) { if (!element) return false; return ElementTypeUtility.isPackageableElement(element.elementType); } /** * Asserts that the element is a Type or one of its descendants. */ function isType(element) { if (!element) return false; return ElementTypeUtility.isType(element.elementType); } /** * Asserts that the element is a RedefinableElement or one of its descendants. */ function isRedefinableElement(element) { if (!element) return false; return ElementTypeUtility.isRedefinableElement(element.elementType); } /** * Asserts that the element is a Classifier or one of its descendants. */ function isClassifier(element) { if (!element) return false; return ElementTypeUtility.isClassifier(element.elementType); } /** * Asserts that the element is a StructuredClassifier or one of its descendants. */ function isStructuredClassifier(element) { if (!element) return false; return ElementTypeUtility.isStructuredClassifier(element.elementType); } /** * Asserts that the element is a MultiplicityElement or one of its descendants. */ function isMultiplicityElement(element) { if (!element) return false; return ElementTypeUtility.isMultiplicityElement(element.elementType); } /** * Asserts that the element is a OrderedElement or one of its descendants. */ function isOrderedElement(element) { if (!element) return false; return ElementTypeUtility.isOrderedElement(element.elementType); } /** * Asserts that the element is a Feature or one of its descendants. */ function isFeature(element) { if (!element) return false; return ElementTypeUtility.isFeature(element.elementType); } /** * Asserts that the element is a StructuralFeature or one of its descendants. */ function isStructuralFeature(element) { if (!element) return false; return ElementTypeUtility.isStructuralFeature(element.elementType); } /** * Asserts that the element is a MemberedClassifier or one of its descendants. */ function isMemberedClassifier(element) { if (!element) return false; return ElementTypeUtility.isMemberedClassifier(element.elementType); } /** * Asserts that the element is a BehavioredClassifier or one of its descendants. */ function isBehavioredClassifier(element) { if (!element) return false; return ElementTypeUtility.isBehavioredClassifier(element.elementType); } /** * Asserts that the element is a Class or one of its descendants. */ function isClass(element) { if (!element) return false; return ElementTypeUtility.isClass(element.elementType); } /** * Asserts that the element is a Stereotype or one of its descendants. */ function isStereotype(element) { if (!element) return false; return ElementTypeUtility.isStereotype(element.elementType); } /** * Asserts that the element is a Relationship or one of its descendants. */ function isRelationship(element) { if (!element) return false; return ElementTypeUtility.isRelationship(element.elementType); } /** * Asserts that the element is a Property or one of its descendants. */ function isProperty(element) { if (!element) return false; return ElementTypeUtility.isProperty(element.elementType); } /** * Asserts that the element is a Package or one of its descendants. */ function isPackage(element) { if (!element) return false; return ElementTypeUtility.isPackage(element.elementType); } /** * Asserts that the element is a Profile or one of its descendants. */ function isProfile(element) { if (!element) return false; return ElementTypeUtility.isProfile(element.elementType); } /** * Asserts that the element is a DataType or one of its descendants. */ function isDataType(element) { if (!element) return false; return ElementTypeUtility.isDataType(element.elementType); } /** * Asserts that the element is a PrimitiveType or one of its descendants. */ function isPrimitiveType(element) { if (!element) return false; return ElementTypeUtility.isPrimitiveType(element.elementType); } /** * Asserts that the element is a Parameter or one of its descendants. */ function isParameter(element) { if (!element) return false; return ElementTypeUtility.isParameter(element.elementType); } /** * Asserts that the element is a BehavioralFeature or one of its descendants. */ function isBehavioralFeature(element) { if (!element) return false; return ElementTypeUtility.isBehavioralFeature(element.elementType); } /** * Asserts that the element is a Operation or one of its descendants. */ function isOperation(element) { if (!element) return false; return ElementTypeUtility.isOperation(element.elementType); } /** * Asserts that the element is a Model or one of its descendants. */ function isModel(element) { if (!element) return false; return ElementTypeUtility.isModel(element.elementType); } /** * Asserts that the element is a LiteralSpecification or one of its descendants. */ function isLiteralSpecification(element) { if (!element) return false; return ElementTypeUtility.isLiteralSpecification(element.elementType); } /** * Asserts that the element is a LiteralUnlimitedNatural or one of its descendants. */ function isLiteralUnlimitedNatural(element) { if (!element) return false; return ElementTypeUtility.isLiteralUnlimitedNatural(element.elementType); } /** * Asserts that the element is a LiteralString or one of its descendants. */ function isLiteralString(element) { if (!element) return false; return ElementTypeUtility.isLiteralString(element.elementType); } /** * Asserts that the element is a LiteralReal or one of its descendants. */ function isLiteralReal(element) { if (!element) return false; return ElementTypeUtility.isLiteralReal(element.elementType); } /** * Asserts that the element is a LiteralNull or one of its descendants. */ function isLiteralNull(element) { if (!element) return false; return ElementTypeUtility.isLiteralNull(element.elementType); } /** * Asserts that the element is a LiteralInteger or one of its descendants. */ function isLiteralInteger(element) { if (!element) return false; return ElementTypeUtility.isLiteralInteger(element.elementType); } /** * Asserts that the element is a LiteralBoolean or one of its descendants. */ function isLiteralBoolean(element) { if (!element) return false; return ElementTypeUtility.isLiteralBoolean(element.elementType); } /** * Asserts that the element is a DirectedRelationship or one of its descendants. */ function isDirectedRelationship(element) { if (!element) return false; return ElementTypeUtility.isDirectedRelationship(element.elementType); } /** * Asserts that the element is a InterfaceRealization or one of its descendants. */ function isInterfaceRealization(element) { if (!element) return false; return ElementTypeUtility.isInterfaceRealization(element.elementType); } /** * Asserts that the element is a Interface or one of its descendants. */ function isInterface(element) { if (!element) return false; return ElementTypeUtility.isInterface(element.elementType); } /** * Asserts that the element is a Generalization or one of its descendants. */ function isGeneralization(element) { if (!element) return false; return ElementTypeUtility.isGeneralization(element.elementType); } /** * Asserts that the element is a EnumerationLiteral or one of its descendants. */ function isEnumerationLiteral(element) { if (!element) return false; return ElementTypeUtility.isEnumerationLiteral(element.elementType); } /** * Asserts that the element is a Enumeration or one of its descendants. */ function isEnumeration(element) { if (!element) return false; return ElementTypeUtility.isEnumeration(element.elementType); } /** * Asserts that the element is a Comment or one of its descendants. */ function isComment(element) { if (!element) return false; return ElementTypeUtility.isComment(element.elementType); } /** * Asserts that the element is a Association or one of its descendants. */ function isAssociation(element) { if (!element) return false; return ElementTypeUtility.isAssociation(element.elementType); } /* * 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/. */ class ProfileUtility { static getStereotypes(profile) { if (!profile.packagedElements) return []; return profile.packagedElements.filter((e) => e.elementType === exports.ElementType.stereotype); } static hasStereotypeId(element, stereotypeId) { if (!element || !element.appliedStereotypes) return false; return ProfileUtility.hasStereotypeIdRecursive(element.appliedStereotypes, stereotypeId); } static hasStereotypeIdRecursive(stereotypes, stereotypeId) { for (var index = 0; index < stereotypes.length; index++) { var stereotype = stereotypes[index]; if (stereotype.id === stereotypeId) return true; // If the stereotype has parents, check these too const stereotypeGenerals = stereotype.getParents(); if (stereotypeGenerals.length > 0 && ProfileUtility.hasStereotypeIdRecursive(stereotypeGenerals, stereotypeId)) { return true; } } return false; } static getMetaClassesExtendedBy(stereotype) { // First add the stereotype's own meta classes return stereotype.extends.map(ext => ext.metaClass); } static getAllMetaClassesExtendedBy(stereotype) { // First add the stereotype's own meta classes const metaClasses = ProfileUtility.getMetaClassesExtendedBy(stereotype); // Then add meta classes of the specializing stereotypes stereotype.getSpecializations().forEach((derivedStereotype) => { derivedStereotype.extends.forEach(extension => { if (metaClasses.indexOf(extension.metaClass) === -1) { metaClasses.push(extension.metaClass); } }); }); return metaClasses; } static hasProfileId(pack, profileId) { if (!pack || !pack.appliedProfiles) return false; return pack.appliedProfiles.some((s) => s.id === profileId); } /** * Filters the array of elements by only including the elements that have a particular stereotype applied. */ static filterByStereotypeId(elements, stereotypeId, elementType) { if (!elements) return []; if (elementType) { return elements.filter(e => { return e.elementType === elementType && ProfileUtility.hasStereotypeId(e, stereotypeId); }); } return elements.filter(e => { return ProfileUtility.hasStereotypeId(e, stereotypeId); }); } /** * Filters the array of packageable element by only including the packages that have a particular profile applied. */ static filterByProfileId(elements, profileId) { if (!elements) return []; return elements.filter((e) => e.elementType === exports.ElementType.package && ProfileUtility.hasProfileId(e, profileId)); } } /* * 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/