Skip to content

Commit

Permalink
broke smell repository management responsibility out of sniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
arwagner committed Feb 26, 2012
1 parent 5e914a4 commit 09506bc
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 47 deletions.
65 changes: 65 additions & 0 deletions lib/reek/core/smell_repository.rb
@@ -0,0 +1,65 @@
require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smells')

module Reek
module Core
class SmellRepository

def self.smell_classes
# SMELL: Duplication -- these should be loaded by listing the files
[
Smells::Attribute,
Smells::BooleanParameter,
Smells::ClassVariable,
Smells::ControlCouple,
Smells::DataClump,
Smells::Duplication,
Smells::FeatureEnvy,
Smells::IrresponsibleModule,
Smells::LargeClass,
Smells::LongMethod,
Smells::LongParameterList,
Smells::LongYieldList,
Smells::NestedIterators,
Smells::SimulatedPolymorphism,
Smells::UncommunicativeMethodName,
Smells::UncommunicativeModuleName,
Smells::UncommunicativeParameterName,
Smells::UncommunicativeVariableName,
Smells::UtilityFunction,
]
end

def initialize source_description
@typed_detectors = nil
@detectors = Hash.new
SmellRepository.smell_classes.each do |klass|
@detectors[klass] = klass.new(source_description)
end
end

def configure(klass, config)
@detectors[klass].configure_with(config)
end

def report_on listener
@detectors.each_value { |detector| detector.report_on(listener) }
end

def examine(scope, node_type)
smell_listeners[node_type].each do |detector|
detector.examine(scope)
end
end

private

def smell_listeners()
unless @typed_detectors
@typed_detectors = Hash.new {|hash,key| hash[key] = [] }
@detectors.each_value { |detector| detector.register(@typed_detectors) }
end
@typed_detectors
end
end
end
end
53 changes: 6 additions & 47 deletions lib/reek/core/sniffer.rb
@@ -1,5 +1,5 @@
require File.join(File.dirname(File.expand_path(__FILE__)), 'code_parser')
require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smells')
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_repository')
require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'source', 'config_file')
require 'yaml'
require File.join(File.dirname(File.expand_path(__FILE__)), 'hash_extensions')
Expand All @@ -12,65 +12,24 @@ module Core
#
class Sniffer

def self.smell_classes
# SMELL: Duplication -- these should be loaded by listing the files
[
Smells::Attribute,
Smells::BooleanParameter,
Smells::ClassVariable,
Smells::ControlCouple,
Smells::DataClump,
Smells::Duplication,
Smells::FeatureEnvy,
Smells::IrresponsibleModule,
Smells::LargeClass,
Smells::LongMethod,
Smells::LongParameterList,
Smells::LongYieldList,
Smells::NestedIterators,
Smells::SimulatedPolymorphism,
Smells::UncommunicativeMethodName,
Smells::UncommunicativeModuleName,
Smells::UncommunicativeParameterName,
Smells::UncommunicativeVariableName,
Smells::UtilityFunction,
]
end

def initialize(src, config_files = [])
@typed_detectors = nil
@detectors = Hash.new
Sniffer.smell_classes.each do |klass|
@detectors[klass] = klass.new(src.desc)
end
def initialize(src, config_files = [], smell_repository=Core::SmellRepository.new(src.desc))
@smell_repository = smell_repository
config_files.each{ |cf| Reek::Source::ConfigFile.new(cf).configure(self) }
@source = src
src.configure(self)
end

def configure(klass, config)
@detectors[klass].configure_with(config)
@smell_repository.configure klass, config
end

def report_on(listener)
CodeParser.new(self).process(@source.syntax_tree)
@detectors.each_value { |detector| detector.report_on(listener) }
@smell_repository.report_on(listener)
end

def examine(scope, node_type)
smell_listeners[node_type].each do |detector|
detector.examine(scope)
end
end

private

def smell_listeners()
unless @typed_detectors
@typed_detectors = Hash.new {|hash,key| hash[key] = [] }
@detectors.each_value { |detector| detector.register(@typed_detectors) }
end
@typed_detectors
@smell_repository.examine scope, node_type
end
end
end
Expand Down

0 comments on commit 09506bc

Please sign in to comment.