sw: convert SwTextAnnotationField OSL_ENSUREs to assert() and simplify

Change-Id: Ica69cd4527f36edd7480d897a28ff814ecbe97a9
diff --git a/sw/source/core/crsr/annotationmark.cxx b/sw/source/core/crsr/annotationmark.cxx
index bca5e90..a73c171 100644
--- a/sw/source/core/crsr/annotationmark.cxx
+++ b/sw/source/core/crsr/annotationmark.cxx
@@ -52,26 +52,19 @@ namespace sw { namespace mark
    void AnnotationMark::InitDoc(SwDoc* const io_pDoc)
    {
        SwTextNode *pTextNode = GetMarkEnd().nNode.GetNode().GetTextNode();

        SwTextField* pTextField = pTextNode ?
            pTextNode->GetFieldTextAttrAt(
            GetMarkEnd().nContent.GetIndex()-1, true ) : nullptr;
        OSL_ENSURE( pTextField != nullptr, "<AnnotationMark::InitDoc(..)> - missing text attribute for annotation field!" );
        if ( pTextField != nullptr )
        assert(pTextNode);
        SwTextField *const pTextField = pTextNode->GetFieldTextAttrAt(
            GetMarkEnd().nContent.GetIndex()-1, true);
        assert(pTextField != nullptr);
        const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTextField->GetFormatField().GetField());
        assert(pPostItField != nullptr);
        // use the annotation mark's name as the annotation name, if
        // - the annotation field has an empty annotation name or
        // - the annotation mark's name differs (on mark creation a name clash had been detected)
        if ( pPostItField->GetName().isEmpty()
            || pPostItField->GetName() != GetName() )
        {
            const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTextField->GetFormatField().GetField());
            OSL_ENSURE( pPostItField != nullptr, "<AnnotationMark::InitDoc(..)> - annotation field missing!" );
            if ( pPostItField != nullptr )
            {
                // use the annotation mark's name as the annotation name, if
                // - the annotation field has an empty annotation name or
                // - the annotation mark's name differs (on mark creation a name clash had been detected)
                if ( pPostItField->GetName().isEmpty()
                    || pPostItField->GetName() != GetName() )
                {
                    const_cast<SwPostItField*>(pPostItField)->SetName( GetName() );
                }
            }
            const_cast<SwPostItField*>(pPostItField)->SetName( GetName() );
        }

        if (io_pDoc->GetIDocumentUndoRedo().DoesUndo())
@@ -84,11 +77,7 @@ namespace sw { namespace mark
    const SwFormatField* AnnotationMark::GetAnnotationFormatField() const
    {
        SwDoc* pDoc = GetMarkPos().GetDoc();
        if ( pDoc == nullptr )
        {
            OSL_ENSURE( false, "<AnnotationMark::GetAnnotationFormatField()> - missing document at annotation mark" );
            return nullptr;
        }
        assert(pDoc != nullptr);

        SwFormatField* pAnnotationFormatField = nullptr;

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 7ea1692..68030bb 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -918,15 +918,9 @@ namespace sw { namespace mark
            case IDocumentMarkAccess::MarkType::ANNOTATIONMARK:
                {
                    IDocumentMarkAccess::iterator_t ppAnnotationMark = lcl_FindMark(m_vAnnotationMarks, *ppMark);
                    if ( ppAnnotationMark != m_vAnnotationMarks.end() )
                    {
                        m_vAnnotationMarks.erase(ppAnnotationMark);
                    }
                    else
                    {
                        assert(false &&
                            "<MarkManager::deleteMark(..)> - Annotation Mark not found in Annotation Mark container.");
                    }
                    assert(ppAnnotationMark != m_vAnnotationMarks.end() &&
                        "<MarkManager::deleteMark(..)> - Annotation Mark not found in Annotation Mark container.");
                    m_vAnnotationMarks.erase(ppAnnotationMark);
                }
                break;

diff --git a/sw/source/core/txtnode/atrfld.cxx b/sw/source/core/txtnode/atrfld.cxx
index de3817e..4beca6d 100644
--- a/sw/source/core/txtnode/atrfld.cxx
+++ b/sw/source/core/txtnode/atrfld.cxx
@@ -618,18 +618,10 @@ SwTextAnnotationField::~SwTextAnnotationField()
::sw::mark::IMark* SwTextAnnotationField::GetAnnotationMark() const
{
    const SwPostItField* pPostItField = dynamic_cast<const SwPostItField*>(GetFormatField().GetField());
    OSL_ENSURE( pPostItField != nullptr, "<SwTextAnnotationField::GetAnnotationMark()> - field missing" );
    if ( pPostItField == nullptr )
    {
        return nullptr;
    }
    assert(pPostItField != nullptr);

    SwDoc* pDoc = static_cast<const SwPostItFieldType*>(pPostItField->GetTyp())->GetDoc();
    OSL_ENSURE( pDoc != nullptr, "<SwTextAnnotationField::GetAnnotationMark()> - missing document" );
    if ( pDoc == nullptr )
    {
        return nullptr;
    }
    assert(pDoc != nullptr);

    IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
    IDocumentMarkAccess::const_iterator_t pMark = pMarksAccess->findAnnotationMark( pPostItField->GetName() );
diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx
index 3e8828c..fa2d6d0 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -297,15 +297,12 @@ namespace
            if ( rStartPos.nNode == nOwnNode )
            {
                const SwFormatField* pAnnotationFormatField = pAnnotationMark->GetAnnotationFormatField();
                OSL_ENSURE( pAnnotationFormatField != nullptr, "<lcl_FillAnnotationStartArray(..)> - annotation fmt fld instance missing!" );
                if ( pAnnotationFormatField != nullptr )
                {
                    rAnnotationStartArr.insert(
                        std::make_shared<SwAnnotationStartPortion_Impl>(
                                SwXTextField::CreateXTextField(&rDoc,
                                    pAnnotationFormatField),
                                rStartPos));
                }
                assert(pAnnotationFormatField != nullptr);
                rAnnotationStartArr.insert(
                    std::make_shared<SwAnnotationStartPortion_Impl>(
                            SwXTextField::CreateXTextField(&rDoc,
                                pAnnotationFormatField),
                            rStartPos));
            }
        }
    }