diff options
author | Gergo Mocsi <gmocsi91@gmail.com> | 2013-08-08 13:59:50 +0200 |
---|---|---|
committer | Gergo Mocsi <gmocsi91@gmail.com> | 2013-09-02 18:16:57 +0200 |
commit | 0861ff9dc0db7d58e73ae0cd7c884f21cf55c4c5 (patch) | |
tree | 1939bb0c2f59208124778d40d807abfce73a976d /basctl/source | |
parent | 7023bcf99d88f86399b515ad41c53d6dae611fd3 (diff) |
GSOC work, code fixes
Simplified the nested reflection.
Fixed the small issue with the autocorrect keywords: it corrupted the line when doing nested reflection.
Iterator is used instead of for loop when extracting identifiers for nested ferlection.
Change-Id: I8e7e83b4e46838a32e03f71b4fe91dd9d94b3131
Diffstat (limited to 'basctl/source')
-rw-r--r-- | basctl/source/basicide/baside2.hxx | 7 | ||||
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 73 |
2 files changed, 40 insertions, 40 deletions
diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx index 9c162fc6ed1b..8f96116e614c 100644 --- a/basctl/source/basicide/baside2.hxx +++ b/basctl/source/basicide/baside2.hxx @@ -535,15 +535,14 @@ public: * the window, clear internal variables * */ CodeCompleteListBox* GetListBox(){return pListBox;} - }; 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; + ::css::uno::Reference< ::css::lang::XMultiServiceFactory > xFactory; + ::css::uno::Reference< ::css::reflection::XIdlReflection > xRefl; + ::css::uno::Reference< ::css::reflection::XIdlClass > xClass; bool bCanComplete; bool CheckField( const OUString& sFieldName ); diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index c06933107c95..6d03c4a6d83f 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -507,7 +507,6 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) if( pCodeCompleteWnd->IsVisible() && CodeCompleteOptions::IsCodeCompleteOn() ) { - //std::cerr << "EditorWindow::KeyInput" << std::endl; pCodeCompleteWnd->GetListBox()->KeyInput(rKEvt); if( rKEvt.GetKeyCode().GetCode() == KEY_UP || rKEvt.GetKeyCode().GetCode() == KEY_DOWN @@ -733,28 +732,31 @@ void EditorWindow::HandleCodeCompletition() TextSelection aSel = GetEditView()->GetSelection(); sal_uLong nLine = aSel.GetStart().GetPara(); OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified - std::vector< OUString > aVect; + std::vector< OUString > aVect; //vector to hold the base variable+methods for the nested reflection HighlightPortions aPortions; aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); - if( aPortions.size() != 0 ) + 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++ ) + for( auto aIt = aPortions.crbegin(); aIt != aPortions.crend(); ++aIt ) { - HighlightPortion& r = aPortions[i]; - if( r.tokenType == 1 || r.tokenType == 9) // extract the identifers(methods, base variable) + HighlightPortion r = *aIt; + if( r.tokenType == 2 ) // a whitespace: stop; if there is no ws, it goes to the beginning of the line + break; + if( r.tokenType == 1 || r.tokenType == 9 ) // extract the identifers(methods, base variable) /* an example: Dim aLocVar2 as com.sun.star.beans.PropertyValue * here, aLocVar2.Name, and PropertyValue's Name field is treated as a keyword(?!) * */ - aVect.push_back( aLine.copy(r.nBegin, r.nEnd - r.nBegin) ); + aVect.insert( aVect.begin(), aLine.copy(r.nBegin, r.nEnd - r.nBegin) ); } OUString sBaseName = aVect[0];//variable name OUString sVarType = aCodeCompleteCache.GetVarType( sBaseName ); - if( !sVarType.isEmpty() && CodeCompleteOptions::IsAutoCorrectKeywordsOn() )//correct variable name - { - TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sBaseName.getLength() ); - TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex())); + if( !sVarType.isEmpty() && CodeCompleteOptions::IsAutoCorrectKeywordsOn() ) + {//correct variable name + TextPaM aStart(nLine, aLine.indexOf(sBaseName) ); + TextPaM aEnd(nLine, aLine.indexOf(sBaseName) + sBaseName.getLength() ); + TextSelection sTextSelection(aStart, aEnd); pEditEngine->ReplaceText( sTextSelection, aCodeCompleteCache.GetCorrectCaseVarName(sBaseName) ); pEditView->SetSelection( aSel ); } @@ -772,14 +774,12 @@ void EditorWindow::HandleCodeCompletition() aEntryVect.insert(aEntryVect.end(), aMethVect.begin(), aMethVect.end() ); } if( aEntryVect.size() > 0 ) - { SetupAndShowCodeCompleteWnd( aEntryVect, aSel ); - } } } } -void EditorWindow::SetupAndShowCodeCompleteWnd(const std::vector< OUString >& aEntryVect, TextSelection aSel ) +void EditorWindow::SetupAndShowCodeCompleteWnd( const std::vector< OUString >& aEntryVect, TextSelection aSel ) { // calculate position Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false ); @@ -2760,7 +2760,7 @@ UnoTypeCodeCompletetor::UnoTypeCodeCompletetor( const std::vector< OUString >& a if( xRefl.is() ) xClass = xRefl->forName( sVarType );//get the base class for reflection } - catch( const Exception& ex) + catch( const Exception& ex ) { bCanComplete = false; return; @@ -2768,32 +2768,34 @@ UnoTypeCodeCompletetor::UnoTypeCodeCompletetor( const std::vector< OUString >& a 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; + if( CodeCompleteOptions::IsExtendedTypeDeclaration() ) + { + if( !CheckMethod(sMethName) && !CheckField(sMethName) ) + { + bCanComplete = false; + break; + } + } else { - if( CodeCompleteOptions::IsExtendedTypeDeclaration() ) - {// if extended types on, check methods - if( !CheckMethod(sMethName) ) - { - bCanComplete = false; - break; - } + if( !CheckField(sMethName) ) + { + bCanComplete = false; + break; } - bCanComplete = false; - break; } - j++; + + ++j; } } std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassMethods() const { - std::vector< OUString > aRetVect; if( bCanComplete ) { @@ -2802,7 +2804,7 @@ std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassMethods() const { for(sal_Int32 l = 0; l < aMethods.getLength(); ++l) { - aRetVect.push_back(OUString(aMethods[l]->getName())); + aRetVect.push_back( OUString(aMethods[l]->getName()) ); } } } @@ -2811,7 +2813,6 @@ std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassMethods() const std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassFields() const { - std::vector< OUString > aRetVect; if( bCanComplete ) { @@ -2820,7 +2821,7 @@ std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassFields() const { for(sal_Int32 l = 0; l < aFields.getLength(); ++l) { - aRetVect.push_back(OUString(aFields[l]->getName())); + aRetVect.push_back( OUString(aFields[l]->getName()) ); } } } @@ -2833,12 +2834,12 @@ bool UnoTypeCodeCompletetor::CanCodeComplete() const } bool UnoTypeCodeCompletetor::CheckField( const OUString& sFieldName ) -{ +{// modifies xClass!!! Reference< reflection::XIdlField> xField = xClass->getField( sFieldName ); if( xField != NULL ) { xClass = xField->getType(); - if( xClass == NULL ) + if( xClass != NULL ) { return true; } @@ -2847,12 +2848,12 @@ bool UnoTypeCodeCompletetor::CheckField( const OUString& sFieldName ) } bool UnoTypeCodeCompletetor::CheckMethod( const OUString& sMethName ) -{ +{// modifies xClass!!! Reference< reflection::XIdlMethod> xMethod = xClass->getMethod( sMethName ); - if( xMethod != NULL ) //method OK + if( xMethod != NULL ) //method OK, check return type { xClass = xMethod->getReturnType(); - if( xClass == NULL ) + if( xClass != NULL ) { return true; } |