Class: Parser::Source::Rewriter Deprecated

Inherits:
Object
  • Object
show all
Extended by:
Deprecation
Defined in:
sorbet/rbi/parser@3.3.7.4.rbi

Overview

Deprecated.

Rewriter is deprecated. Use TreeRewriter instead.

TreeRewriter has simplified semantics, and customizable policies with regards to clobbering. Please read the documentation.

Keep in mind:

  • Rewriter was discarding the end_pos of the given range for insert_before, and the begin_pos for insert_after. These are meaningful in TreeRewriter.
  • TreeRewriter's wrap/insert_before/insert_after are multiple by default, while Rewriter would raise clobbering errors if the non '_multi' version was called.
  • The TreeRewriter policy closest to Rewriter's behavior is: different_replacements: :raise, swallowed_insertions: :raise, crossing_deletions: :accept

source://parser//lib/parser/source/rewriter.rb#31

Defined Under Namespace

Classes: Action

Constant Summary collapse

DEPRECATION_WARNING =

source://parser//lib/parser/source/rewriter.rb#504

T.let(T.unsafe(nil), String)

Instance Method Summary collapse

Methods included from Deprecation

warn_of_deprecation, warned_of_deprecation=

Constructor Details

#initialize(source_buffer) ⇒ Rewriter

Deprecated.

source://parser//lib/parser/source/rewriter.rb#39

Parameters:



6279
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6279

def initialize(source_buffer); end

Instance Method Details

#diagnosticsDiagnostic::Engine

source://parser//lib/parser/source/rewriter.rb#33

Returns:



6285
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6285

def diagnostics; end

#insert_after(range, content) ⇒ Rewriter

Deprecated.

Inserts new code after the given source range.

source://parser//lib/parser/source/rewriter.rb#131

Parameters:

Returns:

Raises:



6297
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6297

def insert_after(range, content); end

#insert_after_multi(range, content) ⇒ Rewriter

Deprecated.

Inserts new code after the given source range by allowing other insertions at the same position. Note that an insertion with latter invocation comes after earlier insertion at the same position in the rewritten source.

source://parser//lib/parser/source/rewriter.rb#153

Examples:

Inserting ')]'

rewriter.
insert_after_multi(range, ')').
insert_after_multi(range, ']').
process

Parameters:

Returns:

Raises:



6317
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6317

def insert_after_multi(range, content); end

#insert_before(range, content) ⇒ Rewriter

Inserts new code before the given source range.

source://parser//lib/parser/source/rewriter.rb#80

Parameters:

Returns:

Raises:



6329
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6329

def insert_before(range, content); end

#insert_before_multi(range, content) ⇒ Rewriter

Inserts new code before the given source range by allowing other insertions at the same position. Note that an insertion with latter invocation comes before earlier insertion at the same position in the rewritten source.

source://parser//lib/parser/source/rewriter.rb#117

Examples:

Inserting '[('

rewriter.
insert_before_multi(range, '(').
insert_before_multi(range, '[').
process

Parameters:

Returns:

Raises:



6349
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6349

def insert_before_multi(range, content); end

#processString

Deprecated.

Applies all scheduled changes to the source_buffer and returns modified source as a new string.

source://parser//lib/parser/source/rewriter.rb#178

Returns:



6359
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6359

def process; end

#remove(range) ⇒ Rewriter

Deprecated.

Removes the source range.

source://parser//lib/parser/source/rewriter.rb#67

Parameters:

Returns:

Raises:



6370
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6370

def remove(range); end

#replace(range, content) ⇒ Rewriter

Deprecated.

Replaces the code of the source range range with content.

source://parser//lib/parser/source/rewriter.rb#167

Parameters:

Returns:

Raises:



6382
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6382

def replace(range, content); end

#source_bufferSource::Buffer

source://parser//lib/parser/source/rewriter.rb#32

Returns:



6388
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6388

def source_buffer; end

#transactionObject

Deprecated.

Provides a protected block where a sequence of multiple rewrite actions are handled atomically. If any of the actions failed by clobbering, all the actions are rolled back.

source://parser//lib/parser/source/rewriter.rb#216

Examples:

begin
rewriter.transaction do
rewriter.insert_before(range_of_something, '(')
rewriter.insert_after(range_of_something, ')')
end
rescue Parser::ClobberingError
end

Raises:

  • (RuntimeError)

    when no block is passed

  • (RuntimeError)

    when already in a transaction



6408
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6408

def transaction; end

#wrap(range, before, after) ⇒ Rewriter

Deprecated.

Inserts new code before and after the given source range.

source://parser//lib/parser/source/rewriter.rb#94

Parameters:

Returns:

Raises:



6421
# File 'sorbet/rbi/parser@3.3.7.4.rbi', line 6421

def wrap(range, before, after); end