Class: Orbacle::FindDefinitionUnderPosition
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- Orbacle::FindDefinitionUnderPosition
show all
- Includes:
- AstUtils
- Defined in:
- lib/orbacle/find_definition_under_position.rb
Defined Under Namespace
Classes: ConstantResult, MessageResult, SuperResult
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from AstUtils
#build_position_range_from_ast, #build_position_range_from_parser_range, const_prename_and_name_to_string, const_to_string, get_nesting, prename
Constructor Details
Returns a new instance of FindDefinitionUnderPosition.
13
14
15
|
# File 'lib/orbacle/find_definition_under_position.rb', line 13
def initialize(parser)
@parser = parser
end
|
Instance Attribute Details
#parser ⇒ Object
Returns the value of attribute parser.
28
29
30
|
# File 'lib/orbacle/find_definition_under_position.rb', line 28
def parser
@parser
end
|
Instance Method Details
#on_class(ast) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/orbacle/find_definition_under_position.rb', line 43
def on_class(ast)
klass_name_ast, _ = ast.children
klass_name_ref = ConstRef.from_ast(klass_name_ast, @current_nesting)
with_new_nesting(@current_nesting.increase_nesting_const(klass_name_ref)) do
super
end
nil
end
|
#on_const(ast) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/orbacle/find_definition_under_position.rb', line 36
def on_const(ast)
if build_position_range_from_ast(ast).include_position?(@searched_position)
@result = ConstantResult.new(ConstRef.from_ast(ast, @current_nesting))
end
nil
end
|
#on_module(ast) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/orbacle/find_definition_under_position.rb', line 52
def on_module(ast)
module_name_ast, _ = ast.children
module_name_ref = ConstRef.from_ast(module_name_ast, @current_nesting)
with_new_nesting(@current_nesting.increase_nesting_const(module_name_ref)) do
super
end
nil
end
|
#on_send(ast) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/orbacle/find_definition_under_position.rb', line 61
def on_send(ast)
if ast.loc.selector && build_position_range_from_parser_range(ast.loc.selector).include_position?(@searched_position)
message_name = ast.children.fetch(1)
if message_name.equal?(:[])
selector_position_range = build_position_range_from_parser_range(ast.loc.selector)
if selector_position_range.on_edges?(@searched_position)
@result = MessageResult.new(message_name, selector_position_range)
else
super
end
else
selector_position_range = build_position_range_from_parser_range(ast.loc.selector)
@result = MessageResult.new(message_name, selector_position_range)
end
elsif ast.loc.dot && build_position_range_from_parser_range(ast.loc.dot).include_position?(@searched_position)
message_name = ast.children.fetch(1)
dot_position_range = build_position_range_from_parser_range(ast.loc.dot)
@result = MessageResult.new(message_name, dot_position_range)
else
super
end
nil
end
|
#on_super(ast) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/orbacle/find_definition_under_position.rb', line 85
def on_super(ast)
keyword_position_range = build_position_range_from_parser_range(ast.loc.keyword)
if keyword_position_range.include_position?(@searched_position)
@result = SuperResult.new(keyword_position_range)
else
super
end
nil
end
|
#on_zsuper(ast) ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/orbacle/find_definition_under_position.rb', line 95
def on_zsuper(ast)
keyword_position_range = build_position_range_from_parser_range(ast.loc.keyword)
if keyword_position_range.include_position?(@searched_position)
@result = SuperResult.new(keyword_position_range)
end
nil
end
|
#process(ast) ⇒ Object
30
31
32
33
34
|
# File 'lib/orbacle/find_definition_under_position.rb', line 30
def process(ast)
new_ast = super
raise unless ast.equal?(new_ast)
new_ast
end
|
#process_file(file_content, searched_position) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/orbacle/find_definition_under_position.rb', line 17
def process_file(file_content, searched_position)
ast = parser.parse(file_content)
@current_nesting = Nesting.empty
@searched_position = searched_position
process(ast)
@result
end
|
#with_new_nesting(new_nesting) ⇒ Object
103
104
105
106
107
108
|
# File 'lib/orbacle/find_definition_under_position.rb', line 103
def with_new_nesting(new_nesting)
previous_nesting = @current_nesting
@current_nesting = new_nesting
yield
@current_nesting = previous_nesting
end
|