@microsoft.azure/autorest.incubator
Version:
AutoRest incubator project
101 lines • 3.42 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const initializer_1 = require("../../../common/initializer");
const text_manipulation_1 = require("../../../common/text-manipulation");
const literal_1 = require("../../../csharp/code-dom/statements/literal");
function toStatement(statement) {
return typeof statement === 'string' ? new literal_1.LiteralStatement(statement) : statement;
}
exports.toStatement = toStatement;
function isStatement(object) {
return object.implementation ? true : false;
}
exports.isStatement = isStatement;
class Statements extends initializer_1.Initializer {
constructor(statements, objectIntializer) {
super();
this.statements = new Array();
if (statements) {
this.add(statements);
}
this.apply(objectIntializer);
}
get count() {
return this.statements.length;
}
insert(statements) {
if (typeof (statements) === 'string') {
this.statements.splice(0, 0, new literal_1.LiteralStatement(statements));
return this;
}
if (statements instanceof Statements) {
this.statements.splice(0, 0, statements);
return this;
}
if (isStatement(statements)) {
this.statements.splice(0, 0, statements);
return this;
}
if (typeof (statements) === 'function') {
return this.insert(statements());
}
for (const each of statements) {
this.insert(each);
}
return this;
}
add(statements) {
if (typeof (statements) === 'string') {
this.statements.push(new literal_1.LiteralStatement(statements));
return this;
}
if (statements instanceof Statements) {
this.statements.push(statements);
return this;
}
if (isStatement(statements)) {
this.statements.push(statements);
return this;
}
if (typeof (statements) === 'function') {
return this.add(statements());
}
for (const each of statements) {
this.add(each);
}
return this;
}
appendStatements(statements) {
if (!statements) {
return this;
}
if (typeof statements === 'function') {
statements = statements();
}
if (typeof statements === 'string') {
if (statements.trim().length > 0) {
this.statements.push(new literal_1.LiteralStatement(statements));
}
return this;
}
if (typeof statements === 'object') {
if (isStatement(statements)) {
this.statements.push(statements);
return this;
}
if (statements instanceof Statements) {
this.statements.push(...statements.statements);
return this;
}
for (const statement of statements) {
this.statements.push(typeof statement === 'string' ? new literal_1.LiteralStatement(statement) : statement);
}
}
return this;
}
get implementation() {
return `${this.statements.joinWith(each => each.implementation, text_manipulation_1.EOL)}`.trim();
}
}
exports.Statements = Statements;
//# sourceMappingURL=statement.js.map