Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv489/src/rfta Modified Files: SplitDeclarationRefactoringTest.h SplitDeclarationRefactoringTest.cpp CodeWriterTest.h CodeWriterTest.cpp CodeRewriter.h CodeRewriter.cpp Log Message: fixed problem with spaces when rewriting declarator expressions Index: SplitDeclarationRefactoringTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitDeclarationRefactoringTest.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SplitDeclarationRefactoringTest.h 21 Apr 2003 16:10:21 -0000 1.1 --- SplitDeclarationRefactoringTest.h 24 Apr 2003 16:28:29 -0000 1.2 *************** *** 21,27 **** CPPUNIT_TEST( testEasiestCase ); CPPUNIT_TEST( testSeveralVariables ); ! CPPUNIT_TEST_FAIL( testSpaceProblem ); CPPUNIT_TEST( testSeveralDeclarations ); CPPUNIT_TEST( testInitializers ); CPPUNIT_TEST_SUITE_END(); --- 21,28 ---- CPPUNIT_TEST( testEasiestCase ); CPPUNIT_TEST( testSeveralVariables ); ! CPPUNIT_TEST( testSpaceProblem ); CPPUNIT_TEST( testSeveralDeclarations ); CPPUNIT_TEST( testInitializers ); + CPPUNIT_TEST( testSubscope ); CPPUNIT_TEST_SUITE_END(); *************** *** 42,45 **** --- 43,47 ---- void testSeveralDeclarations(); void testInitializers(); + void testSubscope(); private: void applyRefactoring( ); Index: SplitDeclarationRefactoringTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitDeclarationRefactoringTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SplitDeclarationRefactoringTest.cpp 21 Apr 2003 16:10:24 -0000 1.1 --- SplitDeclarationRefactoringTest.cpp 24 Apr 2003 16:28:30 -0000 1.2 *************** *** 99,103 **** " double* x;\n" " double y[3];\n" ! " double &z;\n" "}\n" ); std::string actualSource( document_->getAllText() ); --- 99,103 ---- " double* x;\n" " double y[3];\n" ! " double&z;\n" "}\n" ); std::string actualSource( document_->getAllText() ); *************** *** 141,144 **** --- 141,167 ---- RFTA_ASSERT_EQUAL( expectedSource, actualSource ); } + + void + SplitDeclarationRefactoringTest::testSubscope() + { + builder_->add( "{\n" ); + builder_->add( " if (true)\n" ); + builder_->add( " {\n" ); + builder_->addKeyingMid( " int ", "x", ", y;\n", "selection"); + builder_->add( " }\n" ); + builder_->add( "}\n" ); + applyRefactoring( ); + std::string expectedSource( + "{\n" + " if (true)\n" + " {\n" + " int x;\n" + " int y;\n" + " }\n" + "}\n"); + std::string actualSource( document_->getAllText() ); + RFTA_ASSERT_EQUAL( expectedSource, actualSource ); + + }; } // namespace Refactoring Index: CodeWriterTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** CodeWriterTest.h 21 Apr 2003 03:08:53 -0000 1.29 --- CodeWriterTest.h 24 Apr 2003 16:28:30 -0000 1.30 *************** *** 46,49 **** --- 46,50 ---- CPPUNIT_TEST( testRemoveDeclaratorMiddle ); CPPUNIT_TEST_FAIL( testRemoveDeclaratorEnd ); + CPPUNIT_TEST( spaceProblem ); CPPUNIT_TEST_SUITE_END(); *************** *** 96,100 **** void testRemoveDeclaratorMiddle(); void testRemoveDeclaratorEnd(); ! private: }; --- 97,101 ---- void testRemoveDeclaratorMiddle(); void testRemoveDeclaratorEnd(); ! void spaceProblem(); private: }; Index: CodeWriterTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** CodeWriterTest.cpp 21 Apr 2003 03:08:53 -0000 1.35 --- CodeWriterTest.cpp 24 Apr 2003 16:28:30 -0000 1.36 *************** *** 618,620 **** --- 618,636 ---- "}"); } + + void + CodeWriterTest::spaceProblem() + { + source_ = "{\n" + " int* x, y[3];\n" + "}"; + generateCompound(); + CodeModel::DeclarationStatement &declarationStatement = + dynamic_cast<CodeModel::DeclarationStatement &>( *compound_->getStatementAt(0) ); + declarationStatement.getDeclaration()->removeDeclaratorAt(0); + generateAndCheckSource( "{\n" + " int y[3];\n" + "}"); + } + } // namespace Refactoring Index: CodeRewriter.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** CodeRewriter.h 22 Apr 2003 19:17:02 -0000 1.19 --- CodeRewriter.h 24 Apr 2003 16:28:30 -0000 1.20 *************** *** 168,171 **** --- 168,172 ---- bool needsToInsertComma( const Change& change, int index, bool firstWasAdded); + bool needsToInsertSpace( const DeclaratorExpressionPtr& expression ); private: IndentLevelManager indentManager_; Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** CodeRewriter.cpp 22 Apr 2003 19:17:01 -0000 1.42 --- CodeRewriter.cpp 24 Apr 2003 16:28:30 -0000 1.43 *************** *** 10,14 **** #include <rfta/refactoring/CodeModelExpressions.h> #include <rfta/refactoring/CodeModelStatements.h> ! namespace Refactoring { namespace CodeModel { --- 10,14 ---- #include <rfta/refactoring/CodeModelExpressions.h> #include <rfta/refactoring/CodeModelStatements.h> ! #include <cctype> namespace Refactoring { namespace CodeModel { *************** *** 636,643 **** if ( isInserting() ) beginInsertNewStatement(); - handleMandatoryChange( expression->getPrimaryTypeChange(), ! *expression->getPrimaryType() ); ! bool firstWasAdded = false; for ( int index = 0; index < expression->getChangeCount(); ++ index ) { --- 636,645 ---- if ( isInserting() ) beginInsertNewStatement(); handleMandatoryChange( expression->getPrimaryTypeChange(), ! *expression->getPrimaryType() ); ! DeclaratorPtr declarator = expression->getDeclaratorAt(0); ! if (needsToInsertSpace( expression ) ) ! insertText( " " ); ! bool firstWasAdded = expression->getChangeAt( 0 ).wasAdded(); for ( int index = 0; index < expression->getChangeCount(); ++ index ) { *************** *** 645,656 **** deleteTextIfNecessary( change ); if (change.wasRemoved()) ! continue; ! if ( index == 0 ) ! firstWasAdded = change.wasAdded(); if ( needsToInsertComma( change, index, firstWasAdded ) ) insertText( ", " ); - DeclaratorPtr declarator = expression->getChangeDeclaratorAt( index ); - ModeModifier mode( mode_, change.isUnmodified() ? updating : inserting ); processDeclarator( declarator ); --- 647,654 ---- deleteTextIfNecessary( change ); if (change.wasRemoved()) ! continue; if ( needsToInsertComma( change, index, firstWasAdded ) ) insertText( ", " ); DeclaratorPtr declarator = expression->getChangeDeclaratorAt( index ); ModeModifier mode( mode_, change.isUnmodified() ? updating : inserting ); processDeclarator( declarator ); *************** *** 743,746 **** --- 741,756 ---- } + bool + CodeRewriter::needsToInsertSpace( const DeclaratorExpressionPtr& expression ) + { + DeclaratorPtr declarator = expression->getDeclaratorAt(0); + if (declarator->hasType() && + declarator->getType()->getTypeText().size() > 0) + return false; + std::string type =expression->getPrimaryType()->getTypeText(); + char lastCharacter = type[type.length()-1]; + return ! std::isspace( lastCharacter ); + + }; } // namespace CodeModel } // namespace Refactoring |