    {-# LANGUAGE LambdaCase #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE RecordWildCards #-}

    -- | Rendering of type class declarations.
    module Ormolu.Printer.Meat.Declaration.Class
      ( p_classDecl,
      )
    where

    import Control.Arrow
    import Control.Monad
    import Data.Foldable
    import Data.Function (on)
    import Data.List (sortBy)
    import Data.Maybe
    import GHC.Hs
    import GHC.Types.Fixity
    import GHC.Types.Name.Reader
    import GHC.Types.SrcLoc
    import Ormolu.Config
    import Ormolu.Printer.Combinators
    import Ormolu.Printer.Meat.Common
    import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration
    import Ormolu.Printer.Meat.Type

    p_classDecl ::
      Maybe (LHsContext GhcPs) ->
      LocatedN RdrName ->
      LHsQTyVars GhcPs ->
      LexicalFixity ->
      [LHsFunDep GhcPs] ->
      [LSig GhcPs] ->
      LHsBinds GhcPs ->
      [LFamilyDecl GhcPs] ->
      [LTyFamDefltDecl GhcPs] ->
      [LDocDecl GhcPs] ->
      R ()
    p_classDecl :: Maybe (LHsContext GhcPs)
    -> LocatedN RdrName
    -> LHsQTyVars GhcPs
    -> LexicalFixity
    -> [LHsFunDep GhcPs]
    -> [LSig GhcPs]
    -> LHsBinds GhcPs
    -> [LFamilyDecl GhcPs]
    -> [LTyFamDefltDecl GhcPs]
    -> [LDocDecl GhcPs]
    -> R ()
    p_classDecl Maybe (LHsContext GhcPs)
    ctx LocatedN RdrName
    name HsQTvs {[LHsTyVarBndr (HsBndrVis GhcPs) GhcPs]
    XHsQTvs GhcPs
    hsq_ext :: XHsQTvs GhcPs
    hsq_explicit :: [LHsTyVarBndr (HsBndrVis GhcPs) GhcPs]
    hsq_explicit :: forall pass.
    LHsQTyVars pass -> [LHsTyVarBndr (HsBndrVis pass) pass]
    hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
    ..} LexicalFixity
    fixity [LHsFunDep GhcPs]
    fdeps [LSig GhcPs]
    csigs LHsBinds GhcPs
    cdefs [LFamilyDecl GhcPs]
    cats [LTyFamDefltDecl GhcPs]
    catdefs [LDocDecl GhcPs]
    cdocs = do
      let variableSpans :: [SrcSpan]
    variableSpans = GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
    -> SrcSpan
    forall a e. HasLoc a => GenLocated a e -> SrcSpan
    getLocA (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
     -> SrcSpan)
    -> [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)]
    -> [SrcSpan]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [LHsTyVarBndr (HsBndrVis GhcPs) GhcPs]
    [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)]
    hsq_explicit
          signatureSpans :: [SrcSpan]
    signatureSpans = LocatedN RdrName -> SrcSpan
    forall a e. HasLoc a => GenLocated a e -> SrcSpan
    getLocA LocatedN RdrName
    name SrcSpan -> [SrcSpan] -> [SrcSpan]
    forall a. a -> [a] -> [a]
    : [SrcSpan]
    variableSpans
          dependencySpans :: [SrcSpan]
    dependencySpans = GenLocated SrcSpanAnnA (FunDep GhcPs) -> SrcSpan
    forall a e. HasLoc a => GenLocated a e -> SrcSpan
    getLocA (GenLocated SrcSpanAnnA (FunDep GhcPs) -> SrcSpan)
    -> [GenLocated SrcSpanAnnA (FunDep GhcPs)] -> [SrcSpan]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [LHsFunDep GhcPs]
    [GenLocated SrcSpanAnnA (FunDep GhcPs)]
    fdeps
          combinedSpans :: [SrcSpan]
    combinedSpans = Maybe SrcSpan -> [SrcSpan]
    forall a. Maybe a -> [a]
    maybeToList (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> SrcSpan
    forall a e. HasLoc a => GenLocated a e -> SrcSpan
    getLocA (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
     -> SrcSpan)
    -> Maybe
         (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)])
    -> Maybe SrcSpan
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe (LHsContext GhcPs)
    Maybe
      (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)])
    ctx) [SrcSpan] -> [SrcSpan] -> [SrcSpan]
    forall a. [a] -> [a] -> [a]
    ++ [SrcSpan]
    signatureSpans [SrcSpan] -> [SrcSpan] -> [SrcSpan]
    forall a. [a] -> [a] -> [a]
    ++ [SrcSpan]
    dependencySpans
          -- GHC's AST does not necessarily store each kind of element in source
          -- location order. This happens because different declarations are stored
          -- in different lists. Consequently, to get all the declarations in proper
          -- order, they need to be manually sorted.
          sigs :: [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    sigs = (GenLocated SrcSpanAnnA (Sig GhcPs) -> SrcSpan
    forall a e. HasLoc a => GenLocated a e -> SrcSpan
    getLocA (GenLocated SrcSpanAnnA (Sig GhcPs) -> SrcSpan)
    -> (GenLocated SrcSpanAnnA (Sig GhcPs)
        -> GenLocated SrcSpanAnnA (HsDecl GhcPs))
    -> GenLocated SrcSpanAnnA (Sig GhcPs)
    -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
    forall b c c'. (b -> c) -> (b -> c') -> b -> (c, c')
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&& (Sig GhcPs -> HsDecl GhcPs)
    -> GenLocated SrcSpanAnnA (Sig GhcPs)
    -> GenLocated SrcSpanAnnA (HsDecl GhcPs)
    forall a b.
    (a -> b) -> GenLocated SrcSpanAnnA a -> GenLocated SrcSpanAnnA b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (XSigD GhcPs -> Sig GhcPs -> HsDecl GhcPs
    forall p. XSigD p -> Sig p -> HsDecl p
    SigD XSigD GhcPs
    NoExtField
    NoExtField)) (GenLocated SrcSpanAnnA (Sig GhcPs)
     -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs)))
    -> [GenLocated SrcSpanAnnA (Sig GhcPs)]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [LSig GhcPs]
    [GenLocated SrcSpanAnnA (Sig GhcPs)]
    csigs
          vals :: [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    vals = (GenLocated SrcSpanAnnA (HsBind GhcPs) -> SrcSpan
    forall a e. HasLoc a => GenLocated a e -> SrcSpan
    getLocA (GenLocated SrcSpanAnnA (HsBind GhcPs) -> SrcSpan)
    -> (GenLocated SrcSpanAnnA (HsBind GhcPs)
        -> GenLocated SrcSpanAnnA (HsDecl GhcPs))
    -> GenLocated SrcSpanAnnA (HsBind GhcPs)
    -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
    forall b c c'. (b -> c) -> (b -> c') -> b -> (c, c')
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&& (HsBind GhcPs -> HsDecl GhcPs)
    -> GenLocated SrcSpanAnnA (HsBind GhcPs)
    -> GenLocated SrcSpanAnnA (HsDecl GhcPs)
    forall a b.
    (a -> b) -> GenLocated SrcSpanAnnA a -> GenLocated SrcSpanAnnA b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (XValD GhcPs -> HsBind GhcPs -> HsDecl GhcPs
    forall p. XValD p -> HsBind p -> HsDecl p
    ValD XValD GhcPs
    NoExtField
    NoExtField)) (GenLocated SrcSpanAnnA (HsBind GhcPs)
     -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs)))
    -> [GenLocated SrcSpanAnnA (HsBind GhcPs)]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [GenLocated SrcSpanAnnA (HsBind GhcPs)]
    -> [GenLocated SrcSpanAnnA (HsBind GhcPs)]
    forall a. [a] -> [a]
    forall (t :: * -> *) a. Foldable t => t a -> [a]
    toList LHsBinds GhcPs
    [GenLocated SrcSpanAnnA (HsBind GhcPs)]
    cdefs
          tyFams :: [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    tyFams = (GenLocated SrcSpanAnnA (FamilyDecl GhcPs) -> SrcSpan
    forall a e. HasLoc a => GenLocated a e -> SrcSpan
    getLocA (GenLocated SrcSpanAnnA (FamilyDecl GhcPs) -> SrcSpan)
    -> (GenLocated SrcSpanAnnA (FamilyDecl GhcPs)
        -> GenLocated SrcSpanAnnA (HsDecl GhcPs))
    -> GenLocated SrcSpanAnnA (FamilyDecl GhcPs)
    -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
    forall b c c'. (b -> c) -> (b -> c') -> b -> (c, c')
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&& (FamilyDecl GhcPs -> HsDecl GhcPs)
    -> GenLocated SrcSpanAnnA (FamilyDecl GhcPs)
    -> GenLocated SrcSpanAnnA (HsDecl GhcPs)
    forall a b.
    (a -> b) -> GenLocated SrcSpanAnnA a -> GenLocated SrcSpanAnnA b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (XTyClD GhcPs -> TyClDecl GhcPs -> HsDecl GhcPs
    forall p. XTyClD p -> TyClDecl p -> HsDecl p
    TyClD XTyClD GhcPs
    NoExtField
    NoExtField (TyClDecl GhcPs -> HsDecl GhcPs)
    -> (FamilyDecl GhcPs -> TyClDecl GhcPs)
    -> FamilyDecl GhcPs
    -> HsDecl GhcPs
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XFamDecl GhcPs -> FamilyDecl GhcPs -> TyClDecl GhcPs
    forall pass. XFamDecl pass -> FamilyDecl pass -> TyClDecl pass
    FamDecl XFamDecl GhcPs
    NoExtField
    NoExtField)) (GenLocated SrcSpanAnnA (FamilyDecl GhcPs)
     -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs)))
    -> [GenLocated SrcSpanAnnA (FamilyDecl GhcPs)]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [LFamilyDecl GhcPs]
    [GenLocated SrcSpanAnnA (FamilyDecl GhcPs)]
    cats
          docs :: [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    docs = (GenLocated SrcSpanAnnA (DocDecl GhcPs) -> SrcSpan
    forall a e. HasLoc a => GenLocated a e -> SrcSpan
    getLocA (GenLocated SrcSpanAnnA (DocDecl GhcPs) -> SrcSpan)
    -> (GenLocated SrcSpanAnnA (DocDecl GhcPs)
        -> GenLocated SrcSpanAnnA (HsDecl GhcPs))
    -> GenLocated SrcSpanAnnA (DocDecl GhcPs)
    -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
    forall b c c'. (b -> c) -> (b -> c') -> b -> (c, c')
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&& (DocDecl GhcPs -> HsDecl GhcPs)
    -> GenLocated SrcSpanAnnA (DocDecl GhcPs)
    -> GenLocated SrcSpanAnnA (HsDecl GhcPs)
    forall a b.
    (a -> b) -> GenLocated SrcSpanAnnA a -> GenLocated SrcSpanAnnA b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (XDocD GhcPs -> DocDecl GhcPs -> HsDecl GhcPs
    forall p. XDocD p -> DocDecl p -> HsDecl p
    DocD XDocD GhcPs
    NoExtField
    NoExtField)) (GenLocated SrcSpanAnnA (DocDecl GhcPs)
     -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs)))
    -> [GenLocated SrcSpanAnnA (DocDecl GhcPs)]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [LDocDecl GhcPs]
    [GenLocated SrcSpanAnnA (DocDecl GhcPs)]
    cdocs
          tyFamDefs :: [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    tyFamDefs =
            (GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs) -> SrcSpan
    forall a e. HasLoc a => GenLocated a e -> SrcSpan
    getLocA (GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs) -> SrcSpan)
    -> (GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)
        -> GenLocated SrcSpanAnnA (HsDecl GhcPs))
    -> GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)
    -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
    forall b c c'. (b -> c) -> (b -> c') -> b -> (c, c')
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&& (TyFamInstDecl GhcPs -> HsDecl GhcPs)
    -> GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)
    -> GenLocated SrcSpanAnnA (HsDecl GhcPs)
    forall a b.
    (a -> b) -> GenLocated SrcSpanAnnA a -> GenLocated SrcSpanAnnA b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (XInstD GhcPs -> InstDecl GhcPs -> HsDecl GhcPs
    forall p. XInstD p -> InstDecl p -> HsDecl p
    InstD XInstD GhcPs
    NoExtField
    NoExtField (InstDecl GhcPs -> HsDecl GhcPs)
    -> (TyFamInstDecl GhcPs -> InstDecl GhcPs)
    -> TyFamInstDecl GhcPs
    -> HsDecl GhcPs
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XTyFamInstD GhcPs -> TyFamInstDecl GhcPs -> InstDecl GhcPs
    forall pass.
    XTyFamInstD pass -> TyFamInstDecl pass -> InstDecl pass
    TyFamInstD XTyFamInstD GhcPs
    NoExtField
    NoExtField))
              (GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)
     -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs)))
    -> [GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [LTyFamDefltDecl GhcPs]
    [GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)]
    catdefs
          allDecls :: [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
    allDecls =
            (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
    -> GenLocated SrcSpanAnnA (HsDecl GhcPs)
    forall a b. (a, b) -> b
    snd ((SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
     -> GenLocated SrcSpanAnnA (HsDecl GhcPs))
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ((SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
     -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs)) -> Ordering)
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall a. (a -> a -> Ordering) -> [a] -> [a]
    sortBy (SrcSpan -> SrcSpan -> Ordering
    leftmost_smallest (SrcSpan -> SrcSpan -> Ordering)
    -> ((SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs)) -> SrcSpan)
    -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
    -> (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))
    -> Ordering
    forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
    `on` (SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs)) -> SrcSpan
    forall a b. (a, b) -> a
    fst) ([(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    sigs [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall a. Semigroup a => a -> a -> a
    <> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    vals [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall a. Semigroup a => a -> a -> a
    <> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    tyFams [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall a. Semigroup a => a -> a -> a
    <> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    tyFamDefs [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    -> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    forall a. Semigroup a => a -> a -> a
    <> [(SrcSpan, GenLocated SrcSpanAnnA (HsDecl GhcPs))]
    docs)
      Text -> R ()
    txt Text
    "class"
      [SrcSpan] -> R () -> R ()
    switchLayout [SrcSpan]
    combinedSpans (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
        R ()
    breakpoint
        R () -> R ()
    inci (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
          Maybe
      (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)])
    -> (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
        -> R ())
    -> R ()
    forall (t :: * -> *) (f :: * -> *) a b.
    (Foldable t, Applicative f) =>
    t a -> (a -> f b) -> f ()
    for_ Maybe (LHsContext GhcPs)
    Maybe
      (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)])
    ctx LHsContext GhcPs -> R ()
    GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> R ()
    p_classContext
          [SrcSpan] -> R () -> R ()
    switchLayout [SrcSpan]
    signatureSpans (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $
            Bool -> Bool -> R () -> [R ()] -> R ()
    p_infixDefHelper
              (LexicalFixity -> Bool
    isInfix LexicalFixity
    fixity)
              Bool
    True
              (LocatedN RdrName -> R ()
    p_rdrName LocatedN RdrName
    name)
              ((HsTyVarBndr (HsBndrVis GhcPs) GhcPs -> R ())
    -> GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
    -> R ()
    forall l a. HasLoc l => (a -> R ()) -> GenLocated l a -> R ()
    located' HsTyVarBndr (HsBndrVis GhcPs) GhcPs -> R ()
    forall flag. IsTyVarBndrFlag flag => HsTyVarBndr flag GhcPs -> R ()
    p_hsTyVarBndr (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
     -> R ())
    -> [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)]
    -> [R ()]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [LHsTyVarBndr (HsBndrVis GhcPs) GhcPs]
    [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)]
    hsq_explicit)
          R () -> R ()
    inci ([LHsFunDep GhcPs] -> R ()
    p_classFundeps [LHsFunDep GhcPs]
    fdeps)
          Bool -> R () -> R ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    unless ([GenLocated SrcSpanAnnA (HsDecl GhcPs)] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
    allDecls) (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
            R ()
    breakpoint
            Text -> R ()
    txt Text
    "where"
      Bool -> R () -> R ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    unless ([GenLocated SrcSpanAnnA (HsDecl GhcPs)] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
    allDecls) (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
        R ()
    breakpoint -- Ensure whitespace is added after where clause.
        R () -> R ()
    inci (FamilyStyle -> [LHsDecl GhcPs] -> R ()
    p_hsDeclsRespectGrouping FamilyStyle
    Associated [LHsDecl GhcPs]
    [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
    allDecls)

    p_classContext :: LHsContext GhcPs -> R ()
    p_classContext :: LHsContext GhcPs -> R ()
    p_classContext LHsContext GhcPs
    ctx = Bool -> R () -> R ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    unless ([GenLocated SrcSpanAnnA (HsType GhcPs)] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> [GenLocated SrcSpanAnnA (HsType GhcPs)]
    forall l e. GenLocated l e -> e
    unLoc LHsContext GhcPs
    GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
    ctx)) (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
      GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> ([GenLocated SrcSpanAnnA (HsType GhcPs)] -> R ()) -> R ()
    forall l a. HasLoc l => GenLocated l a -> (a -> R ()) -> R ()
    located LHsContext GhcPs
    GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
    ctx HsContext GhcPs -> R ()
    [GenLocated SrcSpanAnnA (HsType GhcPs)] -> R ()
    p_hsContext
      R ()
    space
      R ()
    token'darrow
      R ()
    breakpoint

    p_classFundeps :: [LHsFunDep GhcPs] -> R ()
    p_classFundeps :: [LHsFunDep GhcPs] -> R ()
    p_classFundeps [LHsFunDep GhcPs]
    fdeps = Bool -> R () -> R ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    unless ([GenLocated SrcSpanAnnA (FunDep GhcPs)] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [LHsFunDep GhcPs]
    [GenLocated SrcSpanAnnA (FunDep GhcPs)]
    fdeps) (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
      R ()
    breakpoint
      Text -> R ()
    txt Text
    "|"
      R ()
    space
      R () -> R ()
    inci' (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ R ()
    -> (GenLocated SrcSpanAnnA (FunDep GhcPs) -> R ())
    -> [GenLocated SrcSpanAnnA (FunDep GhcPs)]
    -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    commaDel (R () -> R ()
    sitcc (R () -> R ())
    -> (GenLocated SrcSpanAnnA (FunDep GhcPs) -> R ())
    -> GenLocated SrcSpanAnnA (FunDep GhcPs)
    -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (FunDep GhcPs -> R ())
    -> GenLocated SrcSpanAnnA (FunDep GhcPs) -> R ()
    forall l a. HasLoc l => (a -> R ()) -> GenLocated l a -> R ()
    located' FunDep GhcPs -> R ()
    p_funDep) [LHsFunDep GhcPs]
    [GenLocated SrcSpanAnnA (FunDep GhcPs)]
    fdeps
      where
        inci' :: R () -> R ()
    inci' R ()
    x =
          (forall (f :: * -> *). PrinterOpts f -> f CommaStyle)
    -> R CommaStyle
    forall a. (forall (f :: * -> *). PrinterOpts f -> f a) -> R a
    getPrinterOpt PrinterOpts f -> f CommaStyle
    forall (f :: * -> *). PrinterOpts f -> f CommaStyle
    poCommaStyle R CommaStyle -> (CommaStyle -> R ()) -> R ()
    forall a b. R a -> (a -> R b) -> R b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \case
            CommaStyle
    Leading -> R () -> R ()
    forall a. a -> a
    id R ()
    x
            CommaStyle
    Trailing -> R () -> R ()
    inci R ()
    x

    p_funDep :: FunDep GhcPs -> R ()
    p_funDep :: FunDep GhcPs -> R ()
    p_funDep (FunDep XCFunDep GhcPs
    _ [LIdP GhcPs]
    before [LIdP GhcPs]
    after) = do
      R () -> (LocatedN RdrName -> R ()) -> [LocatedN RdrName] -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    space LocatedN RdrName -> R ()
    p_rdrName [LIdP GhcPs]
    [LocatedN RdrName]
    before
      R ()
    space
      R ()
    token'rarrow
      R ()
    space
      R () -> (LocatedN RdrName -> R ()) -> [LocatedN RdrName] -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    space LocatedN RdrName -> R ()
    p_rdrName [LIdP GhcPs]
    [LocatedN RdrName]
    after

    ----------------------------------------------------------------------------
    -- Helpers

    isInfix :: LexicalFixity -> Bool
    isInfix :: LexicalFixity -> Bool
    isInfix = \case
      LexicalFixity
    Infix -> Bool
    True
      LexicalFixity
    Prefix -> Bool
    False