Kaydet (Commit) f97d7946 authored tarafından Gergo Mocsi's avatar Gergo Mocsi

GSOC work week 0-1, allowing BASIC to recognize UNO interfaces

Introduced a new function calles IsUnoInterface in SbiParser to determine, if
a variable is a type of an UNO interface. It uses reflection.CoreReflection to
do that, on success it returs true otherwise false.

Change-Id: I18895127bcbd92dc7a25feb5d82a7d1343bde851
üst 49656398
...@@ -20,7 +20,17 @@ ...@@ -20,7 +20,17 @@
#include <basic/sbx.hxx> #include <basic/sbx.hxx>
#include "sbcomp.hxx" #include "sbcomp.hxx"
#include "sbunoobj.hxx" #include "sbunoobj.hxx"
#include <svtools/miscopt.hxx>
#include "com/sun/star/reflection/XIdlReflection.hpp"
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/configurationhelper.hxx>
#include "com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp"
#include "com/sun/star/reflection/XIdlMethod.hpp"
#include "com/sun/star/uno/Exception.hpp"
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj ); SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj );
...@@ -197,6 +207,7 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic ) ...@@ -197,6 +207,7 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
bool bSwitchPool = false; bool bSwitchPool = false;
bool bPersistantGlobal = false; bool bPersistantGlobal = false;
SbiToken eFirstTok = eCurTok; SbiToken eFirstTok = eCurTok;
SvtMiscOptions aMiscOptions;
if( pProc && ( eCurTok == GLOBAL || eCurTok == PUBLIC || eCurTok == PRIVATE ) ) if( pProc && ( eCurTok == GLOBAL || eCurTok == PUBLIC || eCurTok == PRIVATE ) )
Error( SbERR_NOT_IN_SUBR, eCurTok ); Error( SbERR_NOT_IN_SUBR, eCurTok );
if( eCurTok == PUBLIC || eCurTok == GLOBAL ) if( eCurTok == PUBLIC || eCurTok == GLOBAL )
...@@ -391,7 +402,7 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic ) ...@@ -391,7 +402,7 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
if( !bCompatible && !pDef->IsNew() ) if( !bCompatible && !pDef->IsNew() )
{ {
OUString aTypeName( aGblStrings.Find( pDef->GetTypeId() ) ); OUString aTypeName( aGblStrings.Find( pDef->GetTypeId() ) );
if( rTypeArray->Find( aTypeName, SbxCLASS_OBJECT ) == NULL ) if( rTypeArray->Find( aTypeName, SbxCLASS_OBJECT ) == NULL && (aMiscOptions.IsExperimentalMode() && !IsUnoInterface(aTypeName)))
{ {
Error( SbERR_UNDEF_TYPE, aTypeName ); Error( SbERR_UNDEF_TYPE, aTypeName );
} }
...@@ -1311,4 +1322,29 @@ void SbiParser::DefStatic( bool bPrivate ) ...@@ -1311,4 +1322,29 @@ void SbiParser::DefStatic( bool bPrivate )
} }
} }
bool SbiParser::IsUnoInterface(const OUString& sTypeName)
{
try
{
Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW );
Reference< reflection::XIdlReflection > xRefl( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW );
//DBG_ASSERT(xRefl.Is(), "No reflection class!"); ???
if( !xRefl.is() )
{
return false;
}
Reference< reflection::XIdlClass > xClass = xRefl->forName(sTypeName);
if( xClass != NULL )
{
return true;
}
return false;
}
catch(const Exception& ex)
{
OSL_FAIL("Could not create reflection.CoreReflection.");
}
return false;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -57,6 +57,7 @@ class SbiParser : public SbiTokenizer ...@@ -57,6 +57,7 @@ class SbiParser : public SbiTokenizer
void DefEnum( bool bPrivate ); // Parse enum declaration void DefEnum( bool bPrivate ); // Parse enum declaration
void DefDeclare( bool bPrivate ); void DefDeclare( bool bPrivate );
void EnableCompatibility(); void EnableCompatibility();
bool IsUnoInterface(const OUString& sTypeName);
public: public:
SbxArrayRef rTypeArray; SbxArrayRef rTypeArray;
SbxArrayRef rEnumArray; SbxArrayRef rEnumArray;
......
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