@yellicode/elements
Version:
The meta model API for Yellicode - an extensible code generator.
89 lines (88 loc) • 5.63 kB
JavaScript
import * as utils from "./utils";
/**
* Default implementation of the TypeNameProvider interface. This implementation
* returns type names as-is, but allows inheritors to provide their own implementation
* by overriding getTypeNameForType and/or getTypeNameForTypedElement.
*/
var DefaultTypeNameProvider = /** @class */ (function () {
function DefaultTypeNameProvider() {
}
DefaultTypeNameProvider.prototype.getTypeName = function (typeOrTypedElement) {
if (utils.isTypedElement(typeOrTypedElement)) {
// The argument is a typedElement
var isMultiValued = utils.isMultiplicityElement(typeOrTypedElement) && typeOrTypedElement.isMultivalued();
return this.getTypeNameForTypedElement(typeOrTypedElement, utils.isDataType(typeOrTypedElement.type), isMultiValued);
}
else {
// The argument is a type
return this.getTypeNameForType(typeOrTypedElement, utils.isDataType(typeOrTypedElement));
}
};
/**
* Returns the name of the provided type. This function is also called by getTypeNameOfTypedElement() if that function is not overridden.
* @param type The type information.
* @param isDataType Indicates if the type is a data type (that is, an Enumeration, PrimitiveType or DataType).
*/
DefaultTypeNameProvider.prototype.getTypeNameForType = function (type, isDataType) {
// Note: we don't use isDataType in this default implementation, but it is considered relevant for implementers.
return type ? type.name : null;
};
/**
* Returns the name of the provided element's type. Internally, this function calls getTypeNameForType for the type, but
* you should override this function if you need to provide different type names for a type depending on the context.
* For example, you may return a different type name for a property or parameter that is multi-valued.
* @param typedElement Any element that has a type.
* @param isDataType Indicates if the element's type is a data type (that is, an Enumeration, PrimitiveType or DataType).
* @param isMultiValued Indicates if the TypedElement is multi-valued (that is, has an upper bound greater than 1).
*/
DefaultTypeNameProvider.prototype.getTypeNameForTypedElement = function (typedElement, isDataType, isMultiValued) {
// Note: we don't use isMultiValued in this default implementation, but it is considered relevant for implementers.
return this.getTypeNameForType(typedElement.type, isDataType);
};
/**
* DEPRECATED: Returns the name of the provided element's data type. Override this function to map primitives and other data types
* (both built-in or types exported from a profile) to the target language. The default implementation calls the
* getDataTypeNameForType function using the type of the typedElement.
* @param typedElement Any TypedElement instance.
* @deprecated Please override getTypeNameForTypedElement instead.
*/
DefaultTypeNameProvider.prototype.getDataTypeName = function (typedElement) {
console.warn("DefaultTypeNameProvider.getDataTypeName is deprecated. Please override getTypeNameForTypedElement instead.");
var isMultiValued = utils.isMultiplicityElement(typedElement) && typedElement.isMultivalued();
return this.getTypeNameForTypedElement(typedElement, true, isMultiValued);
};
/**
* DEPRECATED: Returns the name of the provided data type. Override this function to map primitives and other data types
* (both built-in or types exported from a profile) to the target language.
* @param type The type information.
* @deprecated Please override getTypeNameForType instead.
*/
DefaultTypeNameProvider.prototype.getDataTypeNameForType = function (type) {
console.warn("DefaultTypeNameProvider.getDataTypeNameForType is deprecated. Please override getTypeNameForType instead.");
return this.getTypeNameForType(type, true);
};
/**
* DEPRECATED: Returns the name of the provided element's complex type (any type that is not a DataType). Override this function to provide
* a custom name for the complex type. The default implementation calls the getComplexTypeNameForType function using
* the type of the typedElement.
* @param typedElement Any TypedElement instance.
* @deprecated Please override getTypeNameForTypedElement instead.
*/
DefaultTypeNameProvider.prototype.getComplexTypeName = function (typedElement) {
console.warn("DefaultTypeNameProvider.getComplexTypeName is deprecated. Please override getTypeNameForTypedElement instead.");
var isMultiValued = utils.isMultiplicityElement(typedElement) && typedElement.isMultivalued();
return this.getTypeNameForTypedElement(typedElement, false, isMultiValued);
};
/**
* DEPRECATED: Returns the name of the provided complex type (any type that is not a DataType). Override this function to provide
* a custom name for the complex type.
* @param type The type information.
* @deprecated Please override getTypeNameForType instead.
*/
DefaultTypeNameProvider.prototype.getComplexTypeNameForType = function (type) {
console.warn("DefaultTypeNameProvider.getComplexTypeNameForType is deprecated. Please override getTypeNameForType instead.");
return this.getTypeNameForType(type, false);
};
return DefaultTypeNameProvider;
}());
export { DefaultTypeNameProvider };