diff options
author | Gergo Mocsi <gmocsi91@gmail.com> | 2013-07-26 17:28:54 +0200 |
---|---|---|
committer | Gergo Mocsi <gmocsi91@gmail.com> | 2013-09-02 18:16:50 +0200 |
commit | 2a87d09bc87af84aee9e1986ebb4888264c99dd7 (patch) | |
tree | dcf47563bf16d8474d7bdafacb5bb66ed044644c /basctl/source | |
parent | 412e91d33dfc392f15858614369f956e531785b9 (diff) |
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
Diffstat (limited to 'basctl/source')
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 115 |
1 files changed, 70 insertions, 45 deletions
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index d39f06139a8e..95beacd46738 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 { @@ -505,6 +506,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(); @@ -513,12 +515,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 ) ); + } } } @@ -571,58 +576,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(); } } } |