UNPKG

@microsoft.azure/autorest.incubator

Version:
112 lines 4.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const text_manipulation_1 = require("../../common/text-manipulation"); const access_modifier_1 = require("../../csharp/code-dom/access-modifier"); const doc_comments_1 = require("../../csharp/code-dom/doc-comments"); const dotnet = require("./mscorlib"); const statement_1 = require("./statements/statement"); const expression_1 = require("../../csharp/code-dom/expression"); class Method extends statement_1.Statements { constructor(name, returnType = dotnet.Void, objectIntializer) { super(); this.name = name; this.returnType = returnType; this.parameters = new Array(); this["new"] = access_modifier_1.Modifier.None; this.access = access_modifier_1.Access.Public; this["static"] = access_modifier_1.Modifier.None; this.virtual = access_modifier_1.Modifier.None; this.sealed = access_modifier_1.Modifier.None; this.override = access_modifier_1.Modifier.None; this.abstract = access_modifier_1.Modifier.None; this.extern = access_modifier_1.Modifier.None; this.async = access_modifier_1.Modifier.None; this.isPartial = false; this.description = ""; this.apply(objectIntializer); // easy access to allow statements in the initalizer. if (this.body) { this.add(this.body); } } addParameter(parameter) { this.parameters.push(parameter); return parameter; } get summaryDocumentation() { return text_manipulation_1.docComment(doc_comments_1.summary(this.description) + doc_comments_1.remarks(this.externalDocs)); } get parameterDocumentation() { return text_manipulation_1.docComment(this.parameters.joinWith(p => p.comment, text_manipulation_1.EOL)); } get declaration() { const parameterDeclaration = this.parameters.joinWith(p => p.declaration, text_manipulation_1.CommaChar); return ` ${this.summaryDocumentation} ${this.parameterDocumentation} ${this.new}${this.access} ${this.static} ${this.virtual} ${this.sealed} ${this.override} ${this.abstract} ${this.extern} ${this.async} ${this.returnType.declaration} ${this.name}(${parameterDeclaration}) `.slim(); } get interfaceDeclaration() { const parameterDeclaration = this.parameters.joinWith(p => p.declaration, text_manipulation_1.CommaChar); return ` ${this.summaryDocumentation} ${this.parameterDocumentation} ${this.returnType.declaration} ${this.name}(${parameterDeclaration}); `.slim(); } get implementation() { return ` ${this.declaration} { ${text_manipulation_1.indent(super.implementation)} }`.trim(); } invoke(...parameters) { return { value: `${this.name}(${parameters.joinWith(each => expression_1.valueOf(each))})` }; } addTo(parent) { parent.addMethod(this); return this; } } exports.Method = Method; class PartialMethod extends Method { constructor(name, returnType = dotnet.Void, objectIntializer) { super(name, returnType); this.isPartial = true; this.apply(objectIntializer); } get declaration() { const parameterDeclaration = this.parameters.joinWith(p => p.declaration, text_manipulation_1.CommaChar); return ` ${this.summaryDocumentation} ${this.parameterDocumentation} partial ${this.new}${this.access} ${this.static} ${this.virtual} ${this.sealed} ${this.override} ${this.abstract} ${this.extern} ${this.async} ${this.returnType.declaration} ${this.name}(${parameterDeclaration}) `.slim(); } get implementation() { return `${this.declaration};`.slim(); } } exports.PartialMethod = PartialMethod; class LambdaMethod extends Method { constructor(name, returnType = dotnet.Void, expression, objectIntializer) { super(name, returnType); this.expression = expression; this.apply(objectIntializer); } get declaration() { const parameterDeclaration = this.parameters.joinWith(p => p.declaration, text_manipulation_1.CommaChar); return ` ${this.summaryDocumentation} ${this.parameterDocumentation} ${this.new}${this.access} ${this.static} ${this.virtual} ${this.sealed} ${this.override} ${this.abstract} ${this.extern} ${this.async} ${this.returnType.declaration} ${this.name}(${parameterDeclaration}) => ${expression_1.valueOf(this.expression)} `.slim(); } get implementation() { return `${this.declaration};`.slim(); } } exports.LambdaMethod = LambdaMethod; //# sourceMappingURL=method.js.map