mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 456099. Corrected include replacement in partner files.
This commit is contained in:
parent
f582de0a88
commit
f11fcce2ee
3 changed files with 39 additions and 2 deletions
|
@ -295,9 +295,13 @@ public class RenameMoveHeaderRefactoringTest extends RefactoringTestBase {
|
||||||
|
|
||||||
// OriginalClass.cpp
|
// OriginalClass.cpp
|
||||||
//#include "OriginalClass.h"
|
//#include "OriginalClass.h"
|
||||||
|
//
|
||||||
|
//#include <cstdio>
|
||||||
//====================
|
//====================
|
||||||
// RenamedClass.cpp
|
// RenamedClass.cpp
|
||||||
//#include "RenamedClass.h"
|
//#include "RenamedClass.h"
|
||||||
|
//
|
||||||
|
//#include <cstdio>
|
||||||
|
|
||||||
// OriginalClass_test.cpp
|
// OriginalClass_test.cpp
|
||||||
//#include "OriginalClass.h"
|
//#include "OriginalClass.h"
|
||||||
|
|
|
@ -48,9 +48,11 @@ public class InclusionContext {
|
||||||
private final IncludePreferences fPreferences;
|
private final IncludePreferences fPreferences;
|
||||||
private String fSourceContents;
|
private String fSourceContents;
|
||||||
private String fLineDelimiter;
|
private String fLineDelimiter;
|
||||||
|
private IPath fTuLocation;
|
||||||
|
|
||||||
public InclusionContext(ITranslationUnit tu) {
|
public InclusionContext(ITranslationUnit tu) {
|
||||||
fTu = tu;
|
fTu = tu;
|
||||||
|
fTuLocation = fTu.getLocation();
|
||||||
ICProject cProject = fTu.getCProject();
|
ICProject cProject = fTu.getCProject();
|
||||||
fProject = cProject.getProject();
|
fProject = cProject.getProject();
|
||||||
fCurrentDirectory = fTu.getResource().getParent().getLocation();
|
fCurrentDirectory = fTu.getResource().getParent().getLocation();
|
||||||
|
@ -245,7 +247,7 @@ public class InclusionContext {
|
||||||
* used for test files.
|
* used for test files.
|
||||||
*/
|
*/
|
||||||
public boolean isPartnerFile(IPath path) {
|
public boolean isPartnerFile(IPath path) {
|
||||||
return SourceHeaderPartnerFinder.isPartnerFile(getTranslationUnit().getLocation(), path,
|
return SourceHeaderPartnerFinder.isPartnerFile(getTranslationUnitLocation(), path,
|
||||||
fPreferences.partnerFileSuffixes);
|
fPreferences.partnerFileSuffixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,4 +294,21 @@ public class InclusionContext {
|
||||||
}
|
}
|
||||||
return fLineDelimiter;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -208,6 +208,11 @@ public class HeaderFileReferenceAdjuster {
|
||||||
private TextEdit createEdit(IASTTranslationUnit ast, ITranslationUnit tu, IProgressMonitor pm)
|
private TextEdit createEdit(IASTTranslationUnit ast, ITranslationUnit tu, IProgressMonitor pm)
|
||||||
throws CoreException, OperationCanceledException {
|
throws CoreException, OperationCanceledException {
|
||||||
IncludeCreationContext context = new IncludeCreationContext(tu, index);
|
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();
|
String contents = context.getSourceContents();
|
||||||
|
|
||||||
MultiTextEdit rootEdit = createIncludeGuardEdit(ast, tu, contents);
|
MultiTextEdit rootEdit = createIncludeGuardEdit(ast, tu, contents);
|
||||||
|
@ -353,7 +358,7 @@ public class HeaderFileReferenceAdjuster {
|
||||||
} else {
|
} else {
|
||||||
if (previousInclude != null && affectedIncludes.containsKey(previousInclude.getExistingInclude()) &&
|
if (previousInclude != null && affectedIncludes.containsKey(previousInclude.getExistingInclude()) &&
|
||||||
isBlankLineNeededBetween(previousInclude, include, preferences) &&
|
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());
|
text.append(context.getLineDelimiter());
|
||||||
}
|
}
|
||||||
flushEditBuffer(offset, text, deletes, rootEdit);
|
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 {
|
private void lockIndex() throws CoreException, OperationCanceledException {
|
||||||
if (indexLockCount == 0) {
|
if (indexLockCount == 0) {
|
||||||
if (index == null) {
|
if (index == null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue