mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 04:15:35 +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:
parent
baf4816657
commit
0dfdf444dd
3 changed files with 42 additions and 5 deletions
|
@ -2564,3 +2564,31 @@ int main() {
|
||||||
return 0;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -714,8 +714,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTStatement stmt) {
|
public int visit(IASTStatement stmt) {
|
||||||
if (!(stmt instanceof IASTCompoundStatement)
|
if ( SelectionHelper.isSelectedFile(region, stmt, file)) {
|
||||||
&& SelectionHelper.isSelectedFile(region, stmt, file)) {
|
|
||||||
container.add(stmt);
|
container.add(stmt);
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,15 +105,25 @@ public class SelectionHelper {
|
||||||
|
|
||||||
protected static Region createExpressionPosition(IASTNode expression) {
|
protected static Region createExpressionPosition(IASTNode expression) {
|
||||||
|
|
||||||
int start = 0;
|
int start = Integer.MAX_VALUE;
|
||||||
int nodeLength = 0;
|
int nodeLength = 0;
|
||||||
IASTNodeLocation[] nodeLocations = expression.getNodeLocations();
|
IASTNodeLocation[] nodeLocations = expression.getNodeLocations();
|
||||||
if (nodeLocations.length != 1) {
|
if (nodeLocations.length != 1) {
|
||||||
for (IASTNodeLocation location : nodeLocations) {
|
for (IASTNodeLocation location : nodeLocations) {
|
||||||
if (location instanceof IASTMacroExpansionLocation) {
|
if (location instanceof IASTMacroExpansionLocation) {
|
||||||
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
|
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
|
||||||
start = macroLoc.asFileLocation().getNodeOffset();
|
int nodeOffset = macroLoc.asFileLocation().getNodeOffset();
|
||||||
nodeLength = macroLoc.asFileLocation().getNodeLength();
|
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 {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue