forked from troessner/reek
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
broke smell repository management responsibility out of sniffer
- Loading branch information
Showing
2 changed files
with
71 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters