From a8622c77d26ca7a635afc95bba9a5054dc31eb7c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 22 Sep 2017 12:53:28 +0200 Subject: loplugin:flatten in sdext..stoc Change-Id: I460e813e20a691c53738373376d3363f553bbab2 Reviewed-on: https://gerrit.libreoffice.org/42636 Tested-by: Jenkins Reviewed-by: Noel Grandin --- stoc/source/corereflection/crcomp.cxx | 14 ++---- stoc/source/corereflection/crefl.cxx | 8 ++-- stoc/source/corereflection/criface.cxx | 5 +-- stoc/source/defaultregistry/defaultregistry.cxx | 60 +++++++++++-------------- stoc/source/inspect/introspection.cxx | 5 +-- stoc/source/javaloader/javaloader.cxx | 10 ++--- stoc/source/security/access_controller.cxx | 16 +++---- stoc/source/typeconv/convert.cxx | 31 ++++++------- 8 files changed, 62 insertions(+), 87 deletions(-) (limited to 'stoc') diff --git a/stoc/source/corereflection/crcomp.cxx b/stoc/source/corereflection/crcomp.cxx index 0a0572676a73..01e043144075 100644 --- a/stoc/source/corereflection/crcomp.cxx +++ b/stoc/source/corereflection/crcomp.cxx @@ -210,16 +210,13 @@ void IdlCompFieldImpl::set( const Any & rObj, const Any & rValue ) if (pTD) { TYPELIB_DANGER_RELEASE( pObjTD ); - if (coerce_assign( const_cast(static_cast(rObj.getValue()) + _nOffset), getTypeDescr(), rValue, getReflection() )) - { - return; - } - else + if (!coerce_assign( const_cast(static_cast(rObj.getValue()) + _nOffset), getTypeDescr(), rValue, getReflection() )) { throw IllegalArgumentException( "cannot assign value to destination", static_cast(static_cast(this)), 1 ); } + return; } TYPELIB_DANGER_RELEASE( pObjTD ); } @@ -246,16 +243,13 @@ void IdlCompFieldImpl::set( Any & rObj, const Any & rValue ) if (pTD) { TYPELIB_DANGER_RELEASE( pObjTD ); - if (coerce_assign( const_cast(static_cast(rObj.getValue()) + _nOffset), getTypeDescr(), rValue, getReflection() )) - { - return; - } - else + if (!coerce_assign( const_cast(static_cast(rObj.getValue()) + _nOffset), getTypeDescr(), rValue, getReflection() )) { throw IllegalArgumentException( "cannot assign to destination", static_cast(static_cast(this)), 1 ); } + return; } TYPELIB_DANGER_RELEASE( pObjTD ); } diff --git a/stoc/source/corereflection/crefl.cxx b/stoc/source/corereflection/crefl.cxx index 00c9429b3586..8982b768a684 100644 --- a/stoc/source/corereflection/crefl.cxx +++ b/stoc/source/corereflection/crefl.cxx @@ -264,12 +264,10 @@ Any IdlReflectionServiceImpl::getByHierarchicalName( const OUString & rName ) // else is enum member(?) // update - if (aRet.hasValue()) - _aElements.setValue( rName, aRet ); - else - { + if (!aRet.hasValue()) throw container::NoSuchElementException( rName ); - } + + _aElements.setValue( rName, aRet ); } return aRet; } diff --git a/stoc/source/corereflection/criface.cxx b/stoc/source/corereflection/criface.cxx index 680e55083dd4..841cb235eb90 100644 --- a/stoc/source/corereflection/criface.cxx +++ b/stoc/source/corereflection/criface.cxx @@ -296,16 +296,15 @@ void IdlAttributeFieldImpl::checkException( &e, exception->pData, exception->pType, getReflection()->getUno2Cpp().get()); uno_any_destruct(exception, nullptr); - if (e.isExtractableTo( + if (!e.isExtractableTo( cppu::UnoType::get())) { - cppu::throwException(e); - } else { throw WrappedTargetRuntimeException( "non-RuntimeException occurred when accessing an" " interface type attribute", context, e); } + cppu::throwException(e); } } diff --git a/stoc/source/defaultregistry/defaultregistry.cxx b/stoc/source/defaultregistry/defaultregistry.cxx index fb54149dc27d..5f24b18e34f6 100644 --- a/stoc/source/defaultregistry/defaultregistry.cxx +++ b/stoc/source/defaultregistry/defaultregistry.cxx @@ -263,10 +263,10 @@ sal_Bool SAL_CALL NestedKeyImpl::isReadOnly( ) Guard< Mutex > aGuard( m_xRegistry->m_mutex ); computeChanges(); - if ( m_localKey.is() && m_localKey->isValid() ) - return m_localKey->isReadOnly(); - else + if ( !m_localKey.is() || !m_localKey->isValid() ) throw InvalidRegistryException(); + + return m_localKey->isReadOnly(); } @@ -724,22 +724,20 @@ void SAL_CALL NestedKeyImpl::closeKey( ) void SAL_CALL NestedKeyImpl::deleteKey( const OUString& rKeyName ) { Guard< Mutex > aGuard( m_xRegistry->m_mutex ); - if ( m_localKey.is() && m_localKey->isValid() && - !m_localKey->isReadOnly() ) + if ( !m_localKey.is() || !m_localKey->isValid() || + m_localKey->isReadOnly() ) { - OUString resolvedName = computeName(rKeyName); + throw InvalidRegistryException(); + } - if ( resolvedName.isEmpty() ) - { - throw InvalidRegistryException(); - } + OUString resolvedName = computeName(rKeyName); - m_xRegistry->m_localReg->getRootKey()->deleteKey(resolvedName); - } - else + if ( resolvedName.isEmpty() ) { throw InvalidRegistryException(); } + + m_xRegistry->m_localReg->getRootKey()->deleteKey(resolvedName); } @@ -976,15 +974,13 @@ void SAL_CALL NestedKeyImpl::deleteLink( const OUString& rLinkName ) resolvedName = m_name + "/" + rLinkName; } - if ( m_localKey.is() && m_localKey->isValid() && - !m_localKey->isReadOnly() ) - { - m_xRegistry->m_localReg->getRootKey()->deleteLink(resolvedName); - } - else + if ( !m_localKey.is() || !m_localKey->isValid() || + m_localKey->isReadOnly() ) { throw InvalidRegistryException(); } + + m_xRegistry->m_localReg->getRootKey()->deleteLink(resolvedName); } @@ -1224,25 +1220,23 @@ void SAL_CALL NestedRegistryImpl::destroy( ) Reference< XRegistryKey > SAL_CALL NestedRegistryImpl::getRootKey( ) { Guard< Mutex > aGuard( m_mutex ); - if ( m_localReg.is() && m_localReg->isValid() ) + if ( !m_localReg.is() || !m_localReg->isValid() ) { - Reference localKey, defaultKey; + throw InvalidRegistryException(); + } - localKey = m_localReg->getRootKey(); + Reference localKey, defaultKey; - if ( localKey.is() ) - { - if ( m_defaultReg.is() && m_defaultReg->isValid() ) - { - defaultKey = m_defaultReg->getRootKey(); - } + localKey = m_localReg->getRootKey(); - return static_cast(new NestedKeyImpl(this, localKey, defaultKey)); - } - } - else + if ( localKey.is() ) { - throw InvalidRegistryException(); + if ( m_defaultReg.is() && m_defaultReg->isValid() ) + { + defaultKey = m_defaultReg->getRootKey(); + } + + return static_cast(new NestedKeyImpl(this, localKey, defaultKey)); } return Reference(); diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx index 063e868a1604..3bb086d5ad7d 100644 --- a/stoc/source/inspect/introspection.cxx +++ b/stoc/source/inspect/introspection.cxx @@ -372,10 +372,9 @@ void IntrospectionAccessStatic_Impl::setPropertyValue( const Any& obj, const OUS //void IntrospectionAccessStatic_Impl::setPropertyValue( Any& obj, const OUString& aPropertyName, const Any& aValue ) const { sal_Int32 i = getPropertyIndex( aPropertyName ); - if( i != -1 ) - setPropertyValueByIndex( obj, i, aValue ); - else + if( i == -1 ) throw UnknownPropertyException(aPropertyName); + setPropertyValueByIndex( obj, i, aValue ); } void IntrospectionAccessStatic_Impl::setPropertyValueByIndex(const Any& obj, sal_Int32 nSequenceIndex, const Any& aValue) const diff --git a/stoc/source/javaloader/javaloader.cxx b/stoc/source/javaloader/javaloader.cxx index 01000b0ab827..2139815d357c 100644 --- a/stoc/source/javaloader/javaloader.cxx +++ b/stoc/source/javaloader/javaloader.cxx @@ -310,10 +310,9 @@ sal_Bool SAL_CALL JavaComponentLoader::writeRegistryInfo( const OUString & rLibName) { const css::uno::Reference & loader = getJavaLoader(); - if (loader.is()) - return loader->writeRegistryInfo(xKey, blabla, rLibName); - else + if (!loader.is()) throw CannotRegisterImplementationException("Could not create Java implementation loader"); + return loader->writeRegistryInfo(xKey, blabla, rLibName); } @@ -322,10 +321,9 @@ css::uno::Reference SAL_CALL JavaComponentLoader::activate( const css::uno::Reference & xKey) { const css::uno::Reference & loader = getJavaLoader(); - if (loader.is()) - return loader->activate(rImplName, blabla, rLibName, xKey); - else + if (!loader.is()) throw CannotActivateFactoryException("Could not create Java implementation loader"); + return loader->activate(rImplName, blabla, rLibName, xKey); } static Mutex & getInitMutex() diff --git a/stoc/source/security/access_controller.cxx b/stoc/source/security/access_controller.cxx index 65771de2bd99..06fdc0e4cfbf 100644 --- a/stoc/source/security/access_controller.cxx +++ b/stoc/source/security/access_controller.cxx @@ -439,19 +439,17 @@ Reference< security::XPolicy > const & AccessController::getPolicy() Reference< security::XPolicy > xPolicy; m_xComponentContext->getValueByName( "/singletons/com.sun.star.security.thePolicy" ) >>= xPolicy; - if (xPolicy.is()) - { - MutexGuard guard( m_mutex ); - if (! m_xPolicy.is()) - { - m_xPolicy = xPolicy; - } - } - else + if (!xPolicy.is()) { throw SecurityException( "cannot get policy singleton!", static_cast(this) ); } + + MutexGuard guard( m_mutex ); + if (! m_xPolicy.is()) + { + m_xPolicy = xPolicy; + } } return m_xPolicy; } diff --git a/stoc/source/typeconv/convert.cxx b/stoc/source/typeconv/convert.cxx index 8a0ea977272d..011340f4e88e 100644 --- a/stoc/source/typeconv/convert.cxx +++ b/stoc/source/typeconv/convert.cxx @@ -507,17 +507,14 @@ Any SAL_CALL TypeConverter_Impl::convertTo( const Any& rVal, const Type& aDestTy // same types or destination type is derived source type? TypeDescription aSourceTD( aSourceType ); TypeDescription aDestTD( aDestType ); - if (typelib_typedescription_isAssignableFrom( aDestTD.get(), aSourceTD.get() )) - { - aRet.setValue( rVal.getValue(), aDestTD.get() ); // evtl. .uP.cAsT. - } - else + if (!typelib_typedescription_isAssignableFrom( aDestTD.get(), aSourceTD.get() )) { throw CannotConvertException( "value is not of same or derived type!", Reference< XInterface >(), aDestinationClass, FailReason::SOURCE_IS_NO_DERIVED_TYPE, 0 ); } + aRet.setValue( rVal.getValue(), aDestTD.get() ); // evtl. .uP.cAsT. break; } // --- to INTERFACE ------------------------------------------------------------------------- @@ -636,18 +633,17 @@ Any SAL_CALL TypeConverter_Impl::convertTo( const Any& rVal, const Type& aDestTy } } - if (nPos >= 0) - { - aRet.setValue( - &reinterpret_cast(aEnumTD.get())->pEnumValues[nPos], - aEnumTD.get() ); - } - else + if (nPos < 0) { throw CannotConvertException( "value cannot be converted to demanded ENUM!", Reference< XInterface >(), aDestinationClass, FailReason::IS_NOT_ENUM, 0 ); } + + aRet.setValue( + &reinterpret_cast(aEnumTD.get())->pEnumValues[nPos], + aEnumTD.get() ); + break; } @@ -815,17 +811,16 @@ Any TypeConverter_Impl::convertToSimpleType( const Any& rVal, TypeClass aDestina if (nEnumValue == reinterpret_cast(aEnumTD.get())->pEnumValues[nPos]) break; } - if (nPos >= 0) - { - aRet <<= OUString::unacquired( - &reinterpret_cast(aEnumTD.get())->ppEnumNames[nPos]); - } - else + if (nPos < 0) { throw CannotConvertException( "value is not ENUM!", Reference< XInterface >(), aDestinationClass, FailReason::IS_NOT_ENUM, 0 ); } + + aRet <<= OUString::unacquired( + &reinterpret_cast(aEnumTD.get())->ppEnumNames[nPos]); + break; } -- cgit