mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed MalformedTreeException.
This commit is contained in:
parent
349cdb089d
commit
f92fff3e50
2 changed files with 50 additions and 15 deletions
|
@ -460,7 +460,7 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
IFile file = FileHelper.getFileFromNode(anchorNode);
|
IFile file = FileHelper.getFileFromNode(anchorNode);
|
||||||
MultiTextEdit parentEdit = getEdit(anchorNode, file);
|
MultiTextEdit parentEdit = getEdit(anchorNode, file);
|
||||||
parentEdit.addChild(edit);
|
parentEdit.addChild(edit);
|
||||||
sourceOffsets.put(file.getName(), Integer.valueOf(edit.getOffset()));
|
sourceOffsets.put(file.getName(), edit.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleReplace(IASTNode node) {
|
private void handleReplace(IASTNode node) {
|
||||||
|
@ -469,10 +469,13 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
TextEdit edit;
|
TextEdit edit;
|
||||||
ChangeGeneratorWriterVisitor writer =
|
ChangeGeneratorWriterVisitor writer =
|
||||||
new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
|
new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
|
||||||
|
IASTFileLocation fileLocation = node.getFileLocation();
|
||||||
|
Integer val = sourceOffsets.get(fileLocation.getFileName());
|
||||||
|
int processedOffset = val != null ? val.intValue() : 0;
|
||||||
if (modifications.size() == 1 && modifications.get(0).getNewNode() == null) {
|
if (modifications.size() == 1 && modifications.get(0).getNewNode() == null) {
|
||||||
int offset = getOffsetIncludingComments(node);
|
int offset = getOffsetIncludingComments(node);
|
||||||
int endOffset = getEndOffsetIncludingComments(node);
|
int endOffset = getEndOffsetIncludingComments(node);
|
||||||
offset = skipPrecedingBlankLines(source, offset);
|
offset = Math.max(skipPrecedingBlankLines(source, offset), processedOffset);
|
||||||
endOffset = skipTrailingBlankLines(source, endOffset);
|
endOffset = skipTrailingBlankLines(source, endOffset);
|
||||||
IASTNode[] siblingsList = getContainingNodeList(node);
|
IASTNode[] siblingsList = getContainingNodeList(node);
|
||||||
if (siblingsList != null) {
|
if (siblingsList != null) {
|
||||||
|
@ -500,9 +503,8 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
} else {
|
} else {
|
||||||
node.accept(writer);
|
node.accept(writer);
|
||||||
String code = writer.toString();
|
String code = writer.toString();
|
||||||
IASTFileLocation location = node.getFileLocation();
|
int offset = fileLocation.getNodeOffset();
|
||||||
int offset = location.getNodeOffset();
|
int endOffset = offset + fileLocation.getNodeLength();
|
||||||
int endOffset = offset + location.getNodeLength();
|
|
||||||
if (node instanceof IASTStatement || node instanceof IASTDeclaration) {
|
if (node instanceof IASTStatement || node instanceof IASTDeclaration) {
|
||||||
// Include trailing comments in the area to be replaced.
|
// Include trailing comments in the area to be replaced.
|
||||||
endOffset = Math.max(endOffset, getEndOffsetIncludingTrailingComments(node));
|
endOffset = Math.max(endOffset, getEndOffsetIncludingTrailingComments(node));
|
||||||
|
@ -517,9 +519,7 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
MultiTextEdit parentEdit = getEdit(node, file);
|
MultiTextEdit parentEdit = getEdit(node, file);
|
||||||
parentEdit.addChild(edit);
|
parentEdit.addChild(edit);
|
||||||
|
|
||||||
IASTFileLocation fileLocation = node.getFileLocation();
|
sourceOffsets.put(fileLocation.getFileName(), edit.getExclusiveEnd());
|
||||||
int newOffset = fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
|
||||||
sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAppends(IASTNode node) {
|
private void handleAppends(IASTNode node) {
|
||||||
|
@ -553,8 +553,7 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
code + anchor.getText());
|
code + anchor.getText());
|
||||||
parentEdit.addChild(edit);
|
parentEdit.addChild(edit);
|
||||||
IASTFileLocation fileLocation = node.getFileLocation();
|
IASTFileLocation fileLocation = node.getFileLocation();
|
||||||
int newOffset = fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
sourceOffsets.put(fileLocation.getFileName(), endOffset(fileLocation));
|
||||||
sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAppends(IASTTranslationUnit tu) {
|
private void handleAppends(IASTTranslationUnit tu) {
|
||||||
|
|
|
@ -2512,24 +2512,60 @@ visibility=public
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||||
//@main.c
|
//@main.c
|
||||||
int main() {
|
int main() {
|
||||||
int a,b;
|
int a, b;
|
||||||
/*$*/a = b*2;/*$$*/
|
/*$*/a = b * 2;/*$$*/
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
//=
|
//=
|
||||||
void test(int* a, int b) {
|
void test(int* a, int b) {
|
||||||
a = b * 2;
|
a = b * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int a,b;
|
int a, b;
|
||||||
test(a, b);
|
test(a, b);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
//@.config
|
//@.config
|
||||||
filename=main.c
|
filename=main.c
|
||||||
methodname=test
|
methodname=test
|
||||||
replaceduplicates=false
|
replaceduplicates=false
|
||||||
returnvalue=false
|
returnvalue=false
|
||||||
|
|
||||||
|
//!Handling of blank lines
|
||||||
|
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||||
|
//@main.c
|
||||||
|
int main() {
|
||||||
|
int f;
|
||||||
|
/*$*/int a = 0;
|
||||||
|
int b = 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
int c = a + b;
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
}/*$$*/
|
||||||
|
|
||||||
|
f = b;
|
||||||
|
}
|
||||||
|
//=
|
||||||
|
int fib() {
|
||||||
|
int a = 0;
|
||||||
|
int b = 1;
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
int c = a + b;
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int f;
|
||||||
|
int b = fib();
|
||||||
|
f = b;
|
||||||
|
}
|
||||||
|
//@.config
|
||||||
|
filename=main.c
|
||||||
|
methodname=fib
|
||||||
|
replaceduplicates=false
|
||||||
|
|
Loading…
Add table
Reference in a new issue