class Parser::Rewriter
{Parser::Rewriter} is deprecated. Use {Parser::TreeRewriter} instead. It has a backwards compatible API and uses {Parser::Source::TreeRewriter} instead of {Parser::Source::Rewriter}. Please check the documentation for {Parser::Source::Rewriter} for details.
@api public @deprecated Use {Parser::TreeRewriter}
Constants
- DEPRECATION_WARNING
Public Class Methods
Source
# File lib/parser/rewriter.rb, line 98 def initialize(*) self.class.warn_of_deprecation Source::Rewriter.warned_of_deprecation = true super end
Public Instance Methods
Source
# File lib/parser/rewriter.rb, line 38 def assignment?(node) [:lvasgn, :ivasgn, :gvasgn, :cvasgn, :casgn].include?(node.type) end
Returns ‘true` if the specified node is an assignment node, returns false otherwise.
@param [Parser::AST::Node] node @return [Boolean]
Source
# File lib/parser/rewriter.rb, line 77 def insert_after(range, content) @source_rewriter.insert_after(range, content) end
Inserts new code after the given source range.
@param [Parser::Source::Range] range @param [String] content
Source
# File lib/parser/rewriter.rb, line 67 def insert_before(range, content) @source_rewriter.insert_before(range, content) end
Inserts new code before the given source range.
@param [Parser::Source::Range] range @param [String] content
Source
# File lib/parser/rewriter.rb, line 47 def remove(range) @source_rewriter.remove(range) end
Removes the source range.
@param [Parser::Source::Range] range
Source
# File lib/parser/rewriter.rb, line 87 def replace(range, content) @source_rewriter.replace(range, content) end
Replaces the code of the source range ‘range` with `content`.
@param [Parser::Source::Range] range @param [String] content
Source
# File lib/parser/rewriter.rb, line 23 def rewrite(source_buffer, ast) @source_rewriter = Source::Rewriter.new(source_buffer) process(ast) @source_rewriter.process end
Rewrites the AST/source buffer and returns a String containing the new version.
@param [Parser::Source::Buffer] source_buffer @param [Parser::AST::Node] ast @return [String]
Source
# File lib/parser/rewriter.rb, line 57 def wrap(range, before, after) @source_rewriter.wrap(range, before, after) end
Wraps the given source range with the given values.
@param [Parser::Source::Range] range @param [String] content