From 31c54fa7bb03768b425ae019096e0a0e26e9c736 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 7 Jul 2017 13:26:50 +0200 Subject: sw: convert SwTextAnnotationField OSL_ENSUREs to assert() and simplify Change-Id: Ica69cd4527f36edd7480d897a28ff814ecbe97a9 --- sw/source/core/crsr/annotationmark.cxx | 37 ++++++++++++---------------------- sw/source/core/doc/docbm.cxx | 12 +++-------- sw/source/core/txtnode/atrfld.cxx | 12 ++--------- sw/source/core/unocore/unoportenum.cxx | 15 ++++++-------- 4 files changed, 24 insertions(+), 52 deletions(-) (limited to 'sw') diff --git a/sw/source/core/crsr/annotationmark.cxx b/sw/source/core/crsr/annotationmark.cxx index bca5e903c72a..a73c1715bb36 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, " - 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, " - 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(pPostItField)->SetName( GetName() ); - } - } + const_cast(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, " - 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 7ea1692dd559..68030bbb2955 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 && - " - Annotation Mark not found in Annotation Mark container."); - } + assert(ppAnnotationMark != m_vAnnotationMarks.end() && + " - 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 de3817eeece9..4beca6d098c6 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(GetFormatField().GetField()); - OSL_ENSURE( pPostItField != nullptr, " - field missing" ); - if ( pPostItField == nullptr ) - { - return nullptr; - } + assert(pPostItField != nullptr); SwDoc* pDoc = static_cast(pPostItField->GetTyp())->GetDoc(); - OSL_ENSURE( pDoc != nullptr, " - 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 3e8828c51319..fa2d6d0173a7 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, " - annotation fmt fld instance missing!" ); - if ( pAnnotationFormatField != nullptr ) - { - rAnnotationStartArr.insert( - std::make_shared( - SwXTextField::CreateXTextField(&rDoc, - pAnnotationFormatField), - rStartPos)); - } + assert(pAnnotationFormatField != nullptr); + rAnnotationStartArr.insert( + std::make_shared( + SwXTextField::CreateXTextField(&rDoc, + pAnnotationFormatField), + rStartPos)); } } } -- cgit