Kaydet (Commit) 9c6a58f8 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Clean up uses of Any::getValue() in basic

Change-Id: Ice269eae6b0278d5e089d973aae72b3f871c1272
üst 53055f2e
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <comphelper/propertysetinfo.hxx> #include <comphelper/propertysetinfo.hxx>
#include <comphelper/sequence.hxx> #include <comphelper/sequence.hxx>
#include <o3tl/any.hxx>
#include <algorithm> #include <algorithm>
#include <limits.h> #include <limits.h>
...@@ -201,14 +202,13 @@ void RTL_Impl_CreatePropertySet( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ...@@ -201,14 +202,13 @@ void RTL_Impl_CreatePropertySet( StarBASIC* pBasic, SbxArray& rPar, bool bWrite
// Set PropertyValues // Set PropertyValues
Any aArgAsAny = sbxToUnoValue( rPar.Get(1), Any aArgAsAny = sbxToUnoValue( rPar.Get(1),
cppu::UnoType<Sequence<PropertyValue>>::get() ); cppu::UnoType<Sequence<PropertyValue>>::get() );
Sequence<PropertyValue> const *pArg = auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
static_cast<Sequence<PropertyValue> const *>(aArgAsAny.getValue());
Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY ); Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
xPropAcc->setPropertyValues( *pArg ); xPropAcc->setPropertyValues( *pArg );
// Build a SbUnoObject and return it // Build a SbUnoObject and return it
auto xUnoObj = tools::make_ref<SbUnoObject>( "stardiv.uno.beans.PropertySet", Any(xInterface) ); auto xUnoObj = tools::make_ref<SbUnoObject>( "stardiv.uno.beans.PropertySet", Any(xInterface) );
if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID ) if( xUnoObj->getUnoAny().hasValue() )
{ {
// Return object // Return object
refVar->PutObject( xUnoObj.get() ); refVar->PutObject( xUnoObj.get() );
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <sal/config.h>
#include <o3tl/any.hxx>
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <tools/errcode.hxx> #include <tools/errcode.hxx>
...@@ -312,12 +315,13 @@ OUString implGetExceptionMsg( const Exception& e, const OUString& aExceptionType ...@@ -312,12 +315,13 @@ OUString implGetExceptionMsg( const Exception& e, const OUString& aExceptionType
OUString implGetExceptionMsg( const Any& _rCaughtException ) OUString implGetExceptionMsg( const Any& _rCaughtException )
{ {
OSL_PRECOND( _rCaughtException.getValueTypeClass() == TypeClass_EXCEPTION, "implGetExceptionMsg: illegal argument!" ); auto e = o3tl::tryAccess<Exception>(_rCaughtException);
if ( _rCaughtException.getValueTypeClass() != TypeClass_EXCEPTION ) OSL_PRECOND( e, "implGetExceptionMsg: illegal argument!" );
if ( !e )
{ {
return OUString(); return OUString();
} }
return implGetExceptionMsg( *static_cast< const Exception* >( _rCaughtException.getValue() ), _rCaughtException.getValueTypeName() ); return implGetExceptionMsg( *e, _rCaughtException.getValueTypeName() );
} }
Any convertAny( const Any& rVal, const Type& aDestType ) Any convertAny( const Any& rVal, const Type& aDestType )
...@@ -406,10 +410,10 @@ void implHandleWrappedTargetException( const Any& _rWrappedTargetException ) ...@@ -406,10 +410,10 @@ void implHandleWrappedTargetException( const Any& _rWrappedTargetException )
++nLevel; ++nLevel;
} }
if ( aExamine.getValueTypeClass() == TypeClass_EXCEPTION ) if ( auto e = o3tl::tryAccess<Exception>(aExamine) )
{ {
// the last element in the chain is still an exception, but no WrappedTargetException // the last element in the chain is still an exception, but no WrappedTargetException
implAppendExceptionMsg( aMessageBuf, *static_cast< const Exception* >( aExamine.getValue() ), aExamine.getValueTypeName(), nLevel ); implAppendExceptionMsg( aMessageBuf, *e, aExamine.getValueTypeName(), nLevel );
} }
StarBASIC::Error( nError, aMessageBuf.makeStringAndClear() ); StarBASIC::Error( nError, aMessageBuf.makeStringAndClear() );
...@@ -622,7 +626,7 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue ) ...@@ -622,7 +626,7 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue )
SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject); SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject);
// If the object is invalid deliver null // If the object is invalid deliver null
if( pSbUnoObject->getUnoAny().getValueType().getTypeClass() == TypeClass_VOID ) if( !pSbUnoObject->getUnoAny().hasValue() )
{ {
pVar->PutObject( nullptr ); pVar->PutObject( nullptr );
} }
...@@ -723,7 +727,7 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue ) ...@@ -723,7 +727,7 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue )
SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject); SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject);
// If the object is invalid deliver null // If the object is invalid deliver null
if( pSbUnoObject->getUnoAny().getValueType().getTypeClass() == TypeClass_VOID ) if( !pSbUnoObject->getUnoAny().hasValue() )
{ {
pVar->PutObject( nullptr ); pVar->PutObject( nullptr );
} }
...@@ -790,10 +794,10 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue ) ...@@ -790,10 +794,10 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue )
break; break;
case TypeClass_BOOLEAN: pVar->PutBool( *static_cast<sal_Bool const *>(aValue.getValue()) ); break; case TypeClass_BOOLEAN: pVar->PutBool( *o3tl::forceAccess<bool>(aValue) ); break;
case TypeClass_CHAR: case TypeClass_CHAR:
{ {
pVar->PutChar( *static_cast<sal_Unicode const *>(aValue.getValue()) ); pVar->PutChar( *o3tl::forceAccess<sal_Unicode>(aValue) );
break; break;
} }
case TypeClass_STRING: { OUString val; aValue >>= val; pVar->PutString( val ); } break; case TypeClass_STRING: { OUString val; aValue >>= val; pVar->PutString( val ); } break;
...@@ -1596,10 +1600,7 @@ OUString getDbgObjectNameImpl(SbUnoObject& rUnoObj) ...@@ -1596,10 +1600,7 @@ OUString getDbgObjectNameImpl(SbUnoObject& rUnoObj)
if( aName.isEmpty() ) if( aName.isEmpty() )
{ {
Any aToInspectObj = rUnoObj.getUnoAny(); Any aToInspectObj = rUnoObj.getUnoAny();
TypeClass eType = aToInspectObj.getValueType().getTypeClass(); Reference< XInterface > xObj(aToInspectObj, css::uno::UNO_QUERY);
Reference< XInterface > xObj;
if( eType == TypeClass_INTERFACE )
xObj = *static_cast<Reference< XInterface > const *>(aToInspectObj.getValue());
if( xObj.is() ) if( xObj.is() )
{ {
Reference< XServiceInfo > xServiceInfo( xObj, UNO_QUERY ); Reference< XServiceInfo > xServiceInfo( xObj, UNO_QUERY );
...@@ -1646,21 +1647,15 @@ OUString getBasicObjectTypeName( SbxObject* pObj ) ...@@ -1646,21 +1647,15 @@ OUString getBasicObjectTypeName( SbxObject* pObj )
bool checkUnoObjectType(SbUnoObject& rUnoObj, const OUString& rClass) bool checkUnoObjectType(SbUnoObject& rUnoObj, const OUString& rClass)
{ {
Any aToInspectObj = rUnoObj.getUnoAny(); Any aToInspectObj = rUnoObj.getUnoAny();
TypeClass eType = aToInspectObj.getValueType().getTypeClass();
if( eType != TypeClass_INTERFACE )
{
return false;
}
const Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aToInspectObj.getValue());
// Return true for XInvocation based objects as interface type names don't count then // Return true for XInvocation based objects as interface type names don't count then
Reference< XInvocation > xInvocation( x, UNO_QUERY ); Reference< XInvocation > xInvocation( aToInspectObj, UNO_QUERY );
if( xInvocation.is() ) if( xInvocation.is() )
{ {
return true; return true;
} }
bool bResult = false; bool bResult = false;
Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY ); Reference< XTypeProvider > xTypeProvider( aToInspectObj, UNO_QUERY );
if( xTypeProvider.is() ) if( xTypeProvider.is() )
{ {
/* Although interfaces in the ooo.vba namespace obey the IDL rules and /* Although interfaces in the ooo.vba namespace obey the IDL rules and
...@@ -1744,19 +1739,16 @@ OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj) ...@@ -1744,19 +1739,16 @@ OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj)
Any aToInspectObj = rUnoObj.getUnoAny(); Any aToInspectObj = rUnoObj.getUnoAny();
// allow only TypeClass interface // allow only TypeClass interface
TypeClass eType = aToInspectObj.getValueType().getTypeClass();
OUStringBuffer aRet; OUStringBuffer aRet;
if( eType != TypeClass_INTERFACE ) auto x = o3tl::tryAccess<Reference<XInterface>>(aToInspectObj);
if( !x )
{ {
aRet.append( ID_DBG_SUPPORTEDINTERFACES ); aRet.append( ID_DBG_SUPPORTEDINTERFACES );
aRet.append( " not available.\n(TypeClass is not TypeClass_INTERFACE)\n" ); aRet.append( " not available.\n(TypeClass is not TypeClass_INTERFACE)\n" );
} }
else else
{ {
// get the interface from the Any Reference< XTypeProvider > xTypeProvider( *x, UNO_QUERY );
const Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aToInspectObj.getValue());
Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY );
aRet.append( "Supported interfaces by object " ); aRet.append( "Supported interfaces by object " );
aRet.append(getDbgObjectName(rUnoObj)); aRet.append(getDbgObjectName(rUnoObj));
...@@ -1774,7 +1766,7 @@ OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj) ...@@ -1774,7 +1766,7 @@ OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj)
Reference<XIdlClass> xClass = TypeToIdlClass( rType ); Reference<XIdlClass> xClass = TypeToIdlClass( rType );
if( xClass.is() ) if( xClass.is() )
{ {
aRet.append( Impl_GetInterfaceInfo( x, xClass, 1 ) ); aRet.append( Impl_GetInterfaceInfo( *x, xClass, 1 ) );
} }
else else
{ {
...@@ -2321,7 +2313,7 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ ) ...@@ -2321,7 +2313,7 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ )
if( eType == TypeClass_INTERFACE ) if( eType == TypeClass_INTERFACE )
{ {
// get the interface from the Any // get the interface from the Any
x = *static_cast<Reference< XInterface > const *>(aUnoObj_.getValue()); aUnoObj_ >>= x;
if( !x.is() ) if( !x.is() )
return; return;
} }
...@@ -2990,7 +2982,7 @@ void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) ...@@ -2990,7 +2982,7 @@ void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, bool bWrite )
{ {
// Create a SbUnoObject out of it and return it // Create a SbUnoObject out of it and return it
SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, Any(xInterface) ); SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, Any(xInterface) );
if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID ) if( xUnoObj->getUnoAny().hasValue() )
{ {
// return the object // return the object
refVar->PutObject( static_cast<SbUnoObject*>(xUnoObj) ); refVar->PutObject( static_cast<SbUnoObject*>(xUnoObj) );
...@@ -3042,7 +3034,7 @@ void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar, ...@@ -3042,7 +3034,7 @@ void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar,
{ {
// Create a SbUnoObject out of it and return it // Create a SbUnoObject out of it and return it
SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, Any(xInterface) ); SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, Any(xInterface) );
if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID ) if( xUnoObj->getUnoAny().hasValue() )
{ {
// return the object // return the object
refVar->PutObject( static_cast<SbUnoObject*>(xUnoObj) ); refVar->PutObject( static_cast<SbUnoObject*>(xUnoObj) );
...@@ -3097,13 +3089,11 @@ void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) ...@@ -3097,13 +3089,11 @@ void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite )
return; return;
} }
Any aAny = static_cast<SbUnoObject*>(static_cast<SbxBase*>(pObj))->getUnoAny(); Any aAny = static_cast<SbUnoObject*>(static_cast<SbxBase*>(pObj))->getUnoAny();
TypeClass eType = aAny.getValueType().getTypeClass(); auto x = o3tl::tryAccess<Reference<XInterface>>(aAny);
if( eType != TypeClass_INTERFACE ) if( !x )
{ {
return; return;
} }
// get the interface out of the Any
Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aAny.getValue());
// get CoreReflection // get CoreReflection
Reference< XIdlReflection > xCoreReflection = getCoreReflection_Impl(); Reference< XIdlReflection > xCoreReflection = getCoreReflection_Impl();
...@@ -3125,7 +3115,7 @@ void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) ...@@ -3125,7 +3115,7 @@ void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite )
// check if the interface will be supported // check if the interface will be supported
OUString aClassName = xClass->getName(); OUString aClassName = xClass->getName();
Type aClassType( xClass->getTypeClass(), aClassName.getStr() ); Type aClassType( xClass->getTypeClass(), aClassName.getStr() );
if( !x->queryInterface( aClassType ).hasValue() ) if( !(*x)->queryInterface( aClassType ).hasValue() )
{ {
return; return;
} }
...@@ -3426,8 +3416,7 @@ SbxVariable* SbUnoClass::Find( const OUString& rName, SbxClassType ) ...@@ -3426,8 +3416,7 @@ SbxVariable* SbUnoClass::Find( const OUString& rName, SbxClassType )
// Interface located? Then it is a class // Interface located? Then it is a class
if( eType == TypeClass_INTERFACE ) if( eType == TypeClass_INTERFACE )
{ {
Reference< XInterface > xIface = *static_cast<Reference< XInterface > const *>(aValue.getValue()); Reference< XIdlClass > xClass( aValue, UNO_QUERY );
Reference< XIdlClass > xClass( xIface, UNO_QUERY );
if( xClass.is() ) if( xClass.is() )
{ {
pRes = new SbxVariable( SbxVARIANT ); pRes = new SbxVariable( SbxVARIANT );
......
...@@ -3691,8 +3691,7 @@ void SbiRuntime::SetupArgs( SbxVariable* p, sal_uInt32 nOp1 ) ...@@ -3691,8 +3691,7 @@ void SbiRuntime::SetupArgs( SbxVariable* p, sal_uInt32 nOp1 )
if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE ) if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
{ {
Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aAny.getValue()); Reference< XDefaultMethod > xDfltMethod( aAny, UNO_QUERY );
Reference< XDefaultMethod > xDfltMethod( x, UNO_QUERY );
OUString sDefaultMethod; OUString sDefaultMethod;
if ( xDfltMethod.is() ) if ( xDfltMethod.is() )
...@@ -3820,8 +3819,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) ...@@ -3820,8 +3819,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE ) if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
{ {
Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aAny.getValue()); Reference< XIndexAccess > xIndexAccess( aAny, UNO_QUERY );
Reference< XIndexAccess > xIndexAccess( x, UNO_QUERY );
if ( !bVBAEnabled ) if ( !bVBAEnabled )
{ {
if( xIndexAccess.is() ) if( xIndexAccess.is() )
...@@ -3839,11 +3837,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) ...@@ -3839,11 +3837,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
try try
{ {
Any aAny2 = xIndexAccess->getByIndex( nIndex ); Any aAny2 = xIndexAccess->getByIndex( nIndex );
TypeClass eType = aAny2.getValueType().getTypeClass(); aAny2 >>= xRet;
if( eType == TypeClass_INTERFACE )
{
xRet = *static_cast<Reference< XInterface > const *>(aAny2.getValue());
}
} }
catch (const IndexOutOfBoundsException&) catch (const IndexOutOfBoundsException&)
{ {
...@@ -3877,6 +3871,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) ...@@ -3877,6 +3871,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
// " // "
// val = rst1("FirstName") // val = rst1("FirstName")
// has the default 'Fields' member between rst1 and '("FirstName")' // has the default 'Fields' member between rst1 and '("FirstName")'
Any x = aAny;
SbxVariable* pDflt = getDefaultProp( pElem ); SbxVariable* pDflt = getDefaultProp( pElem );
if ( pDflt ) if ( pDflt )
{ {
...@@ -3890,7 +3885,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) ...@@ -3890,7 +3885,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
Any aUnoAny = pUnoObj->getUnoAny(); Any aUnoAny = pUnoObj->getUnoAny();
if( aUnoAny.getValueType().getTypeClass() == TypeClass_INTERFACE ) if( aUnoAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
x = *static_cast<Reference< XInterface > const *>(aUnoAny.getValue()); x = aUnoAny;
pElem = pDflt; pElem = pDflt;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment