Class: Parser::Rewriter Deprecated
- Inherits:
-
AST::Processor
- Object
- AST::Processor
- Parser::Rewriter
- Extended by:
- Deprecation
- Defined in:
- lib/parser/rewriter.rb
Overview
Use TreeRewriter
Rewriter is deprecated. Use TreeRewriter instead. It has a backwards compatible API and uses Source::TreeRewriter instead of Source::Rewriter. Please check the documentation for Source::Rewriter for details.
Constant Summary collapse
- DEPRECATION_WARNING =
[ 'Parser::Rewriter is deprecated.', 'Please update your code to use Parser::TreeRewriter instead' ].join("\n").freeze
Instance Attribute Summary
Attributes included from Deprecation
Instance Method Summary collapse
-
#assignment?(node) ⇒ Boolean
Returns ‘true` if the specified node is an assignment node, returns false otherwise.
-
#initialize ⇒ Rewriter
constructor
A new instance of Rewriter.
-
#insert_after(range, content) ⇒ Object
Inserts new code after the given source range.
-
#insert_before(range, content) ⇒ Object
Inserts new code before the given source range.
-
#remove(range) ⇒ Object
Removes the source range.
-
#replace(range, content) ⇒ Object
Replaces the code of the source range ‘range` with `content`.
-
#rewrite(source_buffer, ast) ⇒ String
Rewrites the AST/source buffer and returns a String containing the new version.
-
#wrap(range, before, after) ⇒ Object
Wraps the given source range with the given values.
Methods included from Deprecation
Methods inherited from AST::Processor
#on_arg, #on_argument, #on_back_ref, #on_blockarg, #on_casgn, #on_const, #on_cvar, #on_cvasgn, #on_def, #on_defs, #on_empty_else, #on_forward_arg, #on_gvar, #on_gvasgn, #on_ivar, #on_ivasgn, #on_kwarg, #on_kwoptarg, #on_kwrestarg, #on_lvar, #on_lvasgn, #on_match_var, #on_nth_ref, #on_numblock, #on_op_asgn, #on_optarg, #on_procarg0, #on_restarg, #on_send, #on_shadowarg, #on_var, #on_vasgn, #process_argument_node, #process_regular_node, #process_var_asgn_node, #process_variable_node
Constructor Details
Instance Method Details
#assignment?(node) ⇒ Boolean
Returns ‘true` if the specified node is an assignment node, returns false otherwise.
38 39 40 |
# File 'lib/parser/rewriter.rb', line 38 def assignment?(node) [:lvasgn, :ivasgn, :gvasgn, :cvasgn, :casgn].include?(node.type) end |
#insert_after(range, content) ⇒ Object
Inserts new code after the given source range.
77 78 79 |
# File 'lib/parser/rewriter.rb', line 77 def insert_after(range, content) @source_rewriter.insert_after(range, content) end |
#insert_before(range, content) ⇒ Object
Inserts new code before the given source range.
67 68 69 |
# File 'lib/parser/rewriter.rb', line 67 def insert_before(range, content) @source_rewriter.insert_before(range, content) end |
#remove(range) ⇒ Object
Removes the source range.
47 48 49 |
# File 'lib/parser/rewriter.rb', line 47 def remove(range) @source_rewriter.remove(range) end |
#replace(range, content) ⇒ Object
Replaces the code of the source range ‘range` with `content`.
87 88 89 |
# File 'lib/parser/rewriter.rb', line 87 def replace(range, content) @source_rewriter.replace(range, content) end |
#rewrite(source_buffer, ast) ⇒ String
Rewrites the AST/source buffer and returns a String containing the new version.
23 24 25 26 27 28 29 |
# 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 |
#wrap(range, before, after) ⇒ Object
Wraps the given source range with the given values.
57 58 59 |
# File 'lib/parser/rewriter.rb', line 57 def wrap(range, before, after) @source_rewriter.wrap(range, before, after) end |