Class: NodeMutation::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/node_mutation/adapter.rb

Direct Known Subclasses

ParserAdapter

Instance Method Summary collapse

Instance Method Details

#child_node_range(node, child_name) ⇒ { start: Number, end: Number }

Get the start/end range of the child node

Parameters:

  • node (Node)

    ast node

  • child_name (String)

    child name selector

Returns:

  • ({ start: Number, end: Number })

    child node range

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/node_mutation/adapter.rb', line 32

def child_node_range(node, child_name)
  raise NotImplementedError, "child_node_range is not implemented"
end

#file_content(node) ⇒ Object

The file content of the ast node file

Parameters:

  • node (Node)

    ast node

Returns:

  • file content

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/node_mutation/adapter.rb', line 24

def file_content(node)
  raise NotImplementedError, "file_content is not implemented"
end

#get_end(node) ⇒ Number

Get end position of ast node

Parameters:

  • node (Node)

    ast node

Returns:

  • (Number)

    end position

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/node_mutation/adapter.rb', line 46

def get_end(node)
  raise NotImplementedError, "get_end is not implemented"
end

#get_end_loc(node) ⇒ { line: Number, column: Number }

Get end location of ast node

Parameters:

  • node (Node)

    ast node

Returns:

  • ({ line: Number, column: Number })

    end location

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/node_mutation/adapter.rb', line 60

def get_end_loc(node)
  raise NotImplementedError, "get_end_loc is not implemented"
end

#get_indent(node) ⇒ Number

Get indent of ast node

Parameters:

  • node (Node)

    ast node

Returns:

  • (Number)

    indent

Raises:

  • (NotImplementedError)


67
68
69
# File 'lib/node_mutation/adapter.rb', line 67

def get_indent(node)
  raise NotImplementedError, "get_indent is not implemented"
end

#get_source(node) ⇒ String

Get source code of the ast node

Parameters:

  • node (Node)

    ast node

Returns:

  • (String)

    source code

Raises:

  • (NotImplementedError)


7
8
9
# File 'lib/node_mutation/adapter.rb', line 7

def get_source(node)
  raise NotImplementedError, "get_source is not implemented"
end

#get_start(node) ⇒ Number

Get start position of ast node

Parameters:

  • node (Node)

    ast node

Returns:

  • (Number)

    start position

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/node_mutation/adapter.rb', line 39

def get_start(node)
  raise NotImplementedError, "get_start is not implemented"
end

#get_start_loc(node) ⇒ { line: Number, column: Number }

Get start location of ast node

Parameters:

  • node (Node)

    ast node

Returns:

  • ({ line: Number, column: Number })

    start location

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/node_mutation/adapter.rb', line 53

def get_start_loc(node)
  raise NotImplementedError, "get_start_loc is not implemented"
end

#rewritten_source(node, code) ⇒ String

Replace the child node selector with child node source code it will return ‘Boolean(foobar)`

Examples:

# source code of ast node is ‘!!foobar`, code is `Boolean(NodeMutation::Adapter.{expression{expression.operand{expression.operand.operand})`,

Parameters:

  • node (Node)

    ast node

  • code (String)

    code with child node selector, e.g. ‘Boolean(NodeMutation::Adapter.{expression{expression.operand{expression.operand.operand})`

Returns:

  • (String)

    code with source code of child node selector,

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/node_mutation/adapter.rb', line 17

def rewritten_source(node, code)
  raise NotImplementedError, "rewritten_source is not implemented"
end