Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv3293/src/rfta
Modified Files:
CodeModelStatements.cpp CodeRewriter.cpp CodeRewriter.h
CodeWriterTest.cpp CodeWriterTest.h IndentLevelManager.cpp
IndentLevelManager.h
Log Message:
* added support for replacing while condition and iterated statement
* 'while' compound substatement is not indented
Index: CodeModelStatements.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelStatements.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** CodeModelStatements.cpp 16 Mar 2003 16:18:40 -0000 1.12
--- CodeModelStatements.cpp 16 Mar 2003 20:32:42 -0000 1.13
***************
*** 278,281 ****
--- 278,288 ----
+ Change
+ IterationStatement::getIteratedStatementChange() const
+ {
+ return iteratedStatementTracker_.getChange();
+ }
+
+
void
IterationStatement::accept( StatementVisitor &visitor )
Index: CodeRewriter.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** CodeRewriter.cpp 16 Mar 2003 19:55:05 -0000 1.26
--- CodeRewriter.cpp 16 Mar 2003 20:32:42 -0000 1.27
***************
*** 129,132 ****
--- 129,147 ----
void
+ CodeRewriter::deleteBracedExpression( const SourceRange &range )
+ {
+ int startIndex = range.getStartIndex();
+ while ( startIndex > 0 && isSpace( originalSource_.at( startIndex-1 ) ) )
+ --startIndex;
+
+ int endIndex = range.getEndIndex();
+ while ( endIndex < originalSource_.length() && isSpace( originalSource_.at( endIndex ) ) )
+ ++endIndex;
+
+ deleteText( SourceRange( startIndex, endIndex - startIndex ) );
+ }
+
+
+ void
CodeRewriter::deleteRange( const SourceRange &range,
DeletionType deletionType )
***************
*** 136,139 ****
--- 151,156 ----
else if ( deletionType == trailingExpressionDelete )
deleteTrailingExpression( range );
+ else if ( deletionType == bracedExpressionDelete )
+ deleteBracedExpression( range );
else
deleteText( range );
***************
*** 179,183 ****
--- 196,206 ----
mode_ = inserting;
+ if ( isInserting() && deletionType == bracedExpressionDelete )
+ insertText( " " );
+
element.accept( *this );
+
+ if ( isInserting() && deletionType == bracedExpressionDelete )
+ insertText( " " );
}
***************
*** 478,483 ****
}
- SourceRange range( );
-
handleOptionalChange( statement.getValueChange(),
statement.getValue(),
--- 501,504 ----
***************
*** 511,519 ****
CodeRewriter::visit( WhileStatement &statement )
{
! beginInsertNewStatement();
! insertText( "while ( " );
! statement.getCondition()->accept( *this );
! insertText( " )" );
! statement.getIteratedStatement()->accept( *this );
}
--- 532,559 ----
CodeRewriter::visit( WhileStatement &statement )
{
! if ( isInserting() )
! {
! beginInsertNewStatement();
! insertText( "while (" );
! }
!
! handleMandatoryChange( statement.getConditionChange(),
! *statement.getCondition(),
! bracedExpressionDelete );
!
! IndentLevelManager::IndentRestorer restorer( indentManager_ );
! StatementPtr iteratedStatement = statement.getIteratedStatement();
! if ( isInserting() )
! {
! insertText( ")" );
! indentManager_.enterNewWhileStatement( iteratedStatement );
! }
! else
! indentManager_.enterExistingWhileStatement( iteratedStatement,
! statement.getSourceRange().getStartIndex() );
!
! handleMandatoryChange( statement.getIteratedStatementChange(),
! *statement.getIteratedStatement(),
! statementDelete );
}
Index: CodeRewriter.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** CodeRewriter.h 16 Mar 2003 19:55:06 -0000 1.12
--- CodeRewriter.h 16 Mar 2003 20:32:43 -0000 1.13
***************
*** 76,80 ****
minimalDelete =0,
statementDelete,
! trailingExpressionDelete
};
--- 76,81 ----
minimalDelete =0,
statementDelete,
! trailingExpressionDelete,
! bracedExpressionDelete
};
***************
*** 133,136 ****
--- 134,139 ----
void deleteTrailingExpression( const SourceRange &range );
+
+ void deleteBracedExpression( const SourceRange &range );
void deleteRange( const SourceRange &range,
Index: CodeWriterTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** CodeWriterTest.cpp 16 Mar 2003 19:55:06 -0000 1.27
--- CodeWriterTest.cpp 16 Mar 2003 20:32:43 -0000 1.28
***************
*** 305,308 ****
--- 305,346 ----
+ void
+ CodeWriterTest::testModifyWhileCondition()
+ {
+ source_ = "{\n"
+ " while ( true )\n"
+ " ;\n"
+ "}";
+ generateCompound();
+
+ CodeModel::WhileStatement &whileStatement =
+ dynamic_cast<CodeModel::WhileStatement &>( *compound_->getStatementAt(0) );
+ whileStatement.setCondition( makeExpression( "false" ) );
+ generateAndCheckSource( "{\n"
+ " while ( false )\n"
+ " ;\n"
+ "}" );
+ }
+
+
+ void
+ CodeWriterTest::testModifyWhileIterationStatement()
+ {
+ source_ = "{\n"
+ " while ( true )\n"
+ " ;\n"
+ "}";
+ generateCompound();
+
+ CodeModel::WhileStatement &whileStatement =
+ dynamic_cast<CodeModel::WhileStatement &>( *compound_->getStatementAt(0) );
+ whileStatement.setIteratedStatement( makeBreakStatement() );
+ generateAndCheckSource( "{\n"
+ " while ( true )\n"
+ " break;\n"
+ "}" );
+ }
+
+
} // namespace Refactoring
Index: CodeWriterTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** CodeWriterTest.h 16 Mar 2003 16:18:41 -0000 1.22
--- CodeWriterTest.h 16 Mar 2003 20:32:43 -0000 1.23
***************
*** 29,32 ****
--- 29,34 ----
CPPUNIT_TEST( testRemoveReturnValue );
CPPUNIT_TEST( testAddReturnValue );
+ CPPUNIT_TEST( testModifyWhileCondition );
+ CPPUNIT_TEST( testModifyWhileIterationStatement );
CPPUNIT_TEST_SUITE_END();
***************
*** 56,59 ****
--- 58,64 ----
void testRemoveReturnValue();
void testAddReturnValue();
+
+ void testModifyWhileCondition();
+ void testModifyWhileIterationStatement();
private:
Index: IndentLevelManager.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** IndentLevelManager.cpp 16 Mar 2003 10:23:07 -0000 1.6
--- IndentLevelManager.cpp 16 Mar 2003 20:32:43 -0000 1.7
***************
*** 6,9 ****
--- 6,10 ----
#include "stdafx.h"
#include "IndentLevelManager.h"
+ #include <rfta/refactoring/CodeModelStatements.h>
***************
*** 57,60 ****
--- 58,85 ----
{
pushIndent( getIndentLevel() + indentWidth_ );
+ }
+
+
+ void
+ IndentLevelManager::enterExistingWhileStatement( const CodeModel::StatementPtr &subStatement,
+ int startingPos )
+ {
+ if ( !isCompoundStatement( subStatement ) )
+ pushIndent( findIndentLevelOf( startingPos ) + indentWidth_ );
+ }
+
+
+ void
+ IndentLevelManager::enterNewWhileStatement( const CodeModel::StatementPtr &subStatement )
+ {
+ if ( !isCompoundStatement( subStatement ) )
+ pushIndent( getIndentLevel() + indentWidth_ );
+ }
+
+
+ bool
+ IndentLevelManager::isCompoundStatement( const CodeModel::StatementPtr &subStatement ) const
+ {
+ return dynamic_cast<CodeModel::CompoundStatement *>( subStatement.get() ) != 0;
}
Index: IndentLevelManager.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** IndentLevelManager.h 16 Mar 2003 10:23:07 -0000 1.7
--- IndentLevelManager.h 16 Mar 2003 20:32:43 -0000 1.8
***************
*** 6,10 ****
#define RFTA_INDENTLEVELMANAGER_H
! #include <rfta/refactoring/Config.h>
#include <string>
--- 6,10 ----
#define RFTA_INDENTLEVELMANAGER_H
! #include <rfta/refactoring/CodeModelForward.h>
#include <string>
***************
*** 66,69 ****
--- 66,74 ----
void enterNewElseStatement();
+ void enterExistingWhileStatement( const CodeModel::StatementPtr &subStatement,
+ int startingPos );
+
+ void enterNewWhileStatement( const CodeModel::StatementPtr &subStatement );
+
int getIndentLevel() const;
***************
*** 72,76 ****
--- 77,84 ----
private:
int findIndentLevelOf( int pos ) const;
+
void pushIndent( int indent );
+
+ bool isCompoundStatement( const CodeModel::StatementPtr &subStatement ) const;
private:
|