class SyntaxTree::Index::ParserBackend::IndexVisitor

Attributes

nesting[R]
results[R]
statements[R]

Public Class Methods

new() click to toggle source
# File lib/syntax_tree/index.rb, line 470
def initialize
  @results = []
  @nesting = []
  @statements = nil
end

Public Instance Methods

visit_alias(node) click to toggle source
Calls superclass method
# File lib/syntax_tree/index.rb, line 477
def visit_alias(node)
  if node.left.is_a?(SymbolLiteral) && node.right.is_a?(SymbolLiteral)
    location =
      Location.new(
        node.location.start_line,
        node.location.start_column
      )

    results << AliasMethodDefinition.new(
      nesting.dup,
      node.left.value.value.to_sym,
      location,
      comments_for(node)
    )
  end

  super
end
visit_assign(node) click to toggle source
Calls superclass method
# File lib/syntax_tree/index.rb, line 496
def visit_assign(node)
  if node.target.is_a?(VarField) && node.target.value.is_a?(Const)
    location =
      Location.new(
        node.location.start_line,
        node.location.start_column
      )

    results << ConstantDefinition.new(
      nesting.dup,
      node.target.value.value.to_sym,
      location,
      comments_for(node)
    )
  end

  super
end
visit_class(node) click to toggle source
Calls superclass method
# File lib/syntax_tree/index.rb, line 515
def visit_class(node)
  names = node.constant.accept(ConstantNameVisitor.new)
  nesting << names

  location =
    Location.new(node.location.start_line, node.location.start_column)

  superclass =
    if node.superclass
      visited = node.superclass.accept(ConstantNameVisitor.new)

      if visited == [[]]
        raise NotImplementedError, "superclass with non constant path"
      end

      visited
    else
      []
    end

  results << ClassDefinition.new(
    nesting.dup,
    names.last,
    superclass,
    location,
    comments_for(node)
  )

  super
  nesting.pop
end
visit_command(node) click to toggle source
Calls superclass method
# File lib/syntax_tree/index.rb, line 547
def visit_command(node)
  case node.message.value
  when "attr_reader", "attr_writer", "attr_accessor"
    comments = comments_for(node)
    location =
      Location.new(
        node.location.start_line,
        node.location.start_column
      )

    node.arguments.parts.each do |argument|
      next unless argument.is_a?(SymbolLiteral)
      name = argument.value.value.to_sym

      if node.message.value != "attr_writer"
        results << MethodDefinition.new(
          nesting.dup,
          name,
          location,
          comments
        )
      end

      if node.message.value != "attr_reader"
        results << MethodDefinition.new(
          nesting.dup,
          :"#{name}=",
          location,
          comments
        )
      end
    end
  end

  super
end
visit_def(node) click to toggle source
Calls superclass method
# File lib/syntax_tree/index.rb, line 584
def visit_def(node)
  name = node.name.value.to_sym
  location =
    Location.new(node.location.start_line, node.location.start_column)

  results << if node.target.nil?
    MethodDefinition.new(
      nesting.dup,
      name,
      location,
      comments_for(node)
    )
  else
    SingletonMethodDefinition.new(
      nesting.dup,
      name,
      location,
      comments_for(node)
    )
  end

  super
end
visit_module(node) click to toggle source
Calls superclass method
# File lib/syntax_tree/index.rb, line 608
def visit_module(node)
  names = node.constant.accept(ConstantNameVisitor.new)
  nesting << names

  location =
    Location.new(node.location.start_line, node.location.start_column)

  results << ModuleDefinition.new(
    nesting.dup,
    names.last,
    location,
    comments_for(node)
  )

  super
  nesting.pop
end
visit_program(node) click to toggle source
Calls superclass method
# File lib/syntax_tree/index.rb, line 626
def visit_program(node)
  super
  results
end
visit_statements(node) click to toggle source
Calls superclass method
# File lib/syntax_tree/index.rb, line 631
def visit_statements(node)
  @statements = node
  super
end