Skip to content

Commit

Permalink
Merge pull request #289 from mumuki/fix-dont-duplicate-smells-results
Browse files Browse the repository at this point in the history
Removing duplicates in smells
  • Loading branch information
flbulgarelli authored Apr 25, 2020
2 parents 3cd7587 + c8171ed commit a1a8e93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions spec/SmellsAnalyzerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ spec = describe "SmellsAnalyzer" $ do
runWithTypos JavaScript "function baz() {}" [Expectation "*" "Delegates:bar"] `shouldReturn` [Expectation "baz" "HasDeclarationTypos:bar"]
runWithTypos JavaScript "function baz() {}" [Expectation "*" "SubordinatesDeclarationsTo:bar"] `shouldReturn` [Expectation "baz" "HasDeclarationTypos:bar"]

it "works when there are duplicated expectations" $ do
runWithTypos JavaScript "function baz() {}" [Expectation "*" "Declares:bar", Expectation "*" "Declares:bar"] `shouldReturn` [Expectation "baz" "HasDeclarationTypos:bar"]

it "works when there are duplicated expectation results" $ do
runWithTypos Java "class Foo { void baz() {} }" [Expectation "*" "Declares:bar"] `shouldReturn` [Expectation "baz" "HasDeclarationTypos:bar"]

it "works when there are similar declares expectations results" $ do
runWithTypos Java "class Foo { void baz() {} }" [Expectation "*" "Declares:bar", Expectation "*" "DeclaresComputationWithArity0:bar"] `shouldReturn` [Expectation "baz" "HasDeclarationTypos:bar"]

it "works when there are missing declarations and multiple potential typos" $ do
let typos = [ Expectation "Bar" "HasDeclarationTypos:bar", Expectation "baz" "HasDeclarationTypos:bar" ]

Expand Down
8 changes: 5 additions & 3 deletions src/Language/Mulang/Analyzer/SmellsAnalyzer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Language.Mulang.Edl.Expectation (cQuery, Query(..), CQuery (..), Matcher(

import Language.Mulang.Analyzer.Analysis hiding (DomainLanguage, Inspection, allSmells)

import Data.List ((\\), intersect, isPrefixOf)
import Data.List ((\\), intersect, isPrefixOf, nub)
import Data.Maybe (fromMaybe, mapMaybe)

-- the runtime context of a smell analysis,
Expand All @@ -30,13 +30,15 @@ type SmellInstance = (Smell, Maybe Identifier)
-- A Detection is an executable representation of an SmellInstance
type Detection = SmellsContext -> Expression -> [Identifier]

-- Smell detection has three phases:
-- Smell detection has four phases:
--
-- 1. Smells selection: dependening on the given SmellSet, differents lists of smells may be generated
-- 2. Smells instantiation: for each selected smell, one ore more concrete smells will be instantiated
-- 3. Smells evaluation: for each smell instance, it will be evaluated and zero or more Expectations will be synthesized
-- 4. Duplicates removal: context-sensitive smells may be activated more than once, thus nubbing is required.
-- The same applies to smells that apply to both declarations and type signatures
analyseSmells :: Expression -> SmellsContext -> Maybe SmellsSet -> [Expectation]
analyseSmells ast context = concatMap (evalSmellInstance context ast) . concatMap (instantiateSmell context) . smellsFor
analyseSmells ast context = nub . concatMap (evalSmellInstance context ast) . concatMap (instantiateSmell context) . smellsFor

---
--- Selection
Expand Down

0 comments on commit a1a8e93

Please sign in to comment.