[Libreoffice-commits] core.git: Branch 'feature/gsoc-basic-ide-completion-and-other-bits' - basctl/source

Gergo Mocsi gmocsi91 at gmail.com
Fri Jul 26 08:36:23 PDT 2013


 basctl/source/basicide/baside2b.cxx |  115 +++++++++++++++++++++---------------
 1 file changed, 70 insertions(+), 45 deletions(-)

New commits:
commit 6037bf8a26b028542d82deb58e5de4988f346bcc
Author: Gergo Mocsi <gmocsi91 at gmail.com>
Date:   Fri Jul 26 17:28:54 2013 +0200

    GSOC work, extend reflection+crash fix
    
    Fixed creash error on accessing elements of an empty vector.
    Reflection is now extract fields also.
    
    Change-Id: Ic41353cbe9fc404115eb0d2b2f9d5706fc044dab

diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 0cb09c0..5ff3e3d 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -54,6 +54,7 @@
 #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"
 
 namespace basctl
 {
@@ -499,6 +500,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
     // see if there is an accelerator to be processed first
     bool bDone = SfxViewShell::Current()->KeyInput( rKEvt );
 
+
     if( rKEvt.GetCharCode() == '"' && CodeCompleteOptions::IsAutoCloseQuotesOn() )
     {//autoclose double quotes
         TextSelection aSel = GetEditView()->GetSelection();
@@ -507,12 +509,15 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
 
         HighlightPortions aPortions;
         aHighlighter.getHighlightPortions( nLine, aLine, aPortions );
-        if( aLine.getLength() > 0 && aLine[aLine.getLength()-1] != '"' && (aPortions[aPortions.size()-1].tokenType != 4) )
+        if( aPortions.size() != 0 )
         {
-            GetEditView()->InsertText(OUString("\""));
-            //leave the cursor on it's place: inside the two double quotes
-            TextPaM aEnd(nLine, aSel.GetEnd().GetIndex());
-            GetEditView()->SetSelection( TextSelection( aEnd, aEnd ) );
+            if( aLine.getLength() > 0 && aLine[aLine.getLength()-1] != '"' && (aPortions[aPortions.size()-1].tokenType != 4) )
+            {
+                GetEditView()->InsertText(OUString("\""));
+                //leave the cursor on it's place: inside the two double quotes
+                TextPaM aEnd(nLine, aSel.GetEnd().GetIndex());
+                GetEditView()->SetSelection( TextSelection( aEnd, aEnd ) );
+            }
         }
     }
 
@@ -565,58 +570,78 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
 
         HighlightPortions aPortions;
         aHighlighter.getHighlightPortions( nLine, aLine, aPortions );
-        for ( size_t i = 0; i < aPortions.size(); i++ )
+        if( aPortions.size() != 0 )
         {
-            HighlightPortion& r = aPortions[i];
-            if( r.tokenType == 1 ) // extract the identifers(methods, base variable)
-                aVect.push_back( aLine.copy(r.nBegin, r.nEnd - r.nBegin) );
-        }
-        OUString sBaseName = aVect[0];//variable name
-        OUString sVarType = aCodeCompleteCache.GetVarType( sBaseName );
+            for ( size_t i = 0; i < aPortions.size(); i++ )
+            {
+                HighlightPortion& r = aPortions[i];
+                if( r.tokenType == 1 ) // extract the identifers(methods, base variable)
+                    aVect.push_back( aLine.copy(r.nBegin, r.nEnd - r.nBegin) );
+            }
 
-        Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW );
-        Reference< reflection::XIdlReflection > xRefl( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW );
+            OUString sBaseName = aVect[0];//variable name
+            OUString sVarType = aCodeCompleteCache.GetVarType( sBaseName );
 
-        if( xRefl.is() )
-        {
-            Reference< reflection::XIdlClass > xClass = xRefl->forName(sVarType);//get the base class for reflection
-            if( xClass != NULL )
+            Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW );
+            Reference< reflection::XIdlReflection > xRefl( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW );
+
+            if( xRefl.is() )
             {
-                unsigned int j = 1;
-                OUString sMethName;
-                while( j != aVect.size() )
+                Reference< reflection::XIdlClass > xClass = xRefl->forName(sVarType);//get the base class for reflection
+                if( xClass != NULL )
                 {
-                    sMethName = aVect[j];
-                    Reference< reflection::XIdlMethod> xMethod = xClass->getMethod( sMethName );
-                    if( xMethod != NULL ) //method OK
+                    unsigned int j = 1;
+                    OUString sMethName;
+                    while( j != aVect.size() )
                     {
-                        xClass = xMethod->getReturnType();
-                        if( xClass == NULL )
+                        sMethName = aVect[j];
+                        Reference< reflection::XIdlMethod> xMethod = xClass->getMethod( sMethName );
+                        if( xMethod != NULL ) //method OK
+                        {
+                            xClass = xMethod->getReturnType();
+                            if( xClass == NULL )
+                                break;
+                        }
+                        else
+                        {
                             break;
+                        }
+                        j++;
                     }
-                    else
+                    Sequence< Reference< reflection::XIdlMethod > > aMethods = xClass->getMethods();
+                    Sequence< Reference< reflection::XIdlField > > aFields = xClass->getFields();
+                    std::vector< OUString > aEntryVect;
+
+                    if( aMethods.getLength() != 0 )
                     {
-                        break;
+                        for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
+                        {
+                            aEntryVect.push_back(OUString(aMethods[l]->getName()));
+                        }
                     }
-                    j++;
-                }
-                Sequence< Reference< reflection::XIdlMethod > > aMethods = xClass->getMethods();
-                if( aMethods.getLength() != 0 )
-                {
-                    Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false );
-                    aSel.GetStart().GetIndex() += 1;
-                    aSel.GetEnd().GetIndex() += 1;
-                    pCodeCompleteWnd->ClearListBox();
-                    pCodeCompleteWnd->SetTextSelection(aSel);
-
-                    pCodeCompleteWnd->SetPosPixel( aRect.BottomRight() );
-                    for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
+                    if( aFields.getLength() != 0 )
                     {
-                        pCodeCompleteWnd->InsertEntry( OUString(aMethods[l]->getName()) );
+                        for(sal_Int32 l = 0; l < aFields.getLength(); ++l)
+                        {
+                            aEntryVect.push_back(OUString(aFields[l]->getName()));
+                        }
+                    }
+                    if( aEntryVect.size() > 0 )
+                    {
+                        Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false );
+                        aSel.GetStart().GetIndex() += 1;
+                        aSel.GetEnd().GetIndex() += 1;
+                        pCodeCompleteWnd->ClearListBox();
+                        pCodeCompleteWnd->SetTextSelection(aSel);
+                        for(unsigned int l = 0; l < aEntryVect.size(); ++l)
+                        {
+                            pCodeCompleteWnd->InsertEntry( aEntryVect[l] );
+                        }
+                        pCodeCompleteWnd->SetPosPixel( aRect.BottomRight() );
+                        pCodeCompleteWnd->Show();
+                        pCodeCompleteWnd->ResizeListBox();
+                        pCodeCompleteWnd->SelectFirstEntry();
                     }
-                    pCodeCompleteWnd->Show();
-                    pCodeCompleteWnd->ResizeListBox();
-                    pCodeCompleteWnd->SelectFirstEntry();
                 }
             }
         }


More information about the Libreoffice-commits mailing list