Class: Rsense::Server::Listeners::WhereEventListener

Inherits:
Object
  • Object
show all
Includes:
Java::org.cx4a.rsense::Project::EventListener
Defined in:
lib/rsense/server/listeners/where_event_listener.rb

Constant Summary collapse

EventType =
Rsense::Typing::Graph::EventListener::EventType
SourceLocation =
Rsense::Util::SourceLocation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ WhereEventListener

Returns a new instance of WhereEventListener.



17
18
19
# File 'lib/rsense/server/listeners/where_event_listener.rb', line 17

def initialize(context)
  @context = context
end

Instance Attribute Details

#closestObject

Returns the value of attribute closest.



15
16
17
# File 'lib/rsense/server/listeners/where_event_listener.rb', line 15

def closest
  @closest
end

#contextObject

Returns the value of attribute context.



15
16
17
# File 'lib/rsense/server/listeners/where_event_listener.rb', line 15

def context
  @context
end

#lineObject

Returns the value of attribute line.



15
16
17
# File 'lib/rsense/server/listeners/where_event_listener.rb', line 15

def line
  @line
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/rsense/server/listeners/where_event_listener.rb', line 15

def name
  @name
end

Instance Method Details

#prepare(line) ⇒ Object



21
22
23
# File 'lib/rsense/server/listeners/where_event_listener.rb', line 21

def prepare(line)
  @line = line
end

#update(event) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rsense/server/listeners/where_event_listener.rb', line 25

def update(event)
  eligible = [ EventType::DEFINE, EventType::CLASS, EventType::MODULE ]
  if context.main && eligible.any? {|e| event.type == e}
    if event.name && event.node
      loc = SourceLocation.of(event.node)
      loc_line = loc.getLine()
      if loc && @line >= loc_line && @line - @closest > @line - loc_line
        @closest = loc_line
        @name = event.name
      end
    end
  end
end