@yellicode/elements
Version:
The meta model API for Yellicode - an extensible code generator.
41 lines (40 loc) • 1.46 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/.
*/
import { ElementTypeUtility } from '../utils';
/**
* A base class for transforms that need to be applied recursively to all nested packaged elements
* in a model or package.
*/
var PackagedElementTransform = /** @class */ (function () {
function PackagedElementTransform() {
}
/**
* Transforms the package and returns the transformation result.
* @param pack The package or model to transform.
*/
PackagedElementTransform.prototype.transform = function (pack) {
if (pack == null)
return pack;
this.transformElement(pack);
this.transformPackageRecursive(pack);
return pack;
};
PackagedElementTransform.prototype.transformPackageRecursive = function (pack) {
var _this = this;
if (pack.packagedElements == null)
return;
pack.packagedElements.forEach(function (element) {
_this.transformElement(element);
if (ElementTypeUtility.isPackage(element.elementType)) {
_this.transformPackageRecursive(element);
}
});
};
return PackagedElementTransform;
}());
export { PackagedElementTransform };