summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGergo Mocsi <gmocsi91@gmail.com>2013-08-08 13:59:50 +0200
committerGergo Mocsi <gmocsi91@gmail.com>2013-08-08 13:59:50 +0200
commitf022a4966d838b14cdfb1608ba0999520e3b6e40 (patch)
tree55bc7201b0c88938e3b770f26b0e7411c44a2d90
parent7a71169604207979f3d4e8ce9f6c2d956534d82e (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
-rw-r--r--basctl/source/basicide/baside2.hxx7
-rw-r--r--basctl/source/basicide/baside2b.cxx73
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 811cb3b94a94..b9f0cadf33e7 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -501,7 +501,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
@@ -727,28 +726,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 );
}
@@ -766,14 +768,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 );
@@ -2754,7 +2754,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;
@@ -2762,32 +2762,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 )
{
@@ -2796,7 +2798,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()) );
}
}
}
@@ -2805,7 +2807,6 @@ std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassMethods() const
std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassFields() const
{
-
std::vector< OUString > aRetVect;
if( bCanComplete )
{
@@ -2814,7 +2815,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()) );
}
}
}
@@ -2827,12 +2828,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;
}
@@ -2841,12 +2842,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;
}