diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-04-06 10:47:24 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-04-12 10:11:34 +0200 |
commit | 992a33313046f4a4d322db9464c474e7429a019a (patch) | |
tree | 494143e3070af872027ecaca840516d3101a881c /cppuhelper/source | |
parent | 77c1431ee88ab04a9ff48b849acedee6d455bafb (diff) |
clang-tidy: readability-else-after-return
run it against sal,cppu,cppuhelper
I had to run this multiple times to catch all the cases in each module,
and it requires some hand-tweaking of the resulting output - clang-tidy
is not very good about cleaning up trailing spaces, and aligning
things nicely.
Change-Id: I00336345f5f036e12422b98d66526509380c497a
Reviewed-on: https://gerrit.libreoffice.org/36194
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'cppuhelper/source')
-rw-r--r-- | cppuhelper/source/component.cxx | 2 | ||||
-rw-r--r-- | cppuhelper/source/component_context.cxx | 6 | ||||
-rw-r--r-- | cppuhelper/source/factory.cxx | 16 | ||||
-rw-r--r-- | cppuhelper/source/implbase_ex.cxx | 5 | ||||
-rw-r--r-- | cppuhelper/source/interfacecontainer.cxx | 30 | ||||
-rw-r--r-- | cppuhelper/source/propertysetmixin.cxx | 26 | ||||
-rw-r--r-- | cppuhelper/source/propshlp.cxx | 22 | ||||
-rw-r--r-- | cppuhelper/source/shlib.cxx | 128 |
8 files changed, 108 insertions, 127 deletions
diff --git a/cppuhelper/source/component.cxx b/cppuhelper/source/component.cxx index aa8e68c7dfbb..fdff1a21bab8 100644 --- a/cppuhelper/source/component.cxx +++ b/cppuhelper/source/component.cxx @@ -58,7 +58,7 @@ Any OComponentHelper::queryAggregation( Type const & rType ) void * p = static_cast< lang::XComponent * >( this ); return Any( &p, rType ); } - else if (rType == cppu::UnoType<lang::XTypeProvider>::get()) + if (rType == cppu::UnoType<lang::XTypeProvider>::get()) { void * p = static_cast< lang::XTypeProvider * >( this ); return Any( &p, rType ); diff --git a/cppuhelper/source/component_context.cxx b/cppuhelper/source/component_context.cxx index 355445da3076..2df1b495689c 100644 --- a/cppuhelper/source/component_context.cxx +++ b/cppuhelper/source/component_context.cxx @@ -359,8 +359,7 @@ Any ComponentContext::lookupMap( OUString const & rName ) pEntry->lateInit = false; return pEntry->value; } - else - ret = pEntry->value; + ret = pEntry->value; } guard.clear(); if (ret != xInstance) { @@ -377,8 +376,7 @@ Any ComponentContext::getValueByName( OUString const & rName ) { if (m_xDelegate.is()) return m_xDelegate->getValueByName( rName ); - else - return Any( Reference<XComponentContext>(this) ); + return Any( Reference<XComponentContext>(this) ); } Any ret( lookupMap( rName ) ); diff --git a/cppuhelper/source/factory.cxx b/cppuhelper/source/factory.cxx index 55b4f55b90d3..9ed9d0d6b320 100644 --- a/cppuhelper/source/factory.cxx +++ b/cppuhelper/source/factory.cxx @@ -139,7 +139,7 @@ Reference<XInterface > OSingleFactoryHelper::createInstanceEveryTime( { return (*m_fptr)( xContext ); } - else if( pCreateFunction ) + if( pCreateFunction ) { if (xContext.is()) { @@ -150,10 +150,7 @@ Reference<XInterface > OSingleFactoryHelper::createInstanceEveryTime( } return (*pCreateFunction)( xSMgr ); } - else - { - return Reference< XInterface >(); - } + return Reference< XInterface >(); } // XSingleServiceFactory @@ -510,8 +507,7 @@ Any SAL_CALL ORegistryFactoryHelper::queryInterface( Any ret( OFactoryComponentHelper::queryInterface( type ) ); if (ret.hasValue()) return ret; - else - return OPropertySetHelper::queryInterface( type ); + return OPropertySetHelper::queryInterface( type ); } @@ -624,7 +620,7 @@ Reference<XInterface > ORegistryFactoryHelper::createInstanceEveryTime( { return xModuleFactory->createInstanceWithContext( xContext ); } - else if( xModuleFactoryDepr.is() ) + if( xModuleFactoryDepr.is() ) { return xModuleFactoryDepr->createInstance(); } @@ -652,7 +648,7 @@ Reference<XInterface > SAL_CALL ORegistryFactoryHelper::createInstanceWithArgume { return xModuleFactoryDepr->createInstanceWithArguments( Arguments ); } - else if( xModuleFactory.is() ) + if( xModuleFactory.is() ) { SAL_INFO("cppuhelper", "no context ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!"); return xModuleFactory->createInstanceWithArgumentsAndContext( Arguments, Reference< XComponentContext >() ); @@ -682,7 +678,7 @@ Reference< XInterface > ORegistryFactoryHelper::createInstanceWithArgumentsAndCo { return xModuleFactory->createInstanceWithArgumentsAndContext( rArguments, xContext ); } - else if( xModuleFactoryDepr.is() ) + if( xModuleFactoryDepr.is() ) { SAL_INFO_IF(xContext.is(), "cppuhelper", "ignoring context calling ORegistryFactoryHelper::createInstaceWithArgumentsAndContext()!"); return xModuleFactoryDepr->createInstanceWithArguments( rArguments ); diff --git a/cppuhelper/source/implbase_ex.cxx b/cppuhelper/source/implbase_ex.cxx index 485e72957433..6025db018543 100644 --- a/cppuhelper/source/implbase_ex.cxx +++ b/cppuhelper/source/implbase_ex.cxx @@ -247,10 +247,7 @@ Any SAL_CALL ImplHelper_queryNoXInterface( { return Any( &p, pTDR ); } - else - { - return Any(); - } + return Any(); } css::uno::Sequence<sal_Int8> ImplHelper_getImplementationId( diff --git a/cppuhelper/source/interfacecontainer.cxx b/cppuhelper/source/interfacecontainer.cxx index 61989864e90c..2eb7197bf9e6 100644 --- a/cppuhelper/source/interfacecontainer.cxx +++ b/cppuhelper/source/interfacecontainer.cxx @@ -115,7 +115,7 @@ XInterface * OInterfaceIteratorHelper::next() if( bIsList ) // typecase to const,so the getArray method is faster return aData.pAsSequence->getConstArray()[nRemain].get(); - else if( aData.pAsInterface ) + if( aData.pAsInterface ) return aData.pAsInterface; } // exception @@ -159,7 +159,7 @@ sal_Int32 OInterfaceContainerHelper::getLength() const MutexGuard aGuard( rMutex ); if( bIsList ) return aData.pAsSequence->getLength(); - else if( aData.pAsInterface ) + if( aData.pAsInterface ) return 1; return 0; } @@ -169,7 +169,7 @@ Sequence< Reference<XInterface> > OInterfaceContainerHelper::getElements() const MutexGuard aGuard( rMutex ); if( bIsList ) return *aData.pAsSequence; - else if( aData.pAsInterface ) + if( aData.pAsInterface ) { Reference<XInterface> x( aData.pAsInterface ); return Sequence< Reference< XInterface > >( &x, 1 ); @@ -207,7 +207,7 @@ sal_Int32 OInterfaceContainerHelper::addInterface( const Reference<XInterface> & aData.pAsSequence->getArray()[ nLen ] = rListener; return nLen +1; } - else if( aData.pAsInterface ) + if( aData.pAsInterface ) { Sequence< Reference< XInterface > > * pSeq = new Sequence< Reference< XInterface > >( 2 ); Reference<XInterface> * pArray = pSeq->getArray(); @@ -218,13 +218,10 @@ sal_Int32 OInterfaceContainerHelper::addInterface( const Reference<XInterface> & bIsList = true; return 2; } - else - { - aData.pAsInterface = rListener.get(); - if( rListener.is() ) - rListener->acquire(); - return 1; - } + aData.pAsInterface = rListener.get(); + if( rListener.is() ) + rListener->acquire(); + return 1; } sal_Int32 OInterfaceContainerHelper::removeInterface( const Reference<XInterface> & rListener ) @@ -271,10 +268,9 @@ sal_Int32 OInterfaceContainerHelper::removeInterface( const Reference<XInterface bIsList = false; return 1; } - else - return aData.pAsSequence->getLength(); + return aData.pAsSequence->getLength(); } - else if( aData.pAsInterface && Reference<XInterface>( aData.pAsInterface ) == rListener ) + if( aData.pAsInterface && Reference<XInterface>( aData.pAsInterface ) == rListener ) { aData.pAsInterface->release(); aData.pAsInterface = nullptr; @@ -423,8 +419,7 @@ sal_Int32 OMultiTypeInterfaceContainerHelper::addInterface( pMap->push_back(std::pair<Type, void*>(rKey, pLC)); return pLC->addInterface( rListener ); } - else - return static_cast<OInterfaceContainerHelper*>((*iter).second)->addInterface( rListener ); + return static_cast<OInterfaceContainerHelper*>((*iter).second)->addInterface( rListener ); } sal_Int32 OMultiTypeInterfaceContainerHelper::removeInterface( @@ -595,8 +590,7 @@ sal_Int32 OMultiTypeInterfaceContainerHelperInt32::addInterface( pMap->push_back(std::pair< sal_Int32, void* >(rKey, pLC)); return pLC->addInterface( rListener ); } - else - return static_cast<OInterfaceContainerHelper*>((*iter).second)->addInterface( rListener ); + return static_cast<OInterfaceContainerHelper*>((*iter).second)->addInterface( rListener ); } sal_Int32 OMultiTypeInterfaceContainerHelperInt32::removeInterface( diff --git a/cppuhelper/source/propertysetmixin.cxx b/cppuhelper/source/propertysetmixin.cxx index 00769d590454..741afb427cf3 100644 --- a/cppuhelper/source/propertysetmixin.cxx +++ b/cppuhelper/source/propertysetmixin.cxx @@ -750,7 +750,8 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( object); } return strct; - } else if (wrapDefaulted + } + if (wrapDefaulted && type->getName().startsWith("com.sun.star.beans.Defaulted<")) { css::uno::Any strct; @@ -778,7 +779,8 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( object); } return strct; - } else if (wrapOptional + } + if (wrapOptional && type->getName().startsWith("com.sun.star.beans.Optional<")) { css::uno::Any strct; @@ -809,13 +811,12 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( object); } return strct; - } else { - if (wrapAmbiguous || wrapDefaulted || wrapOptional) { - throw css::uno::RuntimeException( - "unexpected type of attribute", object); - } - return value; } + if (wrapAmbiguous || wrapDefaulted || wrapOptional) { + throw css::uno::RuntimeException( + "unexpected type of attribute", object); + } + return value; } PropertySetMixinImpl::PropertySetMixinImpl( @@ -954,21 +955,22 @@ css::uno::Any PropertySetMixinImpl::queryInterface(css::uno::Type const & type) css::uno::Reference< css::uno::XInterface > ifc( static_cast< css::beans::XPropertySet * >(this)); return css::uno::Any(&ifc, type); - } else if ((m_impl->implements & IMPLEMENTS_FAST_PROPERTY_SET) != 0 + } + if ((m_impl->implements & IMPLEMENTS_FAST_PROPERTY_SET) != 0 && type == css::beans::XFastPropertySet::static_type()) { css::uno::Reference< css::uno::XInterface > ifc( static_cast< css::beans::XFastPropertySet * >(this)); return css::uno::Any(&ifc, type); - } else if ((m_impl->implements & IMPLEMENTS_PROPERTY_ACCESS) != 0 + } + if ((m_impl->implements & IMPLEMENTS_PROPERTY_ACCESS) != 0 && type == css::beans::XPropertyAccess::static_type()) { css::uno::Reference< css::uno::XInterface > ifc( static_cast< css::beans::XPropertyAccess * >(this)); return css::uno::Any(&ifc, type); - } else { - return css::uno::Any(); } + return css::uno::Any(); } css::uno::Reference< css::beans::XPropertySetInfo > diff --git a/cppuhelper/source/propshlp.cxx b/cppuhelper/source/propshlp.cxx index 5533e9857477..8cc395a847f9 100644 --- a/cppuhelper/source/propshlp.cxx +++ b/cppuhelper/source/propshlp.cxx @@ -220,8 +220,7 @@ Any OPropertySetHelper2::queryInterface( const css::uno::Type & rType ) Any cnd(cppu::queryInterface(rType, static_cast< XPropertySetOption * >(this))); if ( cnd.hasValue() ) return cnd; - else - return OPropertySetHelper::queryInterface(rType); + return OPropertySetHelper::queryInterface(rType); } /** @@ -1054,19 +1053,16 @@ sal_Bool OPropertyArrayHelper::fillPropertyMembersByHandle *pAttributes = pProperties[ nHandle ].Attributes; return true; } - else + // normally the array is sorted + for( sal_Int32 i = 0; i < nElements; i++ ) { - // normally the array is sorted - for( sal_Int32 i = 0; i < nElements; i++ ) + if( pProperties[i].Handle == nHandle ) { - if( pProperties[i].Handle == nHandle ) - { - if( pPropName ) - *pPropName = pProperties[ i ].Name; - if( pAttributes ) - *pAttributes = pProperties[ i ].Attributes; - return true; - } + if( pPropName ) + *pPropName = pProperties[ i ].Name; + if( pAttributes ) + *pAttributes = pProperties[ i ].Attributes; + return true; } } return false; diff --git a/cppuhelper/source/shlib.cxx b/cppuhelper/source/shlib.cxx index e3791ac12a00..e78071bb4774 100644 --- a/cppuhelper/source/shlib.cxx +++ b/cppuhelper/source/shlib.cxx @@ -127,37 +127,36 @@ css::uno::Reference<css::uno::XInterface> invokeComponentFactory( static_cast<css::uno::XInterface *>( (*function)(impl.getStr(), serviceManager.get(), nullptr)), SAL_NO_ACQUIRE); - } else { - css::uno::Mapping mapTo(source, target); - css::uno::Mapping mapFrom(target, source); - if (!(mapTo.is() && mapFrom.is())) { - throw css::loader::CannotActivateFactoryException( - "cannot get mappings", - css::uno::Reference<css::uno::XInterface>()); - } - void * smgr = mapTo.mapInterface( - serviceManager.get(), - cppu::UnoType<css::lang::XMultiServiceFactory>::get()); - void * factory = nullptr; - target.invoke(getFactory, function, &impl, smgr, &factory); - if (smgr != nullptr) { - (*target.get()->pExtEnv->releaseInterface)( - target.get()->pExtEnv, smgr); - } - if (factory == nullptr) { - throw css::loader::CannotActivateFactoryException( - ("calling factory function for \"" + implementation + "\" in <" - + uri + "> returned null"), - css::uno::Reference<css::uno::XInterface>()); - } - css::uno::Reference<css::uno::XInterface> res; - mapFrom.mapInterface( - reinterpret_cast<void **>(&res), factory, - cppu::UnoType<css::uno::XInterface>::get()); + } + css::uno::Mapping mapTo(source, target); + css::uno::Mapping mapFrom(target, source); + if (!(mapTo.is() && mapFrom.is())) { + throw css::loader::CannotActivateFactoryException( + "cannot get mappings", + css::uno::Reference<css::uno::XInterface>()); + } + void * smgr = mapTo.mapInterface( + serviceManager.get(), + cppu::UnoType<css::lang::XMultiServiceFactory>::get()); + void * factory = nullptr; + target.invoke(getFactory, function, &impl, smgr, &factory); + if (smgr != nullptr) { (*target.get()->pExtEnv->releaseInterface)( - target.get()->pExtEnv, factory); - return res; + target.get()->pExtEnv, smgr); + } + if (factory == nullptr) { + throw css::loader::CannotActivateFactoryException( + ("calling factory function for \"" + implementation + "\" in <" + + uri + "> returned null"), + css::uno::Reference<css::uno::XInterface>()); } + css::uno::Reference<css::uno::XInterface> res; + mapFrom.mapInterface( + reinterpret_cast<void **>(&res), factory, + cppu::UnoType<css::uno::XInterface>::get()); + (*target.get()->pExtEnv->releaseInterface)( + target.get()->pExtEnv, factory); + return res; } #if !defined DISABLE_DYNLOADING @@ -186,44 +185,43 @@ cppuhelper::WrapperConstructorFn mapConstructorFn( } if (source.get() == target.get()) { return cppuhelper::WrapperConstructorFn(constructorFunction); - } else { - // note: it should be valid to capture these mappings because they are - // ref-counted, and the returned closure will always be invoked in the - // "source" environment - css::uno::Mapping mapTo(source, target); - css::uno::Mapping mapFrom(target, source); - if (!(mapTo.is() && mapFrom.is())) { - throw css::loader::CannotActivateFactoryException( - "cannot get mappings", - css::uno::Reference<css::uno::XInterface>()); - } - return [mapFrom, mapTo, target, constructorFunction] - (css::uno::XComponentContext *const context, css::uno::Sequence<css::uno::Any> const& args) - { - void *const ctxt = mapTo.mapInterface( - context, - cppu::UnoType<css::uno::XComponentContext>::get()); - if (args.getLength() > 0) { - std::abort(); // TODO map args - } - void * instance = nullptr; - target.invoke(getInstance, constructorFunction, ctxt, &args, &instance); - if (ctxt != nullptr) { - (*target.get()->pExtEnv->releaseInterface)( - target.get()->pExtEnv, ctxt); - } - css::uno::XInterface * res = nullptr; - if (instance == nullptr) { - return res; - } - mapFrom.mapInterface( - reinterpret_cast<void **>(&res), instance, - cppu::UnoType<css::uno::XInterface>::get()); + } + // note: it should be valid to capture these mappings because they are + // ref-counted, and the returned closure will always be invoked in the + // "source" environment + css::uno::Mapping mapTo(source, target); + css::uno::Mapping mapFrom(target, source); + if (!(mapTo.is() && mapFrom.is())) { + throw css::loader::CannotActivateFactoryException( + "cannot get mappings", + css::uno::Reference<css::uno::XInterface>()); + } + return [mapFrom, mapTo, target, constructorFunction] + (css::uno::XComponentContext *const context, css::uno::Sequence<css::uno::Any> const& args) + { + void *const ctxt = mapTo.mapInterface( + context, + cppu::UnoType<css::uno::XComponentContext>::get()); + if (args.getLength() > 0) { + std::abort(); // TODO map args + } + void * instance = nullptr; + target.invoke(getInstance, constructorFunction, ctxt, &args, &instance); + if (ctxt != nullptr) { (*target.get()->pExtEnv->releaseInterface)( - target.get()->pExtEnv, instance); + target.get()->pExtEnv, ctxt); + } + css::uno::XInterface * res = nullptr; + if (instance == nullptr) { return res; - }; - } + } + mapFrom.mapInterface( + reinterpret_cast<void **>(&res), instance, + cppu::UnoType<css::uno::XInterface>::get()); + (*target.get()->pExtEnv->releaseInterface)( + target.get()->pExtEnv, instance); + return res; + }; } #endif |