diff options
author | Gergo Mocsi <gmocsi91@gmail.com> | 2013-09-19 16:18:10 +0200 |
---|---|---|
committer | Gergo Mocsi <gmocsi91@gmail.com> | 2013-09-19 16:18:10 +0200 |
commit | 59bbf4b37f8572c3fa65bedbc4013fc0ef844c42 (patch) | |
tree | bbe9611b568fbb6fff08e1415aa4ac514da38200 | |
parent | 9dfcb24d5ec5d38d2362297d62dec46ae02d2359 (diff) |
GSOC work, enable interface name usage instead of it's full namefeature/gsoc-basic-ide-completion-and-other-bits
From now, interfaces/structs/enums can be used as types in BASIC IDE.
This example illustrates the feature the best:
dim aPicker as star.ui.dialogs.XFilePicker
dim aPicker2 as sun.star.ui.dialogs.XFilePicker
dim aPicker3 as com.sun.star.ui.dialogs.XFilePicker
dim aPicker4 as css.ui.dialogs.XFilePicker
dim aPicker5 as ui.dialogs.XFilePicker
dim aPicker6 as XFilePicker
Any of the definitions above are accepted (css is shorthand for com.sun.star).
Change-Id: I1ac2196f21ba0950d2932ef5bc11a1d5d2346b4c
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 1 | ||||
-rw-r--r-- | basic/source/classes/codecompletecache.cxx | 83 | ||||
-rw-r--r-- | basic/source/classes/sbxmod.cxx | 8 | ||||
-rw-r--r-- | basic/source/comp/dim.cxx | 31 | ||||
-rw-r--r-- | include/basic/codecompletecache.hxx | 2 |
5 files changed, 88 insertions, 37 deletions
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 5d713ec625f5..1dffce374d60 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -833,6 +833,7 @@ void EditorWindow::HandleCodeCompletition() return; OUString sBaseName = aVect[0];//variable name OUString sVarType = aCodeCompleteCache.GetVarType( sBaseName ); + if( !sVarType.isEmpty() && CodeCompleteOptions::IsAutoCorrectOn() ) {//correct variable name, if autocorrection on const OUString& sStr = aCodeCompleteCache.GetCorrectCaseVarName( sBaseName, GetActualSubName(nLine) ); diff --git a/basic/source/classes/codecompletecache.cxx b/basic/source/classes/codecompletecache.cxx index 71de600c0af0..ee5bd08d703e 100644 --- a/basic/source/classes/codecompletecache.cxx +++ b/basic/source/classes/codecompletecache.cxx @@ -21,6 +21,22 @@ #include <iostream> #include <rtl/instance.hxx> #include <officecfg/Office/BasicIDE.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/reflection/XTypeDescriptionEnumerationAccess.hpp" +#include "com/sun/star/reflection/XTypeDescription.hpp" +#include "com/sun/star/reflection/TypeDescriptionSearchDepth.hpp" +#include "com/sun/star/uno/Exception.hpp" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/uno/TypeClass.hpp" +#include "com/sun/star/container/XHierarchicalNameAccess.hpp" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; namespace { @@ -97,21 +113,70 @@ void CodeCompleteOptions::SetAutoCorrectOn( const bool& b ) theCodeCompleteOptions::get().bIsAutoCorrectOn = b; } -OUString CodeCompleteOptions::AddUnoPrefix( const OUString& sTypeName ) +OUString CodeCompleteOptions::GetUnoType( const OUString& sTypeName ) { + //returns the fully qualified UNO type name if exsists, else empty string OUString sNewTypeName = sTypeName; if( sNewTypeName.toAsciiLowerCase().startsWith("css.") ) - {//enables shorthand "css" instead of "com.sun.star" - sNewTypeName = sNewTypeName.replaceFirst("css","com.sun.star"); - } - else + //enables shorthand "css" instead of "com.sun.star" + sNewTypeName = sNewTypeName.replaceFirst("css.",""); + //if "com.sun.star" or any of it left out, add it + else if( sNewTypeName.toAsciiLowerCase().startsWith("com.sun.star.") ) + sNewTypeName = sNewTypeName.replaceFirst("com.sun.star.",""); + + else if( sNewTypeName.toAsciiLowerCase().startsWith("sun.star.") ) + sNewTypeName = sNewTypeName.replaceFirst("sun.star.",""); + + else if( sNewTypeName.toAsciiLowerCase().startsWith("star.") ) + sNewTypeName = sNewTypeName.replaceFirst("star.",""); + + try { - if( !sNewTypeName.toAsciiLowerCase().startsWith("com.sun.star.") ) - {//if "com.sun.star" left out, add it - sNewTypeName = OUString("com.sun.star.") + sTypeName; + Reference< container::XHierarchicalNameAccess > xAccess; + Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() ); + if( xContext.is() ) + { + xContext->getValueByName( + OUString( "/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) ) + >>= xAccess; + OSL_ENSURE( xAccess.is(), "### TypeDescriptionManager singleton not accessible!?" ); } + if( xAccess.is() ) + { + uno::Sequence< uno::TypeClass > aParams(3); + aParams[0] = uno::TypeClass_INTERFACE; + aParams[1] = uno::TypeClass_STRUCT; + aParams[2] = uno::TypeClass_ENUM; + Reference< reflection::XTypeDescriptionEnumeration > sxEnum; + Reference< reflection::XTypeDescriptionEnumerationAccess> xTypeEnumAccess( xAccess, UNO_QUERY ); + if ( xTypeEnumAccess.is() ) + { + try + { + sxEnum = xTypeEnumAccess->createTypeDescriptionEnumeration( + "com.sun.star", aParams, reflection::TypeDescriptionSearchDepth_INFINITE ); + + Reference< reflection::XTypeDescription > xDesc = sxEnum->nextTypeDescription(); + //check the modules + while( sxEnum->hasMoreElements() ) + { + if( xDesc->getName().endsWithIgnoreAsciiCase(sNewTypeName) ) + { + return xDesc->getName(); + } + + xDesc = sxEnum->nextTypeDescription(); + } + } + catch( const Exception& ex ) { return OUString(""); } + } + } + } + catch( const Exception& ex ) + { + OSL_FAIL("Could not create com.sun.star.reflection.TypeDescriptionManager"); } - return sNewTypeName; + return OUString(""); } std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache) diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index d62b4001ef77..c011d51e951d 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -1795,16 +1795,16 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache) { SbiSymDef* pSymDef = pPool->Get(i); //std::cerr << "i: " << i << ", type: " << pSymDef->GetType() << "; name:" << pSymDef->GetName() << std::endl; - if( (pSymDef->GetType() != SbxEMPTY) || (pSymDef->GetType() != SbxNULL) ) - aCache.InsertGlobalVar( pSymDef->GetName(), CodeCompleteOptions::AddUnoPrefix(pParser->aGblStrings.Find(pSymDef->GetTypeId())) ); + if( ((pSymDef->GetType() != SbxEMPTY) || (pSymDef->GetType() != SbxNULL))/* && !CodeCompleteOptions::GetUnoType(pParser->aGblStrings.Find(pSymDef->GetTypeId())).isEmpty() */) + aCache.InsertGlobalVar( pSymDef->GetName(), CodeCompleteOptions::GetUnoType(pParser->aGblStrings.Find(pSymDef->GetTypeId())) ); SbiSymPool& pChildPool = pSymDef->GetPool(); for(sal_uInt16 j = 0; j < pChildPool.GetSize(); ++j ) { SbiSymDef* pChildSymDef = pChildPool.Get(j); //std::cerr << "j: " << j << ", type: " << pChildSymDef->GetType() << "; name:" << pChildSymDef->GetName() << std::endl; - if( (pChildSymDef->GetType() != SbxEMPTY) || (pChildSymDef->GetType() != SbxNULL) ) - aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), CodeCompleteOptions::AddUnoPrefix(pParser->aGblStrings.Find(pChildSymDef->GetTypeId())) ); + if( ((pChildSymDef->GetType() != SbxEMPTY) || (pChildSymDef->GetType() != SbxNULL))/* && !CodeCompleteOptions::GetUnoType(pParser->aGblStrings.Find(pSymDef->GetTypeId())).isEmpty() */) + aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), CodeCompleteOptions::GetUnoType(pParser->aGblStrings.Find(pChildSymDef->GetTypeId())) ); } } delete pParser; diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index c2139196310d..baa6ebcd151d 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -21,13 +21,19 @@ #include "sbcomp.hxx" #include "sbunoobj.hxx" #include <svtools/miscopt.hxx> -#include "com/sun/star/reflection/XIdlReflection.hpp" +/*#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/reflection/XTypeDescriptionEnumerationAccess.hpp" +#include "com/sun/star/reflection/XTypeDescription.hpp" +#include "com/sun/star/reflection/TypeDescriptionSearchDepth.hpp" #include "com/sun/star/uno/Exception.hpp" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/uno/TypeClass.hpp" +#include "com/sun/star/container/XHierarchicalNameAccess.hpp"*/ #include <basic/codecompletecache.hxx> #include <iostream> @@ -1334,28 +1340,7 @@ void SbiParser::DefStatic( bool bPrivate ) bool SbiParser::IsUnoInterface(const OUString& sTypeName) { - OUString sNewTypeName = CodeCompleteOptions::AddUnoPrefix( 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(sNewTypeName); - if( xClass != NULL ) - { - return true; - } - return false; - } - catch( const Exception& ex ) - { - OSL_FAIL("Could not create reflection.CoreReflection."); - } - return false; + return !CodeCompleteOptions::GetUnoType( sTypeName ).isEmpty(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/codecompletecache.hxx b/include/basic/codecompletecache.hxx index 6dc389ad9d67..4bef3d1b13fc 100644 --- a/include/basic/codecompletecache.hxx +++ b/include/basic/codecompletecache.hxx @@ -70,7 +70,7 @@ public: static bool IsAutoCorrectOn(); static void SetAutoCorrectOn( const bool& b ); - static OUString AddUnoPrefix( const OUString& sTypeName ); + static OUString GetUnoType( const OUString& sTypeName ); }; class BASIC_DLLPUBLIC CodeCompleteDataCache |