-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Refactoring Tool for Haskell -- -- Contains a set of refactorings based on the Haskell-Tools framework to -- easily transform a Haskell program. For the descriptions of the -- implemented refactorings, see the homepage. @package haskell-tools-refactor @version 0.1.3.0 module Language.Haskell.Tools.Refactor.RefactorBase -- | The information a refactoring can use data RefactorCtx dom RefactorCtx :: Module -> [Ann ImportDecl dom SrcTemplateStage] -> RefactorCtx dom [refModuleName] :: RefactorCtx dom -> Module [refCtxImports] :: RefactorCtx dom -> [Ann ImportDecl dom SrcTemplateStage] -- | Performs the given refactoring, transforming it into a Ghc action runRefactor :: (SemanticInfo' dom SameInfoModuleCls ~ ModuleInfo n) => Ann Module dom SrcTemplateStage -> (Ann Module dom SrcTemplateStage -> RefactoredModule dom) -> Ghc (Either String (Ann Module dom SrcTemplateStage)) -- | Adds the imports that bring names into scope that are needed by the -- refactoring addGeneratedImports :: (Monad m) => ReaderT (RefactorCtx dom) m (Ann Module dom SrcTemplateStage, [Name]) -> ReaderT (RefactorCtx dom) m (Ann Module dom SrcTemplateStage) -- | Input and output information for the refactoring newtype RefactorT dom m a RefactorT :: WriterT [Name] (ReaderT (RefactorCtx dom) m) a -> RefactorT dom m a [fromRefactorT] :: RefactorT dom m a -> WriterT [Name] (ReaderT (RefactorCtx dom) m) a refactError :: String -> Refactor n a -- | The refactoring monad type Refactor dom = RefactorT dom (ExceptT String Ghc) type RefactoredModule dom = Refactor dom (Ann Module dom SrcTemplateStage) registeredNamesFromPrelude :: [Name] otherNamesFromPrelude :: [String] qualifiedName :: Name -> String referenceName :: (SemanticInfo' dom SameInfoImportCls ~ ImportInfo n, Eq n, NamedThing n) => n -> Refactor dom (Ann Name dom SrcTemplateStage) referenceOperator :: (SemanticInfo' dom SameInfoImportCls ~ ImportInfo n, Eq n, NamedThing n) => n -> Refactor dom (Ann Operator dom SrcTemplateStage) -- | Create a name that references the definition. Generates an import if -- the definition is not yet imported. referenceName' :: (SemanticInfo' dom SameInfoImportCls ~ ImportInfo n, Eq n, NamedThing n) => ([String] -> Name -> Ann nt dom SrcTemplateStage) -> n -> Refactor dom (Ann nt dom SrcTemplateStage) -- | Reference the name by the shortest suitable import referenceBy :: ([String] -> Name -> Ann nt dom SrcTemplateStage) -> Name -> [Ann ImportDecl dom SrcTemplateStage] -> Ann nt dom SrcTemplateStage -- | Different classes of definitions that have different kind of names. data NameClass -- | Normal value definitions: functions, variables Variable :: NameClass -- | Data constructors Ctor :: NameClass -- | Functions with operator-like names ValueOperator :: NameClass -- | Constructors with operator-like names DataCtorOperator :: NameClass -- | Type definitions with operator-like names SynonymOperator :: NameClass -- | Get which category does a given name belong to classifyName :: Name -> Refactor dom NameClass -- | Check if a given name is valid for a given kind of definition nameValid :: NameClass -> String -> Bool isIdStartChar :: Char -> Bool isOperatorChar :: Char -> Bool instance GhcMonad.GhcMonad m => GhcMonad.GhcMonad (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom m) instance Exception.ExceptionMonad m => Exception.ExceptionMonad (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom m) instance (GHC.Base.Monad m, DynFlags.HasDynFlags m) => DynFlags.HasDynFlags (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom m) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom m) instance GHC.Base.Monad m => Control.Monad.Writer.Class.MonadWriter [Name.Name] (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom m) instance GHC.Base.Monad m => Control.Monad.Reader.Class.MonadReader (Language.Haskell.Tools.Refactor.RefactorBase.RefactorCtx dom) (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom m) instance GHC.Base.Monad m => GHC.Base.Monad (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom m) instance GHC.Base.Applicative m => GHC.Base.Applicative (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom m) instance GHC.Base.Functor m => GHC.Base.Functor (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom m) instance (GhcMonad.GhcMonad m, GHC.Base.Monoid s) => GhcMonad.GhcMonad (Control.Monad.Trans.Writer.Lazy.WriterT s m) instance (Exception.ExceptionMonad m, GHC.Base.Monoid s) => Exception.ExceptionMonad (Control.Monad.Trans.Writer.Lazy.WriterT s m) instance GhcMonad.GhcMonad m => GhcMonad.GhcMonad (Control.Monad.Trans.Reader.ReaderT s m) instance Exception.ExceptionMonad m => Exception.ExceptionMonad (Control.Monad.Trans.Reader.ReaderT s m) instance GhcMonad.GhcMonad m => GhcMonad.GhcMonad (Control.Monad.Trans.Except.ExceptT s m) instance Exception.ExceptionMonad m => Exception.ExceptionMonad (Control.Monad.Trans.Except.ExceptT s m) instance Control.Monad.Trans.Class.MonadTrans (Language.Haskell.Tools.Refactor.RefactorBase.RefactorT dom) module Language.Haskell.Tools.Refactor.ExtractBinding type Ann' e dom = Ann e dom SrcTemplateStage type AnnMaybe' e dom = AnnMaybe e dom SrcTemplateStage type ExtractBindingDomain dom = (Domain dom, HasNameInfo (SemanticInfo' dom SameInfoNameCls), HasDefiningInfo (SemanticInfo' dom SameInfoNameCls), HasScopeInfo (SemanticInfo' dom SameInfoExprCls)) extractBinding' :: ExtractBindingDomain dom => RealSrcSpan -> String -> Ann' Module dom -> RefactoredModule dom extractBinding :: forall dom. ExtractBindingDomain dom => Simple Traversal (Ann' Module dom) (Ann' ValueBind dom) -> Simple Traversal (Ann' ValueBind dom) (Ann' Expr dom) -> String -> Ann' Module dom -> RefactoredModule dom isConflicting :: ExtractBindingDomain dom => String -> Ann' SimpleName dom -> Bool extractThatBind :: ExtractBindingDomain dom => String -> Ann' Expr dom -> Ann' Expr dom -> StateT (Maybe (Ann' ValueBind dom)) (Refactor dom) (Ann' Expr dom) addLocalBinding :: SrcSpan -> SrcSpan -> Ann' ValueBind dom -> ValueBind dom SrcTemplateStage -> State Bool (ValueBind dom SrcTemplateStage) insertLocalBind :: SrcSpan -> Ann' ValueBind dom -> AnnMaybe' LocalBinds dom -> AnnMaybe' LocalBinds dom -- | All expressions that are bound stronger than function application. isParenLikeExpr :: Expr dom st -> Bool doExtract :: ExtractBindingDomain dom => String -> Ann' Expr dom -> Ann' Expr dom -> StateT (Maybe (Ann' ValueBind dom)) (Refactor dom) (Ann' Expr dom) -- | Gets the values that have to be passed to the extracted definition getExternalBinds :: ExtractBindingDomain dom => Ann' Expr dom -> Ann' Expr dom -> [Ann' Name dom] actualContainingExpr :: SourceInfo st => SrcSpan -> Simple Traversal (Ann ValueBind dom st) (Ann Expr dom st) -- | Generates the expression that calls the local binding generateCall :: String -> [Ann' Name dom] -> Ann' Expr dom -- | Generates the local binding for the selected expression generateBind :: String -> [Ann' Pattern dom] -> Ann' Expr dom -> Ann' ValueBind dom isValidBindingName :: String -> Bool module Language.Haskell.Tools.Refactor.RenameDefinition renameDefinition :: DomainRenameDefinition dom => Name -> String -> Ann Module dom SrcTemplateStage -> RefactoredModule dom renameDefinition' :: forall dom. DomainRenameDefinition dom => RealSrcSpan -> String -> Ann Module dom SrcTemplateStage -> RefactoredModule dom type DomainRenameDefinition dom = (Domain dom, HasNameInfo (SemanticInfo' dom SameInfoNameCls), Data (SemanticInfo' dom SameInfoNameCls), HasScopeInfo (SemanticInfo' dom SameInfoNameCls), HasDefiningInfo (SemanticInfo' dom SameInfoNameCls)) module Language.Haskell.Tools.Refactor.GenerateExports type DomGenerateExports dom = (Domain dom, HasNameInfo (SemanticInfo' dom SameInfoNameCls)) -- | Creates an export list that imports standalone top-level definitions -- with all of their contained definitions generateExports :: DomGenerateExports dom => Ann Module dom SrcTemplateStage -> RefactoredModule dom -- | Get all the top-level definitions with flags that mark if they can -- contain other top-level definitions (classes and data declarations). getTopLevels :: DomGenerateExports dom => Ann Module dom SrcTemplateStage -> [(Name, Bool)] -- | Get all the standalone top level definitions (their GHC unique names) -- in a module. You could also do getting all the names with a biplate -- reference and select the top-level ones, but this is more efficient. getTopLevelDeclName :: DomGenerateExports dom => Decl dom SrcTemplateStage -> Maybe Name -- | Create the export for a give name. createExports :: DomGenerateExports dom => [(Name, Bool)] -> Ann ExportSpecList dom SrcTemplateStage module Language.Haskell.Tools.Refactor.GenerateTypeSignature -- | Perform the refactoring on either local or top-level definition generateTypeSignature :: GenerateSignatureDomain dom => Simple Traversal (Ann' Module dom) (AnnList' Decl dom) -> Simple Traversal (Ann' Module dom) (AnnList' LocalBind dom) -> (forall d. (Show (d dom SrcTemplateStage), Data (d dom SrcTemplateStage), Typeable d, BindingElem d) => AnnList' d dom -> Maybe (Ann' ValueBind dom)) -> Ann' Module dom -> RefactoredModule dom generateTypeSignature' :: GenerateSignatureDomain dom => RealSrcSpan -> Ann' Module dom -> RefactoredModule dom type GenerateSignatureDomain dom = (Domain dom, HasIdInfo (SemanticInfo' dom SameInfoNameCls), Eq (SemanticInfo' dom SameInfoNameCls), SemanticInfo' dom SameInfoImportCls ~ ImportInfo Id) module Language.Haskell.Tools.Refactor.OrganizeImports organizeImports :: forall n dom. OrganizeImportsDomain dom n => Ann Module dom SrcTemplateStage -> RefactoredModule dom type OrganizeImportsDomain dom n = (Domain dom, HasNameInfo (SemanticInfo' dom SameInfoNameCls), SemanticInfo' dom SameInfoImportCls ~ ImportInfo n, NamedThing n) module Language.Haskell.Tools.Refactor data RefactorCommand NoRefactor :: RefactorCommand OrganizeImports :: RefactorCommand GenerateExports :: RefactorCommand GenerateSignature :: RealSrcSpan -> RefactorCommand RenameDefinition :: RealSrcSpan -> String -> RefactorCommand ExtractBinding :: RealSrcSpan -> String -> RefactorCommand performCommand :: (SemanticInfo' dom SameInfoModuleCls ~ ModuleInfo n, DomGenerateExports dom, OrganizeImportsDomain dom n, DomainRenameDefinition dom, ExtractBindingDomain dom, GenerateSignatureDomain dom) => RefactorCommand -> Ann Module dom SrcTemplateStage -> Ghc (Either String (Ann Module dom SrcTemplateStage)) readCommand :: String -> String -> RefactorCommand readSrcSpan :: String -> String -> RealSrcSpan readSrcLoc :: String -> String -> RealSrcLoc onlineRefactor :: String -> FilePath -> String -> IO (Either String String) onlineASTView :: FilePath -> String -> IO (Either String String) performRefactor :: String -> String -> String -> IO (Either String String) astView :: String -> String -> IO String loadModule :: String -> String -> Ghc ModSummary parseTyped :: ModSummary -> Ghc (Ann Module IdDom SrcTemplateStage) parseRenamed :: ModSummary -> Ghc (Ann Module (Dom Name) SrcTemplateStage) -- | Should be only used for testing demoRefactor :: String -> String -> String -> IO () instance GHC.Show.Show Language.Haskell.Tools.Refactor.RefactorCommand instance GHC.Generics.Generic SrcLoc.SrcSpan instance (GHC.Generics.Generic sema, GHC.Generics.Generic src) => GHC.Generics.Generic (Language.Haskell.Tools.AST.SemaInfoTypes.NodeInfo sema src)