1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

FIXED - bug 262000: refactoring "extract function" misinterprets artificial blocks

https://bugs.eclipse.org/bugs/show_bug.cgi?id=262000
This commit is contained in:
Emanuel Graf 2009-01-22 14:07:20 +00:00
parent baf4816657
commit 0dfdf444dd
3 changed files with 42 additions and 5 deletions

View file

@ -2564,3 +2564,31 @@ int main() {
return 0;
}
//!Bug#262000 refactoring "extract function" misinterprets artificial blocks
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config
filename=main.cpp
methodname=exp
//@main.cpp
int main(int argc, char **argv) {
/*$*/int a = 0;
{
a++;
}/*$$*/
}
//=
void exp()
{
int a = 0;
{
a++;
}
}
int main(int argc, char **argv) {
exp();
}

View file

@ -714,8 +714,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
@Override
public int visit(IASTStatement stmt) {
if (!(stmt instanceof IASTCompoundStatement)
&& SelectionHelper.isSelectedFile(region, stmt, file)) {
if ( SelectionHelper.isSelectedFile(region, stmt, file)) {
container.add(stmt);
return PROCESS_SKIP;
}

View file

@ -105,15 +105,25 @@ public class SelectionHelper {
protected static Region createExpressionPosition(IASTNode expression) {
int start = 0;
int start = Integer.MAX_VALUE;
int nodeLength = 0;
IASTNodeLocation[] nodeLocations = expression.getNodeLocations();
if (nodeLocations.length != 1) {
for (IASTNodeLocation location : nodeLocations) {
if (location instanceof IASTMacroExpansionLocation) {
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
start = macroLoc.asFileLocation().getNodeOffset();
nodeLength = macroLoc.asFileLocation().getNodeLength();
int nodeOffset = macroLoc.asFileLocation().getNodeOffset();
if(nodeOffset < start) {
start = nodeOffset;
}
nodeLength += macroLoc.asFileLocation().getNodeLength();
}else {
IASTFileLocation loc = expression.getFileLocation();
int nodeOffset = loc.getNodeOffset();
if(nodeOffset < start) {
start = nodeOffset;
}
nodeLength = loc.getNodeLength();
}
}
} else {