Sha256: e0a2bf716ec0ff4dab155a19a59cdbd87b083ea1b428086252dd50f7e9787d41

Contents?: true

Size: 724 Bytes

Versions: 1

Compression:

Stored size: 724 Bytes

Contents

require_relative 'ast_node_class_map'

module Reek
  module Source
    #
    # Adorns an abstract syntax tree with mix-in modules to make accessing
    # the tree more understandable and less implementation-dependent.
    #
    class TreeDresser
      def initialize(klass_map = ASTNodeClassMap.new)
        @klass_map = klass_map
      end

      def dress(sexp, comment_map)
        return sexp unless sexp.is_a? AST::Node
        type = sexp.type
        children = sexp.children.map { |child| dress(child, comment_map) }
        comments = comment_map[sexp]
        @klass_map.klass_for(type).new(type, children,
                                       location: sexp.loc, comments: comments)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reek-2.1.0 lib/reek/source/tree_dresser.rb