@tripsnek/tmf
Version:
TypeScript Modeling Framework - A TypeScript port of the Eclipse Modeling Framework (EMF)
144 lines • 5.02 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EObjectImpl = void 0;
// import { EcorePackage } from './ecorepackage';
class EObjectImpl {
// private _eClass: EClass;
_eContainer;
_eContainingFeature;
_eIsProxy = false;
constructor() {
// this._eClass = eClass!;
}
eClass() {
return undefined;
}
// public setEClass(eClass: EClass) {
// this._eClass = eClass;
// }
eContainer() {
return this._eContainer;
}
eInverseRemove(otherEnd, featureId) {
const feature = this.eClass().getEStructuralFeature(featureId);
if (feature) {
if (feature?.isMany()) {
this.eGet(feature).remove(otherEnd);
}
else {
this.eSet(feature, null);
}
}
}
eInverseAdd(otherEnd, featureId) {
const feature = this.eClass().getEStructuralFeature(featureId);
if (feature) {
if (feature.isMany()) {
this.eGet(feature).add(otherEnd);
}
else {
this.eSet(feature, otherEnd);
}
}
}
// TODO: Protected is probably not right
// This method is probably to be invoked by setting a containment field
// This should really only be invoked by generated code!
setEContainer(eContainer, containingFeatureId) {
//remove from old container, if it is different
const oldContainer = this.eContainer();
if (oldContainer && eContainer) {
if (oldContainer !== eContainer ||
containingFeatureId !== this._eContainingFeature) {
if (!oldContainer.eClass().getEStructuralFeature(this._eContainingFeature)?.isMany()) {
if (oldContainer.eGet(this._eContainingFeature)) {
oldContainer.eSet(this._eContainingFeature, null);
}
}
else {
oldContainer.eGet(this._eContainingFeature).remove(this);
}
}
}
this.eBasicSetContainer(eContainer, containingFeatureId);
}
eBasicSetContainer(eContainer, containingFeatureId) {
this._eContainer = eContainer;
this._eContainingFeature = containingFeatureId;
}
//================================================================================
// Serializable Id strategy
fullId() {
//TODO: support encoding of multiple ID attributes
//if the ID attribute does not exist or is not set, return null - do not pretend there is a unique ID
if (!this.eClass().getEIDAttribute())
return '';
if (!this.eClass().getEIDAttribute())
return '';
if (!this.eGet(this.eClass().getEIDAttribute()))
return '';
//TODO: use full path to type rather than just class name
//TODO: Can't use the one in TUtils because it creates circular import - put it somewhere else?
return (this.eClass().getName() + '_' + this.eGet(this.eClass().getEIDAttribute()));
}
//================================================================================
// Reflection
eContainingFeature() {
const containerEClass = this._eContainer?.eClass();
if (containerEClass) {
const containingFeature = containerEClass.getEStructuralFeature(this._eContainingFeature);
return containingFeature;
}
return undefined;
}
// //TODO: What does this even mean?
// public eContainmentFeature() : EStructuralFeature | undefined{
// return undefined;
// }
eContents() {
const contents = new Array();
const containments = this.eClass().getEAllContainments();
for (let i = 0; i < containments.size(); i++) {
const cref = containments.get(i);
if (cref.isMany()) {
const containedList = this.eGet(cref);
for (let j = 0; j < containedList.size(); j++) {
contents.push(containedList.get(j));
}
}
else if (this.eGet(cref))
contents.push(this.eGet(cref));
}
return contents;
}
eAllContents() {
let all = new Array();
all.push(this);
for (const contained of this.eContents()) {
all = all.concat(contained.eAllContents());
}
return all;
}
eIsProxy() {
return this._eIsProxy;
}
eSetProxy(proxy) {
this._eIsProxy = proxy;
}
//================================================================================
// Generic getting/setting
eGet(feature) {
return undefined;
}
eSet(feature, value) {
//do nothing
}
eIsSet(feature) {
throw false;
}
eUnset(feature) {
//do nothing
}
}
exports.EObjectImpl = EObjectImpl;
//# sourceMappingURL=eobjectimpl.js.map