UNPKG

@tripsnek/tmf

Version:

TypeScript Modeling Framework - A TypeScript port of the Eclipse Modeling Framework (EMF)

247 lines 8.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EClassImpl = void 0; const basicelist_1 = require("./basicelist"); const eattribute_impl_1 = require("./eattribute-impl"); const eclassifier_impl_1 = require("./eclassifier-impl"); const ereference_impl_1 = require("./ereference-impl"); class EClassImpl extends eclassifier_impl_1.EClassifierImpl { classIsAbstract = false; classIsInterface = false; eSuperTypes = new basicelist_1.BasicEList(); eStructuralFeatures = new basicelist_1.BasicEList(); eOperations = new basicelist_1.BasicEList(); // pre-computed and cached lists eReferences; eAllSuperTypes; eAllStructuralFeatures; eAttributes; eAllAttributes; eAllReferences; eAllContainments; eAllOperations; constructor(owner, name, abstract, isInterface) { super(owner, name); if (abstract) this.classIsAbstract = abstract; if (isInterface) this.classIsInterface = isInterface; } isAbstract() { return this.classIsAbstract; } isInterface() { return this.classIsInterface; } setAbstract(value) { this.classIsAbstract = value; } setInterface(value) { this.classIsInterface = value; } getEAttributes() { if (this.eAttributes === undefined) { this.computeEAllAttributes(); } return this.eAttributes; } getEAllAttributes() { if (this.eAllAttributes === undefined) { this.computeEAllAttributes(); } return this.eAllAttributes; } computeEAllAttributes() { this.eAllAttributes = new basicelist_1.BasicEList(); this.eAttributes = new basicelist_1.BasicEList(); // Add features from this type const features = this.getEStructuralFeatures(); for (let i = 0; i < features.size(); i++) { const feature = features.get(i); if (feature instanceof eattribute_impl_1.EAttributeImpl) { this.eAllAttributes.add(feature); this.eAttributes.add(feature); } } // Add features from all super types const allSuperTypes = this.getEAllSuperTypes(); for (let i = 0; i < allSuperTypes.size(); i++) { const superType = allSuperTypes.get(i); const superAttributes = superType.getEAttributes(); for (let j = 0; j < superAttributes.size(); j++) { this.eAllAttributes.add(superAttributes.get(j)); } } } getEIDAttribute() { return this.getEAllAttributes().find((e) => e.isId()); } createInstance() { return this.getEPackage().getEFactoryInstance().create(this); } isSuperTypeOf(someClass) { if (someClass === this) { return true; } else if (someClass === null) { return false; } else { return someClass.getESuperTypes().some((e) => this.isSuperTypeOf(e)); } } getESuperTypes() { return this.eSuperTypes; } getEAllSuperTypes() { if (this.eAllSuperTypes === undefined) { this.computeEAllSuperTypes(); } return this.eAllSuperTypes; } computeEAllSuperTypes() { this.eAllSuperTypes = new basicelist_1.BasicEList(); for (let i = 0; i < this.eSuperTypes.size(); i++) { const st = this.eSuperTypes.get(i); const allSuperTypes = st.getEAllSuperTypes(); for (let j = 0; j < allSuperTypes.size(); j++) { this.eAllSuperTypes.add(allSuperTypes.get(j)); } this.eAllSuperTypes.add(st); } } getEStructuralFeatures() { return this.eStructuralFeatures; } getEAllStructuralFeatures() { if (this.eAllStructuralFeatures === undefined) { this.computeAllStructuralFeatures(); } return this.eAllStructuralFeatures; } computeAllStructuralFeatures() { this.eAllStructuralFeatures = new basicelist_1.BasicEList(); // Add features from this type for (let i = 0; i < this.eStructuralFeatures.size(); i++) { this.eAllStructuralFeatures.add(this.eStructuralFeatures.get(i)); } // Add features from all super types const superTypes = this.getESuperTypes(); for (let i = 0; i < superTypes.size(); i++) { const superType = superTypes.get(i); const allStructuralFeatures = superType.getEAllStructuralFeatures(); for (let j = 0; j < allStructuralFeatures.size(); j++) { this.eAllStructuralFeatures.add(allStructuralFeatures.get(j)); } } } /** * Returns the feature identified by either it's feature ID (a number) or * name (a string). * @param featureIdOrName */ getEStructuralFeature(featureIdOrName) { if (typeof featureIdOrName === 'number') return this.getEAllStructuralFeatures().find((e) => e.getFeatureID() === featureIdOrName); else return this.getEAllStructuralFeatures().find((e) => e.getName() === featureIdOrName); } getFeatureCount() { return this.getEAllStructuralFeatures().size(); } getFeatureID(feature) { const features = this.getEStructuralFeatures(); if (feature.getFeatureID() >= 0) return feature.getFeatureID(); for (let i = 0; i < features.size(); i++) { if (features.get(i) === feature) { return i; } } return -1; } //====================================================================== // References getEReferences() { if (this.eReferences === undefined) { this.computeEAllReferences(); } return this.eReferences; } getEAllReferences() { if (this.eAllReferences === undefined) { this.computeEAllReferences(); } return this.eAllReferences; } computeEAllReferences() { this.eAllReferences = new basicelist_1.BasicEList(); this.eReferences = new basicelist_1.BasicEList(); // Add features from this type for (let i = 0; i < this.eStructuralFeatures.size(); i++) { const feature = this.eStructuralFeatures.get(i); if (feature instanceof ereference_impl_1.EReferenceImpl) { this.eAllReferences.add(feature); this.eReferences.add(feature); } } // Add features from all super types const allSuperTypes = this.getEAllSuperTypes(); for (let i = 0; i < allSuperTypes.size(); i++) { const superType = allSuperTypes.get(i); const references = superType.getEReferences(); for (let j = 0; j < references.size(); j++) { this.eAllReferences.add(references.get(j)); } } } getEAllContainments() { if (this.eAllContainments === undefined) { this.computeEAllContainments(); } return this.eAllContainments; } computeEAllContainments() { this.eAllContainments = new basicelist_1.BasicEList(); const allReferences = this.getEAllReferences(); for (let i = 0; i < allReferences.size(); i++) { const f = allReferences.get(i); if (f.isContainment()) { this.eAllContainments.add(f); } } } //====================================================================== // Operations getEOperations() { return this.eOperations; } getEAllOperations() { if (this.eAllOperations === undefined) { this.computeEAllOperations(); } return this.eAllOperations; } computeEAllOperations() { this.eAllOperations = new basicelist_1.BasicEList(); const allSuperTypes = this.getEAllSuperTypes(); for (let i = 0; i < allSuperTypes.size(); i++) { const superType = allSuperTypes.get(i); const operations = superType.getEOperations(); for (let j = 0; j < operations.size(); j++) { this.eAllOperations.add(operations.get(j)); } } } //hacky method for when a metamodel is being manipulated at runtime (e.g. in Ecore Editor) recomputeAllLists() { this.computeEAllSuperTypes(); this.computeAllStructuralFeatures(); this.computeEAllAttributes(); this.computeEAllReferences(); this.computeEAllContainments(); this.computeEAllOperations(); } } exports.EClassImpl = EClassImpl; //# sourceMappingURL=eclass-impl.js.map