Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2014-12-24 05:10:09 +0000
committerSergey Prigogin2014-12-24 05:18:40 +0000
commitf11fcce2ee2e6c74e5d3a2c3517f9f1e5ad3e63a (patch)
treeb714f33c20104c6d68eb3f71d0c6f40f51509ce9
parentf582de0a88d91e1431b6e9d4d924cd4f2846d0c5 (diff)
downloadorg.eclipse.cdt-f11fcce2ee2e6c74e5d3a2c3517f9f1e5ad3e63a.tar.gz
org.eclipse.cdt-f11fcce2ee2e6c74e5d3a2c3517f9f1e5ad3e63a.tar.xz
org.eclipse.cdt-f11fcce2ee2e6c74e5d3a2c3517f9f1e5ad3e63a.zip
Bug 456099. Corrected include replacement in partner files.
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMoveHeaderRefactoringTest.java4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/InclusionContext.java21
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileReferenceAdjuster.java16
3 files changed, 39 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMoveHeaderRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMoveHeaderRefactoringTest.java
index 3569960ec4..cab94c9702 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMoveHeaderRefactoringTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMoveHeaderRefactoringTest.java
@@ -295,9 +295,13 @@ public class RenameMoveHeaderRefactoringTest extends RefactoringTestBase {
// OriginalClass.cpp
//#include "OriginalClass.h"
+ //
+ //#include <cstdio>
//====================
// RenamedClass.cpp
//#include "RenamedClass.h"
+ //
+ //#include <cstdio>
// OriginalClass_test.cpp
//#include "OriginalClass.h"
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/InclusionContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/InclusionContext.java
index aace2938f3..37ff79e2ad 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/InclusionContext.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/InclusionContext.java
@@ -48,9 +48,11 @@ public class InclusionContext {
private final IncludePreferences fPreferences;
private String fSourceContents;
private String fLineDelimiter;
+ private IPath fTuLocation;
public InclusionContext(ITranslationUnit tu) {
fTu = tu;
+ fTuLocation = fTu.getLocation();
ICProject cProject = fTu.getCProject();
fProject = cProject.getProject();
fCurrentDirectory = fTu.getResource().getParent().getLocation();
@@ -245,7 +247,7 @@ public class InclusionContext {
* used for test files.
*/
public boolean isPartnerFile(IPath path) {
- return SourceHeaderPartnerFinder.isPartnerFile(getTranslationUnit().getLocation(), path,
+ return SourceHeaderPartnerFinder.isPartnerFile(getTranslationUnitLocation(), path,
fPreferences.partnerFileSuffixes);
}
@@ -292,4 +294,21 @@ public class InclusionContext {
}
return fLineDelimiter;
}
+
+ /**
+ * Sets the effective translation unit location that overrides the default value obtained by
+ * calling {@code getTranslationUnit().getLocation()}.
+ *
+ * @param location the file system location to set
+ */
+ public void setTranslationUnitLocation(IPath location) {
+ this.fTuLocation = location;
+ }
+
+ /**
+ * Returns the effective translation unit location.
+ */
+ public IPath getTranslationUnitLocation() {
+ return fTuLocation;
+ }
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileReferenceAdjuster.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileReferenceAdjuster.java
index f87ce5c3c7..388d72492c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileReferenceAdjuster.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileReferenceAdjuster.java
@@ -208,6 +208,11 @@ public class HeaderFileReferenceAdjuster {
private TextEdit createEdit(IASTTranslationUnit ast, ITranslationUnit tu, IProgressMonitor pm)
throws CoreException, OperationCanceledException {
IncludeCreationContext context = new IncludeCreationContext(tu, index);
+ // Adjust the translation unit location in the inclusion context.
+ IFile movedFile = movedFiles.get(tu.getFile());
+ if (movedFile != null)
+ context.setTranslationUnitLocation(movedFile.getLocation());
+
String contents = context.getSourceContents();
MultiTextEdit rootEdit = createIncludeGuardEdit(ast, tu, contents);
@@ -353,7 +358,7 @@ public class HeaderFileReferenceAdjuster {
} else {
if (previousInclude != null && affectedIncludes.containsKey(previousInclude.getExistingInclude()) &&
isBlankLineNeededBetween(previousInclude, include, preferences) &&
- TextUtil.findBlankLine(contents, offset, ASTNodes.offset(existingInclude)) < 0) {
+ TextUtil.findBlankLine(contents, skipDeletedRegion(offset, deletes), ASTNodes.offset(existingInclude)) < 0) {
text.append(context.getLineDelimiter());
}
flushEditBuffer(offset, text, deletes, rootEdit);
@@ -434,6 +439,15 @@ public class HeaderFileReferenceAdjuster {
}
}
+ private int skipDeletedRegion(int offset, Deque<DeleteEdit> deletes) {
+ for (DeleteEdit edit : deletes) {
+ if (edit.getOffset() > offset)
+ break;
+ offset = edit.getExclusiveEnd();
+ }
+ return offset;
+ }
+
private void lockIndex() throws CoreException, OperationCanceledException {
if (indexLockCount == 0) {
if (index == null) {

Back to the top