From 1ffba0e356608fb6dbf568248e2a953b4d7fb5d6 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 28 Sep 2017 10:33:09 +0200 Subject: 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 Reviewed-by: Noel Grandin --- .../moduleuiconfigurationmanager.cxx | 88 ++++++++++------------ .../uiconfiguration/uiconfigurationmanager.cxx | 35 ++++----- .../uiconfiguration/windowstateconfiguration.cxx | 76 +++++++++---------- 3 files changed, 90 insertions(+), 109 deletions(-) (limited to 'framework/source/uiconfiguration') diff --git a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx index 403e045c99f8..fcde32765a42 100644 --- a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx +++ b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx @@ -1128,17 +1128,15 @@ sal_Bool SAL_CALL ModuleUIConfigurationManager::hasSettings( const OUString& Res if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); - if ( pDataSettings ) - return true; - } + if ( m_bDisposed ) + throw DisposedException(); + + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); + if ( pDataSettings ) + return true; return false; } @@ -1150,22 +1148,20 @@ Reference< XIndexAccess > SAL_CALL ModuleUIConfigurationManager::getSettings( co if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); - if ( pDataSettings ) - { - // Create a copy of our data if someone wants to change the data. - if ( bWriteable ) - return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); - else - return pDataSettings->xSettings; - } + if ( m_bDisposed ) + throw DisposedException(); + + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); + if ( pDataSettings ) + { + // Create a copy of our data if someone wants to change the data. + if ( bWriteable ) + return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); + else + return pDataSettings->xSettings; } throw NoSuchElementException(); @@ -1474,17 +1470,15 @@ sal_Bool SAL_CALL ModuleUIConfigurationManager::isDefaultSettings( const OUStrin if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); - if ( pDataSettings && pDataSettings->bDefaultNode ) - return true; - } + if ( m_bDisposed ) + throw DisposedException(); + + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); + if ( pDataSettings && pDataSettings->bDefaultNode ) + return true; return false; } @@ -1496,25 +1490,23 @@ Reference< XIndexAccess > SAL_CALL ModuleUIConfigurationManager::getDefaultSetti if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - // preload list of element types on demand - impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType ); + if ( m_bDisposed ) + throw DisposedException(); - // Look into our default vector/unordered_map combination - UIElementDataHashMap& rDefaultHashMap = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap; - UIElementDataHashMap::iterator pIter = rDefaultHashMap.find( ResourceURL ); - if ( pIter != rDefaultHashMap.end() ) - { - if ( !pIter->second.xSettings.is() ) - impl_requestUIElementData( nElementType, LAYER_DEFAULT, pIter->second ); - return pIter->second.xSettings; - } + // preload list of element types on demand + impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType ); + + // Look into our default vector/unordered_map combination + UIElementDataHashMap& rDefaultHashMap = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap; + UIElementDataHashMap::iterator pIter = rDefaultHashMap.find( ResourceURL ); + if ( pIter != rDefaultHashMap.end() ) + { + if ( !pIter->second.xSettings.is() ) + impl_requestUIElementData( nElementType, LAYER_DEFAULT, pIter->second ); + return pIter->second.xSettings; } // Nothing has been found! diff --git a/framework/source/uiconfiguration/uiconfigurationmanager.cxx b/framework/source/uiconfiguration/uiconfigurationmanager.cxx index 06b267a48700..16a3ca5310cf 100644 --- a/framework/source/uiconfiguration/uiconfigurationmanager.cxx +++ b/framework/source/uiconfiguration/uiconfigurationmanager.cxx @@ -902,12 +902,9 @@ sal_Bool SAL_CALL UIConfigurationManager::hasSettings( const OUString& ResourceU if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); - if ( pDataSettings && !pDataSettings->bDefault ) - return true; - } + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); + if ( pDataSettings && !pDataSettings->bDefault ) + return true; return false; } @@ -919,22 +916,20 @@ Reference< XIndexAccess > SAL_CALL UIConfigurationManager::getSettings( const OU if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); - if ( pDataSettings && !pDataSettings->bDefault ) - { - // Create a copy of our data if someone wants to change the data. - if ( bWriteable ) - return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); - else - return pDataSettings->xSettings; - } + if ( m_bDisposed ) + throw DisposedException(); + + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); + if ( pDataSettings && !pDataSettings->bDefault ) + { + // Create a copy of our data if someone wants to change the data. + if ( bWriteable ) + return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); + else + return pDataSettings->xSettings; } throw NoSuchElementException(); diff --git a/framework/source/uiconfiguration/windowstateconfiguration.cxx b/framework/source/uiconfiguration/windowstateconfiguration.cxx index 97c71e7a39b4..99a6464c50e0 100644 --- a/framework/source/uiconfiguration/windowstateconfiguration.cxx +++ b/framework/source/uiconfiguration/windowstateconfiguration.cxx @@ -255,8 +255,7 @@ Any SAL_CALL ConfigurationAccess_WindowState::getByName( const OUString& rResour Any a( impl_getWindowStateFromResourceURL( rResourceURL ) ); if ( a == Any() ) throw NoSuchElementException(); - else - return a; + return a; } } @@ -365,54 +364,49 @@ void SAL_CALL ConfigurationAccess_WindowState::insertByName( const OUString& rRe ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL ); if ( pIter != m_aResourceURLToInfoCache.end() ) throw ElementExistException(); - else + + if ( !m_bConfigAccessInitialized ) { - if ( !m_bConfigAccessInitialized ) - { - impl_initializeConfigAccess(); - m_bConfigAccessInitialized = true; - } + impl_initializeConfigAccess(); + m_bConfigAccessInitialized = true; + } - // Try to ask our configuration access - if ( m_xConfigAccess.is() ) + // Try to ask our configuration access + if ( m_xConfigAccess.is() ) + { + if ( m_xConfigAccess->hasByName( rResourceURL ) ) + throw ElementExistException(); + + WindowStateInfo aWinStateInfo; + impl_fillStructFromSequence( aWinStateInfo, aPropSet ); + m_aResourceURLToInfoCache.emplace( rResourceURL, aWinStateInfo ); + + // insert must be write-through => insert element into configuration + Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY ); + if ( xNameContainer.is() ) { - if ( m_xConfigAccess->hasByName( rResourceURL ) ) - throw ElementExistException(); - else - { - WindowStateInfo aWinStateInfo; - impl_fillStructFromSequence( aWinStateInfo, aPropSet ); - m_aResourceURLToInfoCache.emplace( rResourceURL, aWinStateInfo ); + Reference< XSingleServiceFactory > xFactory( m_xConfigAccess, UNO_QUERY ); + g.clear(); - // insert must be write-through => insert element into configuration - Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY ); - if ( xNameContainer.is() ) + try + { + Reference< XPropertySet > xPropSet( xFactory->createInstance(), UNO_QUERY ); + if ( xPropSet.is() ) { - Reference< XSingleServiceFactory > xFactory( m_xConfigAccess, UNO_QUERY ); - g.clear(); - - try - { - Reference< XPropertySet > xPropSet( xFactory->createInstance(), UNO_QUERY ); - if ( xPropSet.is() ) - { - Any a; - impl_putPropertiesFromStruct( aWinStateInfo, xPropSet ); - a <<= xPropSet; - xNameContainer->insertByName( rResourceURL, a ); - Reference< XChangesBatch > xFlush( xFactory, UNO_QUERY ); - if ( xFlush.is() ) - xFlush->commitChanges(); - } - } - catch ( const Exception& ) - { - } + Any a; + impl_putPropertiesFromStruct( aWinStateInfo, xPropSet ); + a <<= xPropSet; + xNameContainer->insertByName( rResourceURL, a ); + Reference< XChangesBatch > xFlush( xFactory, UNO_QUERY ); + if ( xFlush.is() ) + xFlush->commitChanges(); } } + catch ( const Exception& ) + { + } } } - } // XNameReplace -- cgit v1.2.3