module Data.GI.GIR.Deprecation
( DeprecationInfo(..)
, queryDeprecated
) where
import qualified Data.Map as M
import Data.Text (Text)
import Text.XML (Element(elementAttributes))
import Data.GI.GIR.XMLUtils (firstChildWithLocalName, getElementContent)
data DeprecationInfo = DeprecationInfo {
DeprecationInfo -> Maybe Text
deprecatedSinceVersion :: Maybe Text,
DeprecationInfo -> Maybe Text
deprecationMessage :: Maybe Text
} deriving (Int -> DeprecationInfo -> ShowS
[DeprecationInfo] -> ShowS
DeprecationInfo -> String
(Int -> DeprecationInfo -> ShowS)
-> (DeprecationInfo -> String)
-> ([DeprecationInfo] -> ShowS)
-> Show DeprecationInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeprecationInfo] -> ShowS
$cshowList :: [DeprecationInfo] -> ShowS
show :: DeprecationInfo -> String
$cshow :: DeprecationInfo -> String
showsPrec :: Int -> DeprecationInfo -> ShowS
$cshowsPrec :: Int -> DeprecationInfo -> ShowS
Show, DeprecationInfo -> DeprecationInfo -> Bool
(DeprecationInfo -> DeprecationInfo -> Bool)
-> (DeprecationInfo -> DeprecationInfo -> Bool)
-> Eq DeprecationInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeprecationInfo -> DeprecationInfo -> Bool
$c/= :: DeprecationInfo -> DeprecationInfo -> Bool
== :: DeprecationInfo -> DeprecationInfo -> Bool
$c== :: DeprecationInfo -> DeprecationInfo -> Bool
Eq)
queryDeprecated :: Element -> Maybe DeprecationInfo
queryDeprecated :: Element -> Maybe DeprecationInfo
queryDeprecated Element
element =
case Name -> Map Name Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Name
"deprecated" Map Name Text
attrs of
Just Text
_ -> let version :: Maybe Text
version = Name -> Map Name Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Name
"deprecated-version" Map Name Text
attrs
msg :: Maybe Text
msg = Text -> Element -> Maybe Element
firstChildWithLocalName Text
"doc-deprecated" Element
element Maybe Element -> (Element -> Maybe Text) -> Maybe Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Text
getElementContent
in DeprecationInfo -> Maybe DeprecationInfo
forall a. a -> Maybe a
Just (Maybe Text -> Maybe Text -> DeprecationInfo
DeprecationInfo Maybe Text
version Maybe Text
msg)
Maybe Text
Nothing -> Maybe DeprecationInfo
forall a. Maybe a
Nothing
where attrs :: Map Name Text
attrs = Element -> Map Name Text
elementAttributes Element
element