Class: Yoda::Parsing::Query::CurrentCommentingNodeQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/parsing/query/current_commenting_node_query.rb

Overview

Provides helper methods to find the node whose comment include the current position (is the current comment).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast, comments, location) ⇒ CurrentCommentingNodeQuery

Returns a new instance of CurrentCommentingNodeQuery.

Parameters:

  • ast (AST::Node)
  • comments (Array<::Parser::Source::Comment>)
  • location (Location)

    represents the current position.



11
12
13
14
15
16
17
18
# File 'lib/yoda/parsing/query/current_commenting_node_query.rb', line 11

def initialize(ast, comments, location)
  fail ArgumentError, ast unless ast.is_a?(AST::Vnode)
  fail ArgumentError, comments unless comments.all? { |comment| comment.is_a?(::Parser::Source::Comment) }
  fail ArgumentError, location unless location.is_a?(Location)
  @ast = ast
  @comments = comments
  @location = location
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



6
7
8
# File 'lib/yoda/parsing/query/current_commenting_node_query.rb', line 6

def ast
  @ast
end

#commentsObject (readonly)

Returns the value of attribute comments.



6
7
8
# File 'lib/yoda/parsing/query/current_commenting_node_query.rb', line 6

def comments
  @comments
end

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/yoda/parsing/query/current_commenting_node_query.rb', line 6

def location
  @location
end

Instance Method Details

#current_commenting_nodeArray<::Parser::Source::Comment>

Returns:

  • (Array<::Parser::Source::Comment>)


21
22
23
# File 'lib/yoda/parsing/query/current_commenting_node_query.rb', line 21

def current_commenting_node
  @current_commenting_node ||= inverse_association[current_comment_query.current_comment_block]
end

#current_method_definitionNodeObjects::MethodDefition?

Returns:

  • (NodeObjects::MethodDefition, nil)


31
32
33
# File 'lib/yoda/parsing/query/current_commenting_node_query.rb', line 31

def current_method_definition
  @current_method_definition ||= namespace.calc_current_location_method(current_commenting_node_location)
end

#current_namespaceNodeObjects::Namespace?

Returns:



26
27
28
# File 'lib/yoda/parsing/query/current_commenting_node_query.rb', line 26

def current_namespace
  @current_namespace ||= namespace.calc_current_location_namespace(current_commenting_node_location)
end