add default value for Context param in uno::Exception constructors

and all it's subtypes, which is almost never used, so this allows us to
simplify lots of call sites.

Change-Id: I0b05793ea2bdd1027679f63252d42ce4af89433b
This commit is contained in:
Noel Grandin 2014-05-22 07:53:36 +02:00
parent 66fc6d223f
commit c5d47c327a
6 changed files with 44 additions and 39 deletions

View File

@ -257,7 +257,7 @@ DocObjectWrapper::invoke( const OUString& aFunctionName, const Sequence< Any >&
sal_Int32 nSbxCount = n - 1;
if ( nParamsCount < nSbxCount - nSbxOptional )
{
throw RuntimeException( "wrong number of parameters!", Reference< XInterface >() );
throw RuntimeException( "wrong number of parameters!" );
}
}
// set parameters

View File

@ -24,6 +24,7 @@
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include "boost/noncopyable.hpp"
#include "rtl/alloc.h"
@ -2680,7 +2681,8 @@ private:
virtual void dumpDeclaration(FileStream & out) SAL_OVERRIDE;
bool dumpBaseMembers(
FileStream & out, OUString const & base, bool withType);
FileStream & out, OUString const & base, bool withType,
bool withDefaults, bool parentsHadDirectMember);
sal_uInt32 getTotalMemberCount(OUString const & base) const;
@ -2730,7 +2732,7 @@ void ExceptionType::dumpHxxFile(
out << "}\n\n";
if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
out << indent() << "inline " << id_ << "::" << id_ << "(";
first = !dumpBaseMembers(out, base, true);
first = !dumpBaseMembers(out, base, true, false, false);
for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(entity_->getDirectMembers().begin());
i != entity_->getDirectMembers().end(); ++i)
@ -2748,7 +2750,7 @@ void ExceptionType::dumpHxxFile(
if (!base.isEmpty()) {
out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
<< "(";
dumpBaseMembers(out, base, false);
dumpBaseMembers(out, base, false, false, false);
out << ")\n";
first = false;
}
@ -2984,7 +2986,9 @@ void ExceptionType::dumpDeclaration(FileStream & out) {
<< "() SAL_THROW(());\n\n";
if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(";
bool first = !dumpBaseMembers(out, base, true);
bool withDefaults = true;
bool parentsHadDirectMembers = !entity_->getDirectMembers().empty();
bool first = !dumpBaseMembers(out, base, true, withDefaults, parentsHadDirectMembers);
for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(entity_->getDirectMembers().begin());
i != entity_->getDirectMembers().end(); ++i)
@ -3023,7 +3027,7 @@ void ExceptionType::dumpDeclaration(FileStream & out) {
}
bool ExceptionType::dumpBaseMembers(
FileStream & out, OUString const & base, bool withType)
FileStream & out, OUString const & base, bool withType, bool withDefaults, bool parentsHadDirectMember)
{
bool hasMember = false;
if (!base.isEmpty()) {
@ -3036,10 +3040,12 @@ bool ExceptionType::dumpBaseMembers(
rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
assert(ent2.is());
hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType);
hasMember = dumpBaseMembers( out, ent2->getDirectBase(), withType,
withDefaults, parentsHadDirectMember || !ent2->getDirectMembers().empty() );
int memberCount = 0;
for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(ent2->getDirectMembers().begin());
i != ent2->getDirectMembers().end(); ++i)
i != ent2->getDirectMembers().end(); ++i, ++memberCount)
{
if (hasMember) {
out << ", ";
@ -3049,6 +3055,17 @@ bool ExceptionType::dumpBaseMembers(
out << " ";
}
out << i->name << "_";
// We want to provide a default parameter value for uno::Exception subtype
// constructors, since most of the time we don't pass a Context object in to the exception
// throw sites.
if (withDefaults
&& !parentsHadDirectMember
&& base == "com.sun.star.uno.Exception"
&& memberCount == 1
&& i->name == "Context"
&& i->type == "com.sun.star.uno.XInterface") {
out << " = ::css::uno::Reference< ::css::uno::XInterface >()";
}
hasMember = true;
}
}

View File

@ -53,7 +53,7 @@ static inline void checkInterface( Type const & rType )
{
OUString msg( "querying for interface \"" + rType.getTypeName() + "\": no interface type!" );
SAL_WARN( "cppuhelper", msg );
throw RuntimeException( msg, Reference< XInterface >() );
throw RuntimeException( msg );
}
}
@ -96,7 +96,7 @@ static inline type_entry * __getTypeEntries( class_data * cd )
{
OUString msg( "type \"" + rType.getTypeName() + "\" is no interface type!" );
SAL_WARN( "cppuhelper", msg );
throw RuntimeException( msg, Reference< XInterface >() );
throw RuntimeException( msg );
}
// ref is statically held by getCppuType()
pEntry->m_type.typeRef = rType.getTypeLibType();
@ -202,7 +202,7 @@ static inline void * __queryDeepNoXInterface(
{
OUString msg( "cannot get type description for type \"" + OUString(pEntries[ n ].m_type.typeRef->pTypeName) + "\"!" );
SAL_WARN( "cppuhelper", msg );
throw RuntimeException( msg, Reference< XInterface >() );
throw RuntimeException( msg );
}
}
return 0;

View File

@ -105,9 +105,7 @@ static bool readOption( OUString * pValue, const sal_Char * pOpt,
rtl_getAppCommandArg(*pnIndex, &pValue->pData);
if (*pnIndex >= rtl_getAppCommandArgCount() || pValue->copy(1).equals(dash))
{
throw RuntimeException(
"incomplete option \"-" + aOpt + "\" given!",
Reference< XInterface >() );
throw RuntimeException( "incomplete option \"-" + aOpt + "\" given!" );
}
else
{
@ -170,9 +168,7 @@ void createInstance(
if (! x.is())
{
throw RuntimeException(
"cannot get service instance \"" + rServiceName + "\"!",
Reference< XInterface >() );
throw RuntimeException( "cannot get service instance \"" + rServiceName + "\"!" );
}
rxOut = Reference< T >::query( x );
@ -182,8 +178,7 @@ void createInstance(
throw RuntimeException(
"service instance \"" + rServiceName +
"\" does not support demanded interface \"" +
rType.getTypeName() + "\"!",
Reference< XInterface >() );
rType.getTypeName() + "\"!" );
}
}
@ -217,8 +212,7 @@ static Reference< XInterface > loadComponent(
else
{
throw RuntimeException(
"unknown extension of \"" + rLocation + "\"! No loader available!",
Reference< XInterface >() );
"unknown extension of \"" + rLocation + "\"! No loader available!" );
}
Reference< XInterface > xInstance;
@ -249,8 +243,7 @@ static Reference< XInterface > loadComponent(
if (! xInstance.is())
{
throw RuntimeException(
"activating component \"" + rImplName + "\" from location \"" + rLocation + "\" failed!",
Reference< XInterface >() );
"activating component \"" + rImplName + "\" from location \"" + rLocation + "\" failed!" );
}
return xInstance;
@ -258,8 +251,7 @@ static Reference< XInterface > loadComponent(
else
{
throw RuntimeException(
"location \"" + rLocation + "\" has no extension! Cannot determine loader to be used!",
Reference< XInterface >() );
"location \"" + rLocation + "\" has no extension! Cannot determine loader to be used!" );
}
}
@ -357,8 +349,7 @@ Reference< XInterface > OInstanceProvider::getInstance( const OUString & rName )
out( rExc.Message );
}
throw NoSuchElementException(
"no such element \"" + rName + "\"!",
Reference< XInterface >() );
"no such element \"" + rName + "\"!" );
}
struct ODisposingListener : public WeakImplHelper1< XEventListener >
@ -437,8 +428,7 @@ SAL_IMPLEMENT_MAIN()
readOption( &bSingleInstance, "singleinstance", &nPos, arg)))
{
throw RuntimeException(
"unexpected argument \"" + arg + "\"",
Reference< XInterface >() );
"unexpected argument \"" + arg + "\"" );
}
}
@ -448,15 +438,13 @@ SAL_IMPLEMENT_MAIN()
{
if (! aUnoUrl.endsWithIgnoreAsciiCase( ";uno.ComponentContext" ))
throw RuntimeException(
OUString("expected UNO-URL with instance name uno.ComponentContext!" ),
Reference<XInterface>() );
OUString("expected UNO-URL with instance name uno.ComponentContext!" ) );
if (bSingleInstance)
throw RuntimeException(
OUString("unexpected option --singleinstance!"),
Reference<XInterface>() );
OUString("unexpected option --singleinstance!") );
}
if (!aImplName.isEmpty() && aLocation.isEmpty())
throw RuntimeException("give component location!", Reference< XInterface >() );
throw RuntimeException("give component location!" );
if (!aServiceName.isEmpty() && !aLocation.isEmpty())
out( "\n> warning: service name given, will ignore location!" );
@ -481,7 +469,7 @@ SAL_IMPLEMENT_MAIN()
if (nTokens != 3 || aUnoUrl.getLength() < 10 ||
!aUnoUrl.copy( 0, 4 ).equalsIgnoreAsciiCase( "uno:" ))
{
throw RuntimeException("illegal uno url given!", Reference< XInterface >() );
throw RuntimeException("illegal uno url given!" );
}
nIndex = 0;
OUString aConnectDescr( aUnoUrl.getToken( 0, ';', nIndex ).copy( 4 ) ); // uno:CONNECTDESCR;iiop;InstanceName
@ -528,7 +516,7 @@ SAL_IMPLEMENT_MAIN()
{
Reference< XComponent > xComp( xBridge, UNO_QUERY );
if (! xComp.is())
throw RuntimeException( OUString( "bridge factory does not export interface \"com.sun.star.lang.XComponent\"!" ), Reference< XInterface >() );
throw RuntimeException( OUString( "bridge factory does not export interface \"com.sun.star.lang.XComponent\"!" ) );
ODisposingListener::waitFor( xComp );
xComp->dispose();
// explicitly dispose the remote bridge so that it joins
@ -557,7 +545,7 @@ SAL_IMPLEMENT_MAIN()
Reference< XComponent > xComp( xInstance, UNO_QUERY );
if (xComp.is())
xComp->dispose();
throw RuntimeException( OUString( "component does not export interface interface \"com.sun.star.lang.XMain\"!" ), Reference< XInterface >() );
throw RuntimeException( OUString( "component does not export interface interface \"com.sun.star.lang.XMain\"!" ) );
}
}
}

View File

@ -761,7 +761,7 @@ Image SfxConfigGroupListBox::GetImage(
Any aAny = xModuleManager->getByName(appModule);
if( !( aAny >>= moduleDescr ) )
{
throw RuntimeException("SFTreeListBox::Init: failed to get PropertyValue", Reference< XInterface >());
throw RuntimeException("SFTreeListBox::Init: failed to get PropertyValue");
}
beans::PropertyValue const * pmoduleDescr =
moduleDescr.getConstArray();

View File

@ -558,7 +558,7 @@ Image SvxConfigGroupListBox::GetImage(
Any aAny = xModuleManager->getByName(appModule);
if( !( aAny >>= moduleDescr ) )
{
throw RuntimeException("SFTreeListBox::Init: failed to get PropertyValue", Reference< XInterface >());
throw RuntimeException("SFTreeListBox::Init: failed to get PropertyValue");
}
beans::PropertyValue const * pmoduleDescr =
moduleDescr.getConstArray();