-- * Combined Node Queries

-- | Search for the given name in an actual parameter link
getActualParameterSpec :: DevGraphNavigator a => String -> a
                       -> Maybe (a, LNode DGNodeLab)
getActualParameterSpec n dgnav =
    -- search first actual param
    case searchLink (isJust . dglPredActualParam n) dgnav of
      Nothing -> Nothing
      Just (dgn', (sn, _, _)) ->
          -- get the spec for the param
          fmap f $ firstMaybe dglPredInstance $ incoming dgnav sn
              where f edg = let sn' = linkSource edg
                            in (dgn', (sn', getLabel dgnav sn'))


-- | Search for the given name in an instantiation node
getActualParameterSpec :: DevGraphNavigator a => String -> a
                       -> Maybe (a, LNode DGNodeLab)
getActualParameterSpec n dgnav =
    -- search first actual param
    case searchLink (isJust . dglPredActualParam n) dgnav of
      Nothing -> Nothing
      Just (dgn', (sn, _, _)) ->
          -- get the spec for the param
          fmap f $ firstMaybe dglPredInstance $ incoming dgnav sn
              where f edg = let sn' = linkSource edg
                            in (dgn', (sn', getLabel dgnav sn'))


-- | Search for the given name in an instantiation node
getActualParameterSpec n dgnav =
    -- search first actual param
    case searchLink (isJust . dglPredActualParam n) dgnav of
      Nothing -> Nothing
      Just (dgn', (sn, _, _)) ->
          -- get the spec for the param
          fmap f $ firstMaybe dglPredInstance $ incoming dgnav sn
              where f edg = let sn' = linkSource edg
                            in (dgn', (sn', getLabel dgnav sn'))


-- | Search for the given name in an instantiation node