summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Tooling/Refactoring.cpp14
-rw-r--r--clang/unittests/Tooling/RefactoringTest.cpp46
2 files changed, 4 insertions, 56 deletions
diff --git a/clang/lib/Tooling/Refactoring.cpp b/clang/lib/Tooling/Refactoring.cpp
index 175dbd42ace..9e58db0f482 100644
--- a/clang/lib/Tooling/Refactoring.cpp
+++ b/clang/lib/Tooling/Refactoring.cpp
@@ -107,16 +107,10 @@ void Replacement::setFromSourceLocation(SourceManager &Sources,
const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first);
if (Entry != NULL) {
// Make FilePath absolute so replacements can be applied correctly when
- // relative paths for files are used. But we don't want to change virtual
- // files.
- if (llvm::sys::fs::exists(Entry->getName())) {
- llvm::SmallString<256> FilePath(Entry->getName());
- llvm::sys::fs::make_absolute(FilePath);
- this->FilePath = FilePath.c_str();
- }
- else {
- this->FilePath = Entry->getName();
- }
+ // relative paths for files are used.
+ llvm::SmallString<256> FilePath(Entry->getName());
+ llvm::error_code EC = llvm::sys::fs::make_absolute(FilePath);
+ this->FilePath = EC ? FilePath.c_str() : Entry->getName();
} else {
this->FilePath = InvalidLocation;
}
diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp
index 004ab2aa784..8c7bfa1c767 100644
--- a/clang/unittests/Tooling/RefactoringTest.cpp
+++ b/clang/unittests/Tooling/RefactoringTest.cpp
@@ -244,10 +244,6 @@ public:
return Context.Sources.createFileID(File, SourceLocation(), SrcMgr::C_User);
}
- StringRef getFilePath(llvm::StringRef Name) {
- return TemporaryFiles.lookup(Name);
- }
-
std::string getFileContentFromDisk(llvm::StringRef Name) {
std::string Path = TemporaryFiles.lookup(Name);
assert(!Path.empty());
@@ -274,48 +270,6 @@ TEST_F(FlushRewrittenFilesTest, StoresChangesOnDisk) {
getFileContentFromDisk("input.cpp"));
}
-TEST_F(FlushRewrittenFilesTest, GetFilePath) {
- // Create a temporary file.
- createFile("input.cpp", "line1\nline2\nline3\nline4");
- StringRef FilePath = getFilePath("input.cpp");
- StringRef TempPath = llvm::sys::path::parent_path(FilePath);
- StringRef TempFile = llvm::sys::path::filename(FilePath);
-
- // Save current path.
- SmallString<512> CurrentPath;
- llvm::sys::fs::current_path(CurrentPath);
-
- // Change directory to the temporary directory.
- EXPECT_EQ(0, chdir(TempPath.str().c_str()));
-
- // Get a FileEntry from the current directory.
- FileManager Files((FileSystemOptions()));
- const FileEntry *Entry = Files.getFile(TempFile);
- ASSERT_TRUE(Entry != NULL);
-
- FileID ID = Context.Sources.createFileID(Entry, SourceLocation(),
- SrcMgr::C_User);
-
- Replacement R = Replacement(Context.Sources, Context.getLocation(ID, 2, 1),
- 5, "replaced");
-
- // Change back to the original path so we can verify that replacements
- // are being applied independently of the location.
- EXPECT_EQ(0, chdir(CurrentPath.c_str()));
-
- // We expect that the file path of the replacement is using an absolute path
- EXPECT_TRUE(llvm::sys::fs::equivalent(R.getFilePath(),
- getFilePath("input.cpp")));
-
- // Apply replacements.
- Replacements Replaces;
- Replaces.insert(R);
- EXPECT_TRUE(applyAllReplacements(Replaces, Context.Rewrite));
- EXPECT_FALSE(Context.Rewrite.overwriteChangedFiles());
- EXPECT_EQ("line1\nreplaced\nline3\nline4",
- getFileContentFromDisk("input.cpp"));
-}
-
namespace {
template <typename T>
class TestVisitor : public clang::RecursiveASTVisitor<T> {
OpenPOWER on IntegriCloud