|
From: <net...@us...> - 2003-04-05 12:14:49
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv16977/src/rfta
Modified Files:
RenameTempRefactoringTest.h RenameTempRefactoringTest.cpp
RenameTempRefactoring.cpp
Log Message:
bugfix + new tests for bug
Index: RenameTempRefactoringTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/RenameTempRefactoringTest.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** RenameTempRefactoringTest.h 19 Dec 2002 20:17:33 -0000 1.8
--- RenameTempRefactoringTest.h 5 Apr 2003 12:14:45 -0000 1.9
***************
*** 25,28 ****
--- 25,29 ----
CPPUNIT_TEST( testRenameSkippingSubScope );
CPPUNIT_TEST( testRenameInVariableInitializer );
+ CPPUNIT_TEST( testSelectInSubScope );
CPPUNIT_TEST_SUITE_END();
***************
*** 44,47 ****
--- 45,50 ----
void testRenameSkippingSubScope();
void testRenameInVariableInitializer();
+
+ void testSelectInSubScope();
private:
Index: RenameTempRefactoringTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/RenameTempRefactoringTest.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** RenameTempRefactoringTest.cpp 22 Dec 2002 15:47:34 -0000 1.14
--- RenameTempRefactoringTest.cpp 5 Apr 2003 12:14:45 -0000 1.15
***************
*** 208,211 ****
--- 208,246 ----
}
+ void
+ RenameTempRefactoringTest::testSelectInSubScope()
+ {
+ builder_->add(
+ "{"
+ " double x = getPrice();"
+ " x += x * rate;");
+ builder_->add(
+ " if ( needTaxes() )"
+ " {"
+ " int z = ");
+ builder_->addKeyingMid( "", "x", " * taxeRate;", "selection" );
+
+ builder_->add(" setTaxes( x );"
+ " }"
+ " return x * getQuantity();"
+ "}" );
+
+ applyRefactoring( "price", "x" );
+
+ std::string expectedSource(
+ "{"
+ " double price = getPrice();"
+ " price += price * rate;"
+ " if ( needTaxes() )"
+ " {"
+ " int z = price * taxeRate;"
+ " setTaxes( price );"
+ " }"
+ " return price * getQuantity();"
+ "}" );
+ std::string actualSource( document_->getAllText() );
+ RFTA_ASSERT_EQUAL( expectedSource, actualSource );
+ }
+
} // namespace Refactoring
Index: RenameTempRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/RenameTempRefactoring.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** RenameTempRefactoring.cpp 22 Dec 2002 16:03:52 -0000 1.14
--- RenameTempRefactoring.cpp 5 Apr 2003 12:14:45 -0000 1.15
***************
*** 73,95 ****
blanker.blank();
! int compoundStartIndex =
! ToolsBox::findCompoundBefore( blankedSource, temporaryLocation_ );
! if ( compoundStartIndex < 0 )
! throw RefactoringError( RefactoringError::temporaryNotInFunctionBody );
! sourceNode_ = SourceASTNode::create( blankedSource, source );
! ParseContext context( sourceNode_ );
! StatementParser parser( context,
! sourceNode_->getBlankedSourceStart() +
! compoundStartIndex,
! sourceNode_->getBlankedSourceEnd() );
! parser.parse();
! // don't bother with lazy parsing for now...
! MaxLODMutator mutator;
! mutator.mutate( sourceNode_, sourceNode_ );
! findLocaleVariableOccurrences();
}
--- 73,128 ----
blanker.blank();
! int start_at = temporaryLocation_;
! bool extend_scope = false;
! do
! {
! // find the compound statement where the temporary is located:
! int compoundStartIndex =
! ToolsBox::findCompoundBefore( blankedSource, start_at );
! if ( compoundStartIndex < 0 )
! throw RefactoringError( RefactoringError::temporaryNotInFunctionBody );
! // 'lazy' parse the source
! sourceNode_ = SourceASTNode::create( blankedSource, source );
! ParseContext context( sourceNode_ );
! StatementParser parser( context,
! sourceNode_->getBlankedSourceStart() +
! compoundStartIndex,
! sourceNode_->getBlankedSourceEnd() );
! try {
! parser.parse();
! // do mutate to highest level until we know how to do it 'lazy'
! MaxLODMutator mutator;
! mutator.mutate( sourceNode_, sourceNode_ );
! }
! catch (ParserError e)
! {
! // tried to parse outside a function body ?
! // TODO: is this change of the exception ok ? (AndreBaresel)
! throw RefactoringError( RefactoringError::identifierIsNotLocalVariable);
! }
! try {
! // find all occurrences of the temporary.
! findLocaleVariableOccurrences();
! extend_scope= false;
! }
! catch (RefactoringError e)
! {
! if (e.getCause() == RefactoringError::identifierIsNotLocalVariable)
! {
! start_at = compoundStartIndex-1;
! if (start_at>=0)
! {
! extend_scope= true;
! continue;
! }
! }
! throw e;
! }
! }
! while (extend_scope);
}
|