summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGergo Mocsi <gmocsi91@gmail.com>2013-08-07 11:49:33 +0200
committerGergo Mocsi <gmocsi91@gmail.com>2013-08-07 11:49:33 +0200
commit64e0656659ab9cae0cfd43a1f4e9286fdefae6fb (patch)
treea42f02e899cfb4edcfb65d6a7b3a888de4e6dd42
parent8f008f0d810068bb9b663fc73177883c3918b6f5 (diff)
GSOC work, code simplification
Created a new class: UnoTypeCodeCompletor, which does the field/method extraction for code completition. Functions GetXIdlClassMethods() and GetXIdlClassFields() have been added to UnoTypeCodeCompletor and removed from EditorWindow. Change-Id: Ia47965b502c868f52c466c282cb98ccd806ff6f7
-rw-r--r--basctl/source/basicide/baside2.hxx27
-rw-r--r--basctl/source/basicide/baside2b.cxx262
2 files changed, 173 insertions, 116 deletions
diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx
index 99822c44627c..b3114cacc64c 100644
--- a/basctl/source/basicide/baside2.hxx
+++ b/basctl/source/basicide/baside2.hxx
@@ -54,6 +54,10 @@ class SvxSearchItem;
#include <vcl/textdata.hxx>
#include <basic/codecompletecache.hxx>
#include "com/sun/star/reflection/XIdlClass.hpp"
+#include <comphelper/namedvaluecollection.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/configurationhelper.hxx>
+#include "com/sun/star/reflection/XIdlReflection.hpp"
namespace com { namespace sun { namespace star { namespace beans {
class XMultiPropertySet;
@@ -120,8 +124,6 @@ private:
CodeCompleteDataCache aCodeCompleteCache;
boost::scoped_ptr< CodeCompleteWindow > pCodeCompleteWnd;
OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number
- std::vector< OUString > GetXIdlClassMethods( ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass > xClass ) const;
- std::vector< OUString > GetXIdlClassFields( ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass > xClass ) const;
void HandleAutoCorrect();
void HandleAutoCloseParen();
void HandleAutoCloseDoubleQuotes();
@@ -537,6 +539,27 @@ public:
};
+class UnoTypeCodeCompletetor
+{
+private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory;
+ ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlReflection > xRefl;
+ ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass > xClass;
+ bool bCanComplete;
+
+ bool CheckField( const OUString& sFieldName );
+ bool CheckMethod( const OUString& sMethName );
+
+public:
+ UnoTypeCodeCompletetor( const std::vector< OUString >& aVect, const OUString& sVarType );
+ ~UnoTypeCodeCompletetor(){}
+
+ std::vector< OUString > GetXIdlClassMethods() const;
+ std::vector< OUString > GetXIdlClassFields() const;
+
+ bool CanCodeComplete() const;
+};
+
} // namespace basctl
#endif // BASCTL_BASIDE2_HXX
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 2481b88974aa..8940ccf654c3 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -48,13 +48,10 @@
#include <vcl/help.hxx>
#include <vector>
-#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/XIdlField.hpp"
+#include "com/sun/star/uno/Exception.hpp"
namespace basctl
{
@@ -738,7 +735,7 @@ void EditorWindow::HandleCodeCompletition()
HighlightPortions aPortions;
aHighlighter.getHighlightPortions( nLine, aLine, aPortions );
if( aPortions.size() != 0 )
- {
+ {//use the syntax highlighter to grab out nested reflection calls, eg. aVar.aMethod("aa").aOtherMethod ..
for ( size_t i = 0; i < aPortions.size(); i++ )
{
HighlightPortion& r = aPortions[i];
@@ -759,124 +756,45 @@ void EditorWindow::HandleCodeCompletition()
pEditView->SetSelection( aSel );
}
- Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW );
- Reference< reflection::XIdlReflection > xRefl( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW );
+ UnoTypeCodeCompletetor aTypeCompletor( aVect, sVarType );
- if( xRefl.is() )
+ if( aTypeCompletor.CanCodeComplete() )
{
- Reference< reflection::XIdlClass > xClass = xRefl->forName(sVarType);//get the base class for reflection
- if( xClass != NULL )
+ std::vector< OUString > aEntryVect;//entries to be inserted into the list
+ std::vector< OUString > aFieldVect = aTypeCompletor.GetXIdlClassFields();//fields
+ aEntryVect.insert(aEntryVect.end(), aFieldVect.begin(), aFieldVect.end() );
+ if( CodeCompleteOptions::IsExtendedTypeDeclaration() )
+ {// if extended types on, reflect classes, else just the structs (XIdlClass without methods)
+ std::vector< OUString > aMethVect = aTypeCompletor.GetXIdlClassMethods();//methods
+ aEntryVect.insert(aEntryVect.end(), aMethVect.begin(), aMethVect.end() );
+ }
+ if( aEntryVect.size() > 0 )
{
- unsigned int j = 1;
- OUString sMethName;
- bool bReflect = true;
- while( j != aVect.size() )
+ // calculate position
+ Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false );
+ long nViewYOffset = pEditView->GetStartDocPos().Y();
+ Point aPoint = aRect.BottomRight();
+ aPoint.Y() = (aPoint.Y() - nViewYOffset) + 2;
+ aSel.GetStart().GetIndex() += 1;
+ aSel.GetEnd().GetIndex() += 1;
+ pCodeCompleteWnd->ClearListBox();
+ pCodeCompleteWnd->SetTextSelection(aSel);
+ //fill the listbox
+ for(unsigned int l = 0; l < aEntryVect.size(); ++l)
{
- sMethName = aVect[j];
- Reference< reflection::XIdlField> xField = xClass->getField( sMethName );
- if( xField != NULL )
- {
- xClass = xField->getType();
- if( xClass == NULL )
- {
- break;
- }
- }
- else
- {
- if( CodeCompleteOptions::IsExtendedTypeDeclaration() )
- {
- Reference< reflection::XIdlMethod> xMethod = xClass->getMethod( sMethName );
- if( xMethod != NULL ) //method OK
- {
- xClass = xMethod->getReturnType();
- if( xClass == NULL )
- {
- break;
- }
- }
- else
- {//nothing to reflect
- bReflect = false;
- break;
- }
- }
- else
- {// no extended types allowed
- bReflect = false;
- break;
- }
- }
- j++;
- }
- if( bReflect )
- {
- std::vector< OUString > aEntryVect;//entries to be inserted into the list
- std::vector< OUString > aMethVect = GetXIdlClassMethods(xClass);//methods
- std::vector< OUString > aFieldVect = GetXIdlClassFields(xClass);//fields
- aEntryVect.insert(aEntryVect.end(), aFieldVect.begin(), aFieldVect.end() );
- if( CodeCompleteOptions::IsExtendedTypeDeclaration() )
- {// if extended types on, reflect classes, else just the structs (XIdlClass without methods)
- aEntryVect.insert(aEntryVect.end(), aMethVect.begin(), aMethVect.end() );
- }
- if( aEntryVect.size() > 0 )
- {
- // calculate position
- Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false );
- long nViewYOffset = pEditView->GetStartDocPos().Y();
- Point aPoint = aRect.BottomRight();
- aPoint.Y() = aPoint.Y() - nViewYOffset;
- aPoint.Y() += 2;
- aSel.GetStart().GetIndex() += 1;
- aSel.GetEnd().GetIndex() += 1;
- pCodeCompleteWnd->ClearListBox();
- pCodeCompleteWnd->SetTextSelection(aSel);
- //fill the listbox
- for(unsigned int l = 0; l < aEntryVect.size(); ++l)
- {
- pCodeCompleteWnd->InsertEntry( aEntryVect[l] );
- }
- //show it
- pCodeCompleteWnd->SetPosPixel( aPoint );
- pCodeCompleteWnd->Show();
- pCodeCompleteWnd->ResizeListBox();
- pCodeCompleteWnd->SelectFirstEntry();
- pEditView->GetWindow()->GrabFocus();
- }
+ pCodeCompleteWnd->InsertEntry( aEntryVect[l] );
}
+ //show it
+ pCodeCompleteWnd->SetPosPixel( aPoint );
+ pCodeCompleteWnd->Show();
+ pCodeCompleteWnd->ResizeListBox();
+ pCodeCompleteWnd->SelectFirstEntry();
+ pEditView->GetWindow()->GrabFocus();
}
}
}
}
-std::vector< OUString > EditorWindow::GetXIdlClassMethods( Reference< reflection::XIdlClass > xClass ) const
-{
- Sequence< Reference< reflection::XIdlMethod > > aMethods = xClass->getMethods();
- std::vector< OUString > aRetVect;
- if( aMethods.getLength() != 0 )
- {
- for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
- {
- aRetVect.push_back(OUString(aMethods[l]->getName()));
- }
- }
- return aRetVect;
-}
-
-std::vector< OUString > EditorWindow::GetXIdlClassFields( Reference< reflection::XIdlClass > xClass ) const
-{
- Sequence< Reference< reflection::XIdlField > > aFields = xClass->getFields();
- std::vector< OUString > aRetVect;
- if( aFields.getLength() != 0 )
- {
- for(sal_Int32 l = 0; l < aFields.getLength(); ++l)
- {
- aRetVect.push_back(OUString(aFields[l]->getName()));
- }
- }
- return aRetVect;
-}
-
void EditorWindow::Paint( const Rectangle& rRect )
{
if ( !pEditEngine ) // We need it now at latest
@@ -2771,7 +2689,7 @@ void CodeCompleteWindow::ResizeListBox()
aLongestEntry = pListBox->GetEntry( i );
}
}
- long nWidth = GetTextWidth(aLongestEntry);
+ //long nWidth = GetTextWidth(aLongestEntry);
sal_uInt16 nColumns = aLongestEntry.getLength();
sal_uInt16 nLines = std::min( (sal_uInt16) 6, pListBox->GetEntryCount() );
const Font& aFont = pListBox->GetUnzoomedControlPointFont();
@@ -2830,6 +2748,122 @@ void CodeCompleteWindow::SetVisibleEntries()
pListBox->SetVisibleEntries();
}
+UnoTypeCodeCompletetor::UnoTypeCodeCompletetor( const std::vector< OUString >& aVect, const OUString& sVarType )
+: bCanComplete( true )
+{
+ if( aVect.size() == 0 || sVarType.isEmpty() )
+ {
+ bCanComplete = false;//invalid parameters, nothing to code complete
+ return;
+ }
+
+ try
+ {
+ xFactory = Reference< lang::XMultiServiceFactory >( comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
+ xRefl = Reference< reflection::XIdlReflection >( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW );
+ if( xRefl.is() )
+ xClass = xRefl->forName( sVarType );//get the base class for reflection
+ }
+ catch( const Exception& ex)
+ {
+ bCanComplete = false;
+ return;
+ }
+
+ unsigned int j = 1;//start from aVect[1]: aVect[0] is the variable name
+ OUString sMethName;
+ while( j != aVect.size() )
+ {
+ sMethName = aVect[j];
+
+ if( !CheckField(sMethName) )//check field
+ break;
+ else
+ {
+ if( CodeCompleteOptions::IsExtendedTypeDeclaration() )
+ {// if extended types on, check methods
+ if( !CheckMethod(sMethName) )
+ {
+ bCanComplete = false;
+ break;
+ }
+ }
+ bCanComplete = false;
+ break;
+ }
+ j++;
+ }
+}
+
+std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassMethods() const
+{
+
+ std::vector< OUString > aRetVect;
+ if( bCanComplete )
+ {
+ Sequence< Reference< reflection::XIdlMethod > > aMethods = xClass->getMethods();
+ if( aMethods.getLength() != 0 )
+ {
+ for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
+ {
+ aRetVect.push_back(OUString(aMethods[l]->getName()));
+ }
+ }
+ }
+ return aRetVect;//this is empty when cannot code complete
+}
+
+std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassFields() const
+{
+
+ std::vector< OUString > aRetVect;
+ if( bCanComplete )
+ {
+ Sequence< Reference< reflection::XIdlField > > aFields = xClass->getFields();
+ if( aFields.getLength() != 0 )
+ {
+ for(sal_Int32 l = 0; l < aFields.getLength(); ++l)
+ {
+ aRetVect.push_back(OUString(aFields[l]->getName()));
+ }
+ }
+ }
+ return aRetVect;//this is empty when cannot code complete
+}
+
+bool UnoTypeCodeCompletetor::CanCodeComplete() const
+{
+ return bCanComplete;
+}
+
+bool UnoTypeCodeCompletetor::CheckField( const OUString& sFieldName )
+{
+ Reference< reflection::XIdlField> xField = xClass->getField( sFieldName );
+ if( xField != NULL )
+ {
+ xClass = xField->getType();
+ if( xClass == NULL )
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool UnoTypeCodeCompletetor::CheckMethod( const OUString& sMethName )
+{
+ Reference< reflection::XIdlMethod> xMethod = xClass->getMethod( sMethName );
+ if( xMethod != NULL ) //method OK
+ {
+ xClass = xMethod->getReturnType();
+ if( xClass == NULL )
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace basctl
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */