UNPKG

@atomist/rug

Version:

TypeScript model for Atomist Rugs, see http://docs.atomist.com/

75 lines (74 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var AstHelper_1 = require("./AstHelper"); var RugOperation_1 = require("../operations/RugOperation"); var treeHelper = require("../tree/TreeHelper"); /** * Base class for decorators on node. * Allows us to get to the containing File and update text. * Extended by specific classes, but also mixed in on its * own if we don't find a specific class. */ var TextTreeNodeOps = (function () { /** * Create a new TextTreeNodeOps, wrapping a given node. * Usually called by infrastructure, not end user. * @param node node to decorate * @param pexe expression engine that methods can use */ function TextTreeNodeOps(node, pexe) { this.node = node; this.pexe = pexe; this.astHelper = new AstHelper_1.AstHelper(pexe); } /** * Delete this node. */ TextTreeNodeOps.prototype.delete = function () { this.node.update(""); }; /** * Append the given value to the content of this node. * Include whitespace or newline if you want it. * @param what content to append */ TextTreeNodeOps.prototype.append = function (what) { this.node.update("" + this.node.value() + what); }; /** * Prepend the given value to the content of this node. * Include whitespace or newline if you want it. * @param what content to prepend */ TextTreeNodeOps.prototype.prepend = function (what) { this.node.update("" + what + this.node.value()); }; /** * Return the file this node is contained in. */ TextTreeNodeOps.prototype.containingFile = function () { return treeHelper.findAncestorWithTag(this.node, "File"); }; /** * Return an issue concerning this, containing format information if available */ TextTreeNodeOps.prototype.commentConcerning = function (comment, severity) { var f = this.containingFile(); var line = 1; var col = 1; var point = this.node.formatInfo.start; if (point) { line = point.lineNumberFrom1; col = point.columnNumberFrom1; } return new RugOperation_1.ReviewComment(f.project.name, comment, severity, f.path, line, col); }; /** * Add a comment to these ReviewResults */ TextTreeNodeOps.prototype.addCommentConcerning = function (comments, comment, severity) { comments.push(this.commentConcerning(comment, severity)); }; return TextTreeNodeOps; }()); exports.TextTreeNodeOps = TextTreeNodeOps;