ClangRefactoring: use sourceUsagesAt instead of locationsAt

Change-Id: I085b243b6e0ea4b786ce5c5f5a6894345f9d87eb
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2017-10-24 13:39:36 +02:00
parent 327b368ab6
commit 7fb80595b9
4 changed files with 10 additions and 14 deletions

View File

@@ -98,15 +98,7 @@ CppTools::Usages RefactoringEngine::locationsAt(const CppTools::CursorInEditor &
const QByteArray filePath = data.filePath().toString().toLatin1(); const QByteArray filePath = data.filePath().toString().toLatin1();
const ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(filePath.constData()); const ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(filePath.constData());
ClangRefactoring::SourceLocations usages = m_symbolQuery.locationsAt(filePathId, line, return m_symbolQuery.sourceUsagesAt(filePathId, line, column + 1);
column + 1);
CppTools::Usages result;
result.reserve(usages.size());
for (const auto &location : usages) {
const Utils::SmallStringView path = m_filePathCache.filePath(location.filePathId).path();
result.push_back({path, location.line, location.column});
}
return result;
} }
void RefactoringEngine::globalRename(const CppTools::CursorInEditor &data, void RefactoringEngine::globalRename(const CppTools::CursorInEditor &data,

View File

@@ -27,12 +27,15 @@
#include "sourcelocations.h" #include "sourcelocations.h"
#include <cpptools/usages.h>
namespace ClangRefactoring { namespace ClangRefactoring {
class SymbolQueryInterface class SymbolQueryInterface
{ {
public: public:
virtual SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) = 0; virtual SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) = 0;
virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) = 0;
}; };
} // namespace ClangRefactoring } // namespace ClangRefactoring

View File

@@ -32,5 +32,6 @@
class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface
{ {
public: public:
MOCK_METHOD3(locationsAt, ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); MOCK_METHOD3(locationsAt, ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column));
MOCK_METHOD3(sourceUsagesAt, CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column));
}; };

View File

@@ -105,21 +105,21 @@ TEST_F(RefactoringEngine, AfterSendRequestSourceLocationsForRenamingMessageIsUnu
ASSERT_FALSE(engine.isRefactoringEngineAvailable()); ASSERT_FALSE(engine.isRefactoringEngineAvailable());
} }
TEST_F(RefactoringEngine, ExpectLocationsAtInFindUsages) TEST_F(RefactoringEngine, ExpectSourceUsagesAtInFindUsages)
{ {
cursor.setPosition(11); cursor.setPosition(11);
EXPECT_CALL(mockSymbolQuery, locationsAt(_, 2, 5)); EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, 2, 5));
engine.findUsages(CppTools::CursorInEditor{cursor, filePath}, engine.findUsages(CppTools::CursorInEditor{cursor, filePath},
[](const CppTools::Usages &) {}); [](const CppTools::Usages &) {});
} }
TEST_F(RefactoringEngine, ExpectLocationsAtInGlobalRename) TEST_F(RefactoringEngine, ExpectSourceUsagesAtInGlobalRename)
{ {
cursor.setPosition(11); cursor.setPosition(11);
EXPECT_CALL(mockSymbolQuery, locationsAt(_, 2, 5)); EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, 2, 5));
engine.globalRename(CppTools::CursorInEditor{cursor, filePath}, engine.globalRename(CppTools::CursorInEditor{cursor, filePath},
[](const CppTools::Usages &) {}, QString()); [](const CppTools::Usages &) {}, QString());