UNPKG

@microsoft.azure/autorest.incubator

Version:
89 lines 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const text_manipulation_1 = require("../../common/text-manipulation"); const field_1 = require("./field"); const type_1 = require("./type"); const expression_1 = require("../../csharp/code-dom/expression"); const utility_1 = require("../../common/utility"); function sortByNamePartialFirst(a, b) { if (a.isPartial !== b.isPartial) { return a.isPartial ? -1 : 1; } return text_manipulation_1.sortByName(a, b); } exports.sortByNamePartialFirst = sortByNamePartialFirst; class Class extends type_1.Type { constructor(namespace, name, parent, objectIntializer) { super(namespace, name); this.parent = parent; this.classOrStruct = 'class'; this.isStatic = false; this.fields = new Array(); this.addGeneratedCodeAttribute = false; this.apply(objectIntializer); namespace.addClass(this); } get codeGenAttribute() { return this.addGeneratedCodeAttribute ? '\n[System.CodeDom.Compiler.GeneratedCode("AutoRest/Incubator", "1.1")]' : ''; } get signature() { const colon = (this.parent || this.interfaces.length > 0) ? ' : ' : ''; const comma = (this.parent && this.interfaces.length > 0) ? ', ' : ''; const extendsClass = this.parent ? this.parent.fullName : ''; const implementsInterfaces = this.interfaces.map(v => v.fullName).join(', '); const description = text_manipulation_1.comment(this.description, text_manipulation_1.docCommentPrefix); const partial = this.partial ? 'partial ' : ''; const stat = this.isStatic ? 'static ' : ''; return ` ${description}${this.codeGenAttribute} ${this.attributeDeclaration}${this.accessModifier} ${stat}${partial}${this.classOrStruct} ${this.name}${colon}${extendsClass}${comma}${implementsInterfaces} `.trim(); } get definition() { const fields = this.fields.sort(text_manipulation_1.sortByName).map(m => m.declaration).join(text_manipulation_1.EOL); const methods = this.methods.sort(sortByNamePartialFirst).map(m => m.implementation).join(text_manipulation_1.EOL); let properties = this.properties.sort(text_manipulation_1.sortByName).map(m => m.declaration).join(text_manipulation_1.EOL); if (properties.indexOf('[]') > -1) { properties = `#pragma warning disable CA1819 // Properties should not return arrays ${properties} #pragma warning restore CA1819 // Properties should not return arrays`; } return ` ${this.signature} { ${text_manipulation_1.indent(fields, 1)} ${text_manipulation_1.indent(properties, 1)} ${text_manipulation_1.indent(methods, 1)} } `.trim(); } add(item) { if (item instanceof field_1.Field) { this.fields.push(item); return item; } return super.add(item); } addField(field) { this.fields.push(field); return field; } get declaration() { return ` ${this.fullName} `.trim(); } newInstance(...parameters) { return { value: `new ${this.name}(${parameters.joinWith(each => expression_1.valueOf(each))})` }; } property(name) { return this.properties.find(p => p.name === name) || utility_1.fail(`No property ${name}`); } $(name) { return this.properties.find(p => p.name === name) || this.methods.find(p => p.name === name) || this.fields.find(p => p.name === name) || utility_1.fail(`No property ${name}`); } } exports.Class = Class; //# sourceMappingURL=class.js.map