HaRe-0.6: refactorer/RefacCase.hs
module RefacCase(ifToCase) where
import RefacUtils
ifToCase args
= do let fileName = args!!0
beginPos = (read (args!!1), read (args!!2))::(Int,Int)
endPos = (read (args!!3), read (args!!4))::(Int,Int)
modInfo@(_, _, mod, toks) <- parseSourceFile fileName
let exp = locToExp beginPos endPos toks mod
case exp of
(Exp (HsIf _ _ _))
-> do refactoredMod <- applyRefac (ifToCase exp) (Just modInfo) fileName
writeRefactoredFiles False [refactoredMod]
_ -> error "You haven't selected an if-then-else expression!"
where
ifToCase exp (_, _, mod)= applyTP (once_buTP (failTP `adhocTP` inExp)) mod
where
inExp exp1@((Exp (HsIf e e1 e2))::HsExpP)
| sameOccurrence exp exp1
= let newExp =Exp (HsCase e [HsAlt loc0 (nameToPat "True") (HsBody e1) [],
HsAlt loc0 (nameToPat "False")(HsBody e2) []])
in update exp1 newExp exp1
inExp _ = mzero