Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv7390
Modified Files:
CodeRewriter.cpp CodeRewriter.h CodeWriterTest.cpp
CodeWriterTest.h IndentLevelManager.cpp IndentLevelManager.h
rfta.dsp
Log Message:
* inserted statement in compound is now correctly indented
Index: CodeRewriter.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CodeRewriter.cpp 6 Mar 2003 22:17:58 -0000 1.3
--- CodeRewriter.cpp 7 Mar 2003 07:58:31 -0000 1.4
***************
*** 15,21 ****
! CodeRewriter::CodeRewriter( const std::string &originalSource )
: originalSource_( originalSource )
! , indentWidth_( 2 )
, nextStatementInsertionPos_( 0 )
, currentInsertionPos_( 0 )
--- 15,22 ----
! CodeRewriter::CodeRewriter( const std::string &originalSource,
! int indentWidth )
: originalSource_( originalSource )
! , indentWidth_( indentWidth )
, nextStatementInsertionPos_( 0 )
, currentInsertionPos_( 0 )
***************
*** 92,96 ****
{
nextStatementInsertionPos_ = statement.getText().getOriginalSourceRange().getStartIndex() + 1;
! indentManager_.enterExistingStatement( nextStatementInsertionPos_ + 1 );
}
--- 93,97 ----
{
nextStatementInsertionPos_ = statement.getText().getOriginalSourceRange().getStartIndex() + 1;
! indentManager_.enterExistingStatement( nextStatementInsertionPos_ - 1 );
}
***************
*** 208,212 ****
replaceText( text.getOriginalSourceRange(), text.getOriginalText() );
else if ( text.isNewText() )
! replaceText( getCurrentInsertionRange(), "\nreturn;" );
}
--- 209,213 ----
replaceText( text.getOriginalSourceRange(), text.getOriginalText() );
else if ( text.isNewText() )
! replaceText( getCurrentInsertionRange(), "\n" + indentManager_.getIndentSpacer() + "return;" );
}
Index: CodeRewriter.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CodeRewriter.h 6 Mar 2003 22:17:58 -0000 1.3
--- CodeRewriter.h 7 Mar 2003 07:58:31 -0000 1.4
***************
*** 25,29 ****
{
public:
! CodeRewriter( const std::string &originalSource );
/// Destructor.
--- 25,30 ----
{
public:
! CodeRewriter( const std::string &originalSource,
! int indentWidth );
/// Destructor.
Index: CodeWriterTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** CodeWriterTest.cpp 6 Mar 2003 22:17:58 -0000 1.4
--- CodeWriterTest.cpp 7 Mar 2003 07:58:31 -0000 1.5
***************
*** 6,10 ****
#include "stdafx.h"
#include "CodeWriterTest.h"
- #include "CodeRewriter.h"
#include <rfta/refactoring/CodeModel.h>
--- 6,9 ----
***************
*** 32,35 ****
--- 31,35 ----
compound_.reset();
document_.reset();
+ writer_.reset();
}
***************
*** 38,41 ****
--- 38,42 ----
CodeWriterTest::tearDown()
{
+ writer_.reset();
document_.reset();
compound_.reset();
***************
*** 58,61 ****
--- 59,70 ----
void
+ CodeWriterTest::rewriteSource()
+ {
+ writer_.reset( new CodeModel::CodeRewriter( source_, 2 ) );
+ writer_->rewrite( *compound_, *document_ );
+ }
+
+
+ void
CodeWriterTest::testRewriteStatement()
{
***************
*** 76,81 ****
condition.setText( "false" );
! CodeModel::CodeRewriter writer( source_ );
! writer.rewrite( *compound_, *document_ );
std::string expectedSource = "{\n"
--- 85,89 ----
condition.setText( "false" );
! rewriteSource();
std::string expectedSource = "{\n"
***************
*** 90,95 ****
CodeWriterTest::testInsertStatement()
{
! source_ = "{\n"
! "}";
generateCompound();
--- 98,103 ----
CodeWriterTest::testInsertStatement()
{
! source_ = " {\n"
! " }";
generateCompound();
***************
*** 98,107 ****
compound_->appendStatement( CodeModel::StatementPtr( new CodeModel::ReturnStatement() ) );
! CodeModel::CodeRewriter writer( source_ );
! writer.rewrite( *compound_, *document_ );
! std::string expectedSource = "{\n"
! "return;\n"
! "}";
RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
--- 106,114 ----
compound_->appendStatement( CodeModel::StatementPtr( new CodeModel::ReturnStatement() ) );
! rewriteSource();
! std::string expectedSource = " {\n"
! " return;\n"
! " }";
RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
Index: CodeWriterTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CodeWriterTest.h 6 Mar 2003 22:17:58 -0000 1.2
--- CodeWriterTest.h 7 Mar 2003 07:58:31 -0000 1.3
***************
*** 7,10 ****
--- 7,11 ----
#include "SourceBasedTestBase.h"
+ #include "CodeRewriter.h"
#include <rfta/refactoring/CodeModelStatements.h>
#include <rfta/refactoring/CodeModelExpressions.h>
***************
*** 40,46 ****
--- 41,49 ----
private:
void generateCompound();
+ void rewriteSource();
CodeModel::CompoundStatementPtr compound_;
boost::shared_ptr<PlainTextDocument> document_;
+ boost::shared_ptr<CodeModel::CodeRewriter> writer_;
};
Index: IndentLevelManager.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IndentLevelManager.cpp 6 Mar 2003 22:17:58 -0000 1.1
--- IndentLevelManager.cpp 7 Mar 2003 07:58:31 -0000 1.2
***************
*** 28,32 ****
IndentLevelManager::enterExistingStatement( int startingPos )
{
! pushIndent( findIndentLevelOf( startingPos ) );
}
--- 28,32 ----
IndentLevelManager::enterExistingStatement( int startingPos )
{
! pushIndent( findIndentLevelOf( startingPos ) + indentWidth_ );
}
***************
*** 46,49 ****
--- 46,65 ----
{
indents_.push_back( indent );
+ }
+
+
+ int
+ IndentLevelManager::getIndentLevel() const
+ {
+ if ( indents_.empty() )
+ return 0;
+ return indents_.back();
+ }
+
+
+ const std::string
+ IndentLevelManager::getIndentSpacer() const
+ {
+ return std::string( getIndentLevel(), ' ' );
}
Index: IndentLevelManager.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IndentLevelManager.h 6 Mar 2003 22:17:59 -0000 1.1
--- IndentLevelManager.h 7 Mar 2003 07:58:31 -0000 1.2
***************
*** 45,48 ****
--- 45,52 ----
void enterExistingStatement( int startingPos );
+ int getIndentLevel() const;
+
+ const std::string getIndentSpacer() const;
+
private:
int findIndentLevelOf( int pos ) const;
Index: rfta.dsp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/rfta.dsp,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** rfta.dsp 6 Mar 2003 22:17:59 -0000 1.36
--- rfta.dsp 7 Mar 2003 07:58:31 -0000 1.37
***************
*** 361,364 ****
--- 361,372 ----
SOURCE=.\CodeRewriter.h
# End Source File
+ # Begin Source File
+
+ SOURCE=.\IndentLevelManager.cpp
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\IndentLevelManager.h
+ # End Source File
# End Group
# Begin Group "Tests"
***************
*** 940,951 ****
# End Source File
# End Group
- # Begin Source File
-
- SOURCE=.\IndentLevelManager.cpp
- # End Source File
- # Begin Source File
-
- SOURCE=.\IndentLevelManager.h
- # End Source File
# Begin Source File
--- 948,951 ----
|