class Yoda::Parsing::Query::CurrentCommentingNodeQuery

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

Attributes

ast[R]
comments[R]
location[R]

Public Class Methods

new(ast, comments, location) click to toggle source

@param ast [::Parser::AST::Node] @param comments [Array<::Parser::Source::Comment>] @param location [Location] represents the current position.

# File lib/yoda/parsing/query/current_commenting_node_query.rb, line 11
def initialize(ast, comments, location)
  fail ArgumentError, ast unless ast.is_a?(::Parser::AST::Node)
  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

Public Instance Methods

current_commenting_node() click to toggle source

@return [Array<::Parser::Source::Comment>]

# 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_definition() click to toggle source

@return [NodeObjects::MethodDefition, nil]

# 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_namespace() click to toggle source

@return [NodeObjects::Namespace, nil]

# 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

Private Instance Methods

association() click to toggle source

@return [{::Parser::AST::Node => Array<::Parser::Source::Comment>}]

# File lib/yoda/parsing/query/current_commenting_node_query.rb, line 47
def association
  @association ||= ::Parser::Source::Comment.associate(ast, comments)
end
current_comment_query() click to toggle source

@return [CurrentCommentQuery]

# File lib/yoda/parsing/query/current_commenting_node_query.rb, line 62
def current_comment_query
  @current_comment_query ||= CurrentCommentQuery.new(comments, location)
end
current_commenting_node_location() click to toggle source
# File lib/yoda/parsing/query/current_commenting_node_query.rb, line 37
def current_commenting_node_location
  @current_commenting_node_location ||= Location.of_ast_location(current_commenting_node.location)
end
inverse_association() click to toggle source

@return [{Array<::Parser::Source::Comment> => ::Parser::AST::Node}]

# File lib/yoda/parsing/query/current_commenting_node_query.rb, line 52
def inverse_association
  @inverse_association ||= association.invert
end
location_association() click to toggle source

@return [{::Parser::Source::Map => Array<::Parser::Source::Comment>]

# File lib/yoda/parsing/query/current_commenting_node_query.rb, line 57
def location_association
  @location_association ||= ::Parser::Source::Comment.associate_with_location(ast, comments)
end
namespace() click to toggle source

@return [Namespace]

# File lib/yoda/parsing/query/current_commenting_node_query.rb, line 42
def namespace
  @namespace ||= NodeObjects::Namespace.new(ast)
end