@microsoft.azure/autorest.incubator
Version:
AutoRest incubator project
65 lines • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const initializer_1 = require("../../common/initializer");
const access_modifier_1 = require("../../csharp/code-dom/access-modifier");
const expression_1 = require("../../csharp/code-dom/expression");
const text_manipulation_1 = require("../../common/text-manipulation");
/** represents a field in a Class */
class Field extends initializer_1.Initializer {
constructor(name, type, objectInitializer) {
super();
this.name = name;
this.type = type;
this['new'] = access_modifier_1.Modifier.None;
this.access = access_modifier_1.Access.Public;
this['static'] = access_modifier_1.Modifier.None;
this['readonly'] = access_modifier_1.Modifier.None;
this.volitile = access_modifier_1.Modifier.None;
this.attributes = new Array();
this.description = '';
this.apply(objectInitializer);
}
get attributeDeclaration() {
return this.attributes.length > 0 ? `${this.attributes.joinWith(each => `${expression_1.valueOf(each)}`, text_manipulation_1.EOL)}${text_manipulation_1.EOL}` : '';
}
get declaration() {
return `${this.attributeDeclaration}${this.new}${this.access} ${this.static} ${this.readonly} ${this.volitile} ${this.type.declaration} ${this.name};`.slim();
}
get value() {
return `${this.name}`;
}
toString() {
return this.value;
}
assign(expression) {
if (this.readonly) {
throw new Error('Readonly Field can not be assigned');
}
return `${this.name} = ${expression_1.valueOf(expression)};`;
}
assignPrivate(expression) {
if (this.readonly) {
throw new Error('Readonly Field can not be assigned');
}
return this.assign(expression);
}
get declarationExpression() {
return this;
}
get declarationStatement() {
throw new Error(`Property can not be a declaration statement`);
}
}
exports.Field = Field;
class InitializedField extends Field {
constructor(name, type, valueExpression, objectInitializer) {
super(name, type);
this.valueExpression = valueExpression;
this.apply(objectInitializer);
}
get declaration() {
return `${this.attributeDeclaration}${this.new}${this.access} ${this.static} ${this.readonly} ${this.volitile} ${this.type.declaration} ${this.name} = ${expression_1.valueOf(this.valueExpression)};`.slim();
}
}
exports.InitializedField = InitializedField;
//# sourceMappingURL=field.js.map