summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-09-28 10:33:09 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-09-29 08:51:48 +0200
commit1ffba0e356608fb6dbf568248e2a953b4d7fb5d6 (patch)
tree5da59640441292421f2137bc85ee7291daed137e /sw
parentce9a41dc387966c74c1af92783a97565b5af3668 (diff)
loplugin:flatten check for throw in then clause
also make the plugin ignore the case where we have var decl's in the clause we want to flatten, which could lead to problematic extension of variable lifetime Change-Id: I3061f7104e8c6a460bf74f5eac325a516ec50c59 Reviewed-on: https://gerrit.libreoffice.org/42889 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/access/accpara.cxx4
-rw-r--r--sw/source/core/unocore/unochart.cxx13
-rw-r--r--sw/source/core/unocore/unodraw.cxx87
-rw-r--r--sw/source/core/unocore/unosett.cxx3
-rw-r--r--sw/source/core/unocore/unotext.cxx24
-rw-r--r--sw/source/uibase/uno/unomailmerge.cxx72
-rw-r--r--sw/source/uibase/uno/unotxvw.cxx60
7 files changed, 125 insertions, 138 deletions
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index e25061c79c33..73d1b437e4d6 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -3138,9 +3138,7 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::getHyperLinkIndex( sal_Int32 nCharInde
if (nRet == -1)
throw lang::IndexOutOfBoundsException();
- else
- return nRet;
- //return nRet;
+ return nRet;
}
// #i71360#, #i108125# - adjustments for change tracking text markup
diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx
index 03dac9d63e22..b7a40b0d66fb 100644
--- a/sw/source/core/unocore/unochart.cxx
+++ b/sw/source/core/unocore/unochart.cxx
@@ -1997,13 +1997,12 @@ uno::Sequence< OUString > SAL_CALL SwChartDataSequence::generateLabel(
SwTable* pTable = pTableFormat ? SwTable::FindTable( pTableFormat ) : nullptr;
if (!pTableFormat || !pTable || pTable->IsTableComplex())
throw uno::RuntimeException();
- else
- {
- const OUString aCellRange( GetCellRangeName( *pTableFormat, *m_pTableCursor ) );
- OSL_ENSURE( !aCellRange.isEmpty(), "failed to get cell range" );
- bOk = FillRangeDescriptor( aDesc, aCellRange );
- OSL_ENSURE( bOk, "failed to get SwRangeDescriptor" );
- }
+
+ const OUString aCellRange( GetCellRangeName( *pTableFormat, *m_pTableCursor ) );
+ OSL_ENSURE( !aCellRange.isEmpty(), "failed to get cell range" );
+ bOk = FillRangeDescriptor( aDesc, aCellRange );
+ OSL_ENSURE( bOk, "failed to get SwRangeDescriptor" );
+
if (bOk)
{
aDesc.Normalize();
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index a112acc2e4b5..2dc746ca6f7f 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -1121,54 +1121,51 @@ void SwXShape::setPropertyValue(const OUString& rPropertyName, const uno::Any& a
// set property <TextRange> not valid for to-page anchored shapes
throw lang::IllegalArgumentException();
}
- else
+
+ std::unique_ptr<SwUnoInternalPaM> pInternalPam(
+ new SwUnoInternalPaM( *(pFormat->GetDoc()) ));
+ uno::Reference< text::XTextRange > xRg;
+ aValue >>= xRg;
+ if (!::sw::XTextRangeToSwPaM(*pInternalPam, xRg) )
{
- std::unique_ptr<SwUnoInternalPaM> pInternalPam(
- new SwUnoInternalPaM( *(pFormat->GetDoc()) ));
- uno::Reference< text::XTextRange > xRg;
- aValue >>= xRg;
- if (!::sw::XTextRangeToSwPaM(*pInternalPam, xRg) )
- {
- throw uno::RuntimeException();
- }
+ throw uno::RuntimeException();
+ }
- if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR)
- {
- //delete old SwFormatFlyCnt
- //With AnchorAsCharacter the current TextAttribute has to be deleted.
- //Tbis removes the frame format too.
- //To prevent this the connection between format and attribute has to be broken before.
- const SwPosition *pPos = aAnchor.GetContentAnchor();
- SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode();
- SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." );
- const sal_Int32 nIdx = pPos->nContent.GetIndex();
- SwTextAttr * const pHint =
+ if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR)
+ {
+ //delete old SwFormatFlyCnt
+ //With AnchorAsCharacter the current TextAttribute has to be deleted.
+ //Tbis removes the frame format too.
+ //To prevent this the connection between format and attribute has to be broken before.
+ const SwPosition *pPos = aAnchor.GetContentAnchor();
+ SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode();
+ SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." );
+ const sal_Int32 nIdx = pPos->nContent.GetIndex();
+ SwTextAttr * const pHint =
pTextNode->GetTextAttrForCharAt(
- nIdx, RES_TXTATR_FLYCNT );
- assert(pHint && "Missing Hint.");
- SAL_WARN_IF( pHint->Which() != RES_TXTATR_FLYCNT,
- "sw.uno", "Missing FlyInCnt-Hint." );
- SAL_WARN_IF( pHint->GetFlyCnt().GetFrameFormat() != pFormat,
- "sw.uno", "Wrong TextFlyCnt-Hint." );
- const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt())
- .SetFlyFormat();
-
- //The connection is removed now the attribute can be deleted.
- pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx );
- //create a new one
- SwTextNode *pNd = pInternalPam->GetNode().GetTextNode();
- SAL_WARN_IF( !pNd, "sw.uno", "Cursor not at TextNode." );
- SwFormatFlyCnt aFormat( pFormat );
- pNd->InsertItem(aFormat, pInternalPam->GetPoint()
- ->nContent.GetIndex(), 0 );
- }
- else
- {
- aAnchor.SetAnchor( pInternalPam->GetPoint() );
- aSet.Put(aAnchor);
- pFormat->SetFormatAttr(aSet);
- }
-
+ nIdx, RES_TXTATR_FLYCNT );
+ assert(pHint && "Missing Hint.");
+ SAL_WARN_IF( pHint->Which() != RES_TXTATR_FLYCNT,
+ "sw.uno", "Missing FlyInCnt-Hint." );
+ SAL_WARN_IF( pHint->GetFlyCnt().GetFrameFormat() != pFormat,
+ "sw.uno", "Wrong TextFlyCnt-Hint." );
+ const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt())
+ .SetFlyFormat();
+
+ //The connection is removed now the attribute can be deleted.
+ pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx );
+ //create a new one
+ SwTextNode *pNd = pInternalPam->GetNode().GetTextNode();
+ SAL_WARN_IF( !pNd, "sw.uno", "Cursor not at TextNode." );
+ SwFormatFlyCnt aFormat( pFormat );
+ pNd->InsertItem(aFormat, pInternalPam->GetPoint()
+ ->nContent.GetIndex(), 0 );
+ }
+ else
+ {
+ aAnchor.SetAnchor( pInternalPam->GetPoint() );
+ aSet.Put(aAnchor);
+ pFormat->SetFormatAttr(aSet);
}
}
else if (pEntry->nWID == FN_TEXT_BOX)
diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx
index 9616c94718f6..ffc325c1cfec 100644
--- a/sw/source/core/unocore/unosett.cxx
+++ b/sw/source/core/unocore/unosett.cxx
@@ -2458,8 +2458,7 @@ void SwXTextColumns::setPropertyValue( const OUString& rPropertyName, const Any&
sal_Int8 nTmp = 0;
if (! ( aValue >>= nTmp ) )
throw IllegalArgumentException();
- else
- nSepLineVertAlign = (style::VerticalAlignment)nTmp;
+ nSepLineVertAlign = (style::VerticalAlignment)nTmp;
}
else
nSepLineVertAlign = eAlign;
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 646a802b61de..48a3ff6109f1 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1883,22 +1883,20 @@ void SwXText::Impl::ConvertCell(
{
throw lang::IllegalArgumentException();
}
- else
+
+ m_pDoc->getIDocumentContentOperations().SplitNode(*aStartCellPam.Start(), false);
+ sal_uLong const nNewIndex(aStartCellPam.Start()->nNode.GetIndex());
+ if (nNewIndex != nStartCellNodeIndex)
{
- m_pDoc->getIDocumentContentOperations().SplitNode(*aStartCellPam.Start(), false);
- sal_uLong const nNewIndex(aStartCellPam.Start()->nNode.GetIndex());
- if (nNewIndex != nStartCellNodeIndex)
+ // aStartCellPam now points to the 2nd node
+ // the last cell may *also* point to 2nd node now - fix it!
+ assert(nNewIndex == nStartCellNodeIndex + 1);
+ if (pLastCell->aEnd.GetIndex() == nNewIndex)
{
- // aStartCellPam now points to the 2nd node
- // the last cell may *also* point to 2nd node now - fix it!
- assert(nNewIndex == nStartCellNodeIndex + 1);
- if (pLastCell->aEnd.GetIndex() == nNewIndex)
+ --pLastCell->aEnd;
+ if (pLastCell->aStart.GetIndex() == nNewIndex)
{
- --pLastCell->aEnd;
- if (pLastCell->aStart.GetIndex() == nNewIndex)
- {
- --pLastCell->aStart;
- }
+ --pLastCell->aStart;
}
}
}
diff --git a/sw/source/uibase/uno/unomailmerge.cxx b/sw/source/uibase/uno/unomailmerge.cxx
index e68f614c3729..871b24520a6f 100644
--- a/sw/source/uibase/uno/unomailmerge.cxx
+++ b/sw/source/uibase/uno/unomailmerge.cxx
@@ -1034,44 +1034,42 @@ uno::Any SAL_CALL SwXMailMerge::getPropertyValue(
const SfxItemPropertySimpleEntry* pCur = m_pPropSet->getPropertyMap().getByName( rPropertyName );
if (!pCur)
throw UnknownPropertyException();
- else
+
+ switch (pCur->nWID)
{
- switch (pCur->nWID)
- {
- case WID_SELECTION : aRet <<= m_aSelection; break;
- case WID_RESULT_SET : aRet <<= m_xResultSet; break;
- case WID_CONNECTION : aRet <<= m_xConnection; break;
- case WID_MODEL : aRet <<= m_xModel; break;
- case WID_DATA_SOURCE_NAME : aRet <<= m_aDataSourceName; break;
- case WID_DATA_COMMAND : aRet <<= m_aDataCommand; break;
- case WID_FILTER : aRet <<= m_aFilter; break;
- case WID_DOCUMENT_URL : aRet <<= m_aDocumentURL; break;
- case WID_OUTPUT_URL : aRet <<= m_aOutputURL; break;
- case WID_DATA_COMMAND_TYPE : aRet <<= m_nDataCommandType; break;
- case WID_OUTPUT_TYPE : aRet <<= m_nOutputType; break;
- case WID_ESCAPE_PROCESSING : aRet <<= m_bEscapeProcessing; break;
- case WID_SINGLE_PRINT_JOBS : aRet <<= m_bSinglePrintJobs; break;
- case WID_FILE_NAME_FROM_COLUMN : aRet <<= m_bFileNameFromColumn; break;
- case WID_FILE_NAME_PREFIX : aRet <<= m_aFileNamePrefix; break;
- case WID_MAIL_SUBJECT: aRet <<= m_sSubject; break;
- case WID_ADDRESS_FROM_COLUMN: aRet <<= m_sAddressFromColumn; break;
- case WID_SEND_AS_HTML: aRet <<= m_bSendAsHTML; break;
- case WID_SEND_AS_ATTACHMENT: aRet <<= m_bSendAsAttachment; break;
- case WID_MAIL_BODY: aRet <<= m_sMailBody; break;
- case WID_ATTACHMENT_NAME: aRet <<= m_sAttachmentName; break;
- case WID_ATTACHMENT_FILTER: aRet <<= m_sAttachmentFilter;break;
- case WID_PRINT_OPTIONS: aRet <<= m_aPrintSettings; break;
- case WID_SAVE_AS_SINGLE_FILE: aRet <<= m_bSaveAsSingleFile; break;
- case WID_SAVE_FILTER: aRet <<= m_sSaveFilter; break;
- case WID_SAVE_FILTER_OPTIONS: aRet <<= m_sSaveFilterOptions; break;
- case WID_SAVE_FILTER_DATA: aRet <<= m_aSaveFilterData; break;
- case WID_COPIES_TO: aRet <<= m_aCopiesTo; break;
- case WID_BLIND_COPIES_TO: aRet <<= m_aBlindCopiesTo;break;
- case WID_IN_SERVER_PASSWORD: aRet <<= m_sInServerPassword; break;
- case WID_OUT_SERVER_PASSWORD: aRet <<= m_sOutServerPassword; break;
- default :
- OSL_FAIL("unknown WID");
- }
+ case WID_SELECTION : aRet <<= m_aSelection; break;
+ case WID_RESULT_SET : aRet <<= m_xResultSet; break;
+ case WID_CONNECTION : aRet <<= m_xConnection; break;
+ case WID_MODEL : aRet <<= m_xModel; break;
+ case WID_DATA_SOURCE_NAME : aRet <<= m_aDataSourceName; break;
+ case WID_DATA_COMMAND : aRet <<= m_aDataCommand; break;
+ case WID_FILTER : aRet <<= m_aFilter; break;
+ case WID_DOCUMENT_URL : aRet <<= m_aDocumentURL; break;
+ case WID_OUTPUT_URL : aRet <<= m_aOutputURL; break;
+ case WID_DATA_COMMAND_TYPE : aRet <<= m_nDataCommandType; break;
+ case WID_OUTPUT_TYPE : aRet <<= m_nOutputType; break;
+ case WID_ESCAPE_PROCESSING : aRet <<= m_bEscapeProcessing; break;
+ case WID_SINGLE_PRINT_JOBS : aRet <<= m_bSinglePrintJobs; break;
+ case WID_FILE_NAME_FROM_COLUMN : aRet <<= m_bFileNameFromColumn; break;
+ case WID_FILE_NAME_PREFIX : aRet <<= m_aFileNamePrefix; break;
+ case WID_MAIL_SUBJECT: aRet <<= m_sSubject; break;
+ case WID_ADDRESS_FROM_COLUMN: aRet <<= m_sAddressFromColumn; break;
+ case WID_SEND_AS_HTML: aRet <<= m_bSendAsHTML; break;
+ case WID_SEND_AS_ATTACHMENT: aRet <<= m_bSendAsAttachment; break;
+ case WID_MAIL_BODY: aRet <<= m_sMailBody; break;
+ case WID_ATTACHMENT_NAME: aRet <<= m_sAttachmentName; break;
+ case WID_ATTACHMENT_FILTER: aRet <<= m_sAttachmentFilter;break;
+ case WID_PRINT_OPTIONS: aRet <<= m_aPrintSettings; break;
+ case WID_SAVE_AS_SINGLE_FILE: aRet <<= m_bSaveAsSingleFile; break;
+ case WID_SAVE_FILTER: aRet <<= m_sSaveFilter; break;
+ case WID_SAVE_FILTER_OPTIONS: aRet <<= m_sSaveFilterOptions; break;
+ case WID_SAVE_FILTER_DATA: aRet <<= m_aSaveFilterData; break;
+ case WID_COPIES_TO: aRet <<= m_aCopiesTo; break;
+ case WID_BLIND_COPIES_TO: aRet <<= m_aBlindCopiesTo;break;
+ case WID_IN_SERVER_PASSWORD: aRet <<= m_sInServerPassword; break;
+ case WID_OUT_SERVER_PASSWORD: aRet <<= m_sOutServerPassword; break;
+ default :
+ OSL_FAIL("unknown WID");
}
return aRet;
diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx
index 3515f1f34f5e..df3b8c3a164a 100644
--- a/sw/source/uibase/uno/unotxvw.cxx
+++ b/sw/source/uibase/uno/unotxvw.cxx
@@ -740,40 +740,38 @@ uno::Any SAL_CALL SwXTextView::getPropertyValue(
const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
if (!pEntry)
throw UnknownPropertyException();
- else
+
+ sal_Int16 nWID = pEntry->nWID;
+ switch (nWID)
{
- sal_Int16 nWID = pEntry->nWID;
- switch (nWID)
+ case WID_PAGE_COUNT :
+ case WID_LINE_COUNT :
{
- case WID_PAGE_COUNT :
- case WID_LINE_COUNT :
- {
- // format document completely in order to get meaningful
- // values for page count and line count
- m_pView->GetWrtShell().CalcLayout();
-
- sal_Int32 nCount = -1;
- if (nWID == WID_PAGE_COUNT)
- nCount = m_pView->GetWrtShell().GetPageCount();
- else // WID_LINE_COUNT
- nCount = m_pView->GetWrtShell().GetLineCount();
- aRet <<= nCount;
- }
- break;
- case WID_IS_HIDE_SPELL_MARKS :
- // deprecated #i91949
- break;
- case WID_IS_CONSTANT_SPELLCHECK :
- {
- const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions();
- if (!pOpt)
- throw RuntimeException();
- aRet <<= bool(pOpt->GetCoreOptions() & ViewOptFlags1::OnlineSpell);
- }
- break;
- default :
- OSL_FAIL("unknown WID");
+ // format document completely in order to get meaningful
+ // values for page count and line count
+ m_pView->GetWrtShell().CalcLayout();
+
+ sal_Int32 nCount = -1;
+ if (nWID == WID_PAGE_COUNT)
+ nCount = m_pView->GetWrtShell().GetPageCount();
+ else // WID_LINE_COUNT
+ nCount = m_pView->GetWrtShell().GetLineCount();
+ aRet <<= nCount;
+ }
+ break;
+ case WID_IS_HIDE_SPELL_MARKS :
+ // deprecated #i91949
+ break;
+ case WID_IS_CONSTANT_SPELLCHECK :
+ {
+ const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions();
+ if (!pOpt)
+ throw RuntimeException();
+ aRet <<= bool(pOpt->GetCoreOptions() & ViewOptFlags1::OnlineSpell);
}
+ break;
+ default :
+ OSL_FAIL("unknown WID");
}
return aRet;