@tripsnek/tmf
Version:
TypeScript Modeling Framework - A TypeScript port of the Eclipse Modeling Framework (EMF)
243 lines • 8.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EPackage = void 0;
const basicelist_1 = require("./basicelist");
const enamed_element_impl_1 = require("./enamed-element-impl");
const eattribute_impl_1 = require("./eattribute-impl");
const eclass_impl_1 = require("./eclass-impl");
const eoperation_impl_1 = require("./eoperation-impl");
const ereference_impl_1 = require("./ereference-impl");
const eenum_impl_1 = require("./eenum-impl");
const edata_type_impl_1 = require("./edata-type-impl");
const eenum_literal_impl_1 = require("./eenum-literal-impl");
const eparameter_impl_1 = require("./eparameter-impl");
class EPackage extends enamed_element_impl_1.ENamedElementImpl {
static EPACKAGE; // Initialized in EClass
static ECORE; // Initialized in EClass
/**
* A map from {@link EPackage#getNsURI() namespace URI} to {@link EPackage}.
*
* NOTE: This is a significant simplication of the EPackage.Registry in EMF, in
* that it consolidates several classes into one.
*/
static Registry = class Registry extends Map {
static INSTANCE = new Registry();
register(pkg) {
if (!this.has(pkg.getNsURI())) {
this.set(pkg.getNsURI(), pkg);
}
}
/**
* Looks up the value in the map.
*/
getEPackage(nsURI) {
return this.get(nsURI);
}
/**
* Looks up the value in the map.
*/
getEFactory(nsURI) {
return this.get(nsURI).getEFactoryInstance();
}
};
_eClassifiers = new basicelist_1.BasicEList();
_eSubPackages = new basicelist_1.BasicEList();
_eSuperPackage;
_nsPrefix;
_nsURI;
_eFactoryInstance;
constructor(name, nsUri, nsPrefix) {
super(name);
if (nsUri) {
this.setNsURI(nsUri);
EPackage.Registry.INSTANCE.register(this);
}
if (nsPrefix) {
this.setNsPrefix(nsPrefix);
}
}
getEClassifier(name) {
return this._eClassifiers.find((e) => e.getName() === name);
}
getESubPackageByName(name) {
return this._eSubPackages.find((e) => e.getName() === name);
}
// TODO: Protected is probably not right
// This method is probably to be invoked by setting an inverse field
addEClassifier(eClassifier) {
this._eClassifiers.add(eClassifier);
}
getEClassifiers() {
return this._eClassifiers;
}
getESubPackages() {
return this._eSubPackages;
}
getESuperPackage() {
return this._eSuperPackage;
}
setESuperPackage(superPkg) {
//TODO: should handle inverse reference on both ends
this._eSuperPackage = superPkg;
if (!this._eSuperPackage.getESubPackages().contains(this))
this._eSuperPackage.getESubPackages().add(this);
}
getNsPrefix() {
return this._nsPrefix;
}
setNsPrefix(value) {
this._nsPrefix = value;
}
getNsURI() {
return this._nsURI;
}
setNsURI(value) {
this._nsURI = value;
}
//======================================================================
// Factory-related methods
getEFactoryInstance() {
return this._eFactoryInstance;
}
setEFactoryInstance(value) {
this._eFactoryInstance = value;
}
createEEnum(id) {
const c = new eenum_impl_1.EEnumImpl();
c.setClassifierId(id);
c.setEPackage(this);
this.getEClassifiers().add(c);
return c;
}
createEDataType(id) {
const c = new edata_type_impl_1.EDataTypeImpl();
c.setClassifierId(id);
c.setEPackage(this);
this.getEClassifiers().add(c);
return c;
}
createEClass(id) {
const c = new eclass_impl_1.EClassImpl();
c.setClassifierId(id);
this.getEClassifiers().add(c);
c.setEPackage(this);
return c;
}
addEEnumLiteral(owner, literal, value) {
//NOTE: This is different from the EMF implementation, which exploits the
//fact that Java allows enums to implement interfaces. To replicate that in
//typescript, we would probably have to use types. If so, we should need only
//to pass in an instance of that base class (Enumerator in EMF) as 'literal'
const l = new eenum_literal_impl_1.EEnumLiteralImpl();
l.setLiteral(literal);
l.setName(literal);
l.setInstance(literal);
l.setValue(value);
l.setEEnum(owner);
owner.getELiterals().add(l);
}
initEClass(c, instanceClassName, isAbstract, isInterface, isGenerated) {
this.initEClassifier(c, instanceClassName, isGenerated);
c.setAbstract(isAbstract);
c.setInterface(isInterface);
return c;
}
initEEnum(e, instanceClassName) {
this.initEClassifier(e, instanceClassName, true);
return e;
}
initEDataType(e, instanceClassName) {
this.initEClassifier(e, instanceClassName, true);
return e;
}
initEClassifier(o, instanceClassName, isGenerated) {
o.setName(instanceClassName);
// if (instanceClassName != null) {
// o.setInstanceClass(instanceClassName);
// }
if (isGenerated) {
//TODO: Should we add this generated class name stuff to EClassifier?
// setGeneratedClassName(o);
}
}
initEReference(r, type, otherEnd, name, defaultValue, lowerBound, upperBound, containerClass, isTransient, isVolatile, isChangeable, isContainment, isResolveProxies, isUnsettable, isUnique, isDerived, isOrdered) {
this.initEStructuralFeature(r, type, name, defaultValue, lowerBound, upperBound, containerClass, isTransient, isVolatile, isChangeable, isUnsettable, isUnique, isDerived, isOrdered);
r.setContainment(isContainment);
if (otherEnd != null) {
r.setEOpposite(otherEnd);
}
// r.setResolveProxies(isResolveProxies);
return r;
}
initEAttribute(a, type, name, defaultValue, lowerBound, upperBound, containerClass, isTransient, isVolatile, isChangeable, isUnsettable, isID, isUnique, isDerived, isOrdered) {
this.initEStructuralFeature(a, type, name, defaultValue, lowerBound, upperBound, containerClass, isTransient, isVolatile, isChangeable, isUnsettable, isUnique, isDerived, isOrdered);
a.setId(isID);
return a;
}
initEStructuralFeature(s, type, name, defaultValue, lowerBound, upperBound, containerClass, isTransient, isVolatile, isChangeable, isUnsettable, isUnique, isDerived, isOrdered) {
s.setName(name);
// s.setContainerClass(containerClass);
s.setTransient(isTransient);
s.setVolatile(isVolatile);
s.setChangeable(isChangeable);
// s.setUnsettable(isUnsettable);
s.setUnique(isUnique);
// s.setDerived(isDerived);
// s.setOrdered(isOrdered);
s.setLowerBound(lowerBound);
s.setUpperBound(upperBound);
s.setEType(type);
if (defaultValue != null) {
s.setDefaultValueLiteral(defaultValue);
}
}
initEOperation(eOperation, type, name, lowerBound, upperBound, isUnique, isOrdered) {
if (type)
eOperation.setEType(type);
eOperation.setName(name);
if (lowerBound)
eOperation.setLowerBound(lowerBound);
if (upperBound)
eOperation.setUpperBound(upperBound);
eOperation.setUnique(isUnique ?? false);
// eOperation.setOrdered(isOrdered ?? false);
return eOperation;
}
createEOperation(owner, id) {
const o = new eoperation_impl_1.EOperationImpl();
o.setOperationID(id);
o.setEContainingClass(owner);
owner.getEOperations().add(o);
}
createEParameter(owner, name, upperBound, type) {
const param = new eparameter_impl_1.EParameterImpl();
param.setName(name);
if (type)
param.setEType(type);
param.setUpperBound(upperBound);
//TODO: Would not have to do both if model was source generated
owner.getEParameters().add(param);
}
createEAttribute(owner, id) {
const a = new eattribute_impl_1.EAttributeImpl();
a.setFeatureID(id);
owner.getEStructuralFeatures().add(a);
a.setEContainingClass(owner);
}
createEReference(owner, id) {
const r = new ereference_impl_1.EReferenceImpl();
r.setFeatureID(id);
owner.getEStructuralFeatures().add(r);
r.setEContainingClass(owner);
}
getRootPackage() {
if (!this.getESuperPackage())
return this;
let cursor = this.getESuperPackage();
while (cursor.getESuperPackage() != null)
cursor = cursor.getESuperPackage();
return cursor;
}
}
exports.EPackage = EPackage;
//# sourceMappingURL=epackage.js.map