Class: JRuby::Lint::Collector::CheckersVisitor

Inherits:
AST::Visitor
  • Object
show all
Defined in:
lib/jruby/lint/collectors.rb

Instance Attribute Summary collapse

Attributes inherited from AST::Visitor

#ast

Instance Method Summary collapse

Methods inherited from AST::Visitor

#each, #method_missing

Constructor Details

#initialize(ast, collector, checkers) ⇒ CheckersVisitor

Returns a new instance of CheckersVisitor.



15
16
17
18
# File 'lib/jruby/lint/collectors.rb', line 15

def initialize(ast, collector, checkers)
  super(ast)
  @collector, @checkers = collector, checkers
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JRuby::Lint::AST::Visitor

Instance Attribute Details

#checkersObject (readonly)

Returns the value of attribute checkers.



13
14
15
# File 'lib/jruby/lint/collectors.rb', line 13

def checkers
  @checkers
end

#collectorObject (readonly)

Returns the value of attribute collector.



13
14
15
# File 'lib/jruby/lint/collectors.rb', line 13

def collector
  @collector
end

Instance Method Details

#visit(method, node) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jruby/lint/collectors.rb', line 20

def visit(method, node)
  after_hooks = []
  checkers.each do |ch|
    begin
      if ch.respond_to?(method)
        res = ch.send(method, node)
        after_hooks << res if res.respond_to?(:call)
      end
    rescue Exception => e
      collector.findings << Finding.new("Exception while traversing: #{e.message}\n  at #{e.backtrace.first}",
                                        [:internal, :debug], node.position)
    end
  end
  super
rescue Exception => e
  collector.findings << Finding.new("Exception while traversing: #{e.message}\n  at #{e.backtrace.first}",
                                    [:internal, :debug], node.position)
ensure
  begin
    after_hooks.each {|h| h.call }
  rescue
  end
end