From 7fb80595b94b02867f2cffc81f6e43fa173cda17 Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Tue, 24 Oct 2017 13:39:36 +0200 Subject: [PATCH] ClangRefactoring: use sourceUsagesAt instead of locationsAt Change-Id: I085b243b6e0ea4b786ce5c5f5a6894345f9d87eb Reviewed-by: Marco Bubke --- src/plugins/clangrefactoring/refactoringengine.cpp | 10 +--------- src/plugins/clangrefactoring/symbolqueryinterface.h | 3 +++ tests/unit/unittest/mocksymbolquery.h | 3 ++- tests/unit/unittest/refactoringengine-test.cpp | 8 ++++---- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/plugins/clangrefactoring/refactoringengine.cpp b/src/plugins/clangrefactoring/refactoringengine.cpp index d519e53156e..37ed6a871f5 100644 --- a/src/plugins/clangrefactoring/refactoringengine.cpp +++ b/src/plugins/clangrefactoring/refactoringengine.cpp @@ -98,15 +98,7 @@ CppTools::Usages RefactoringEngine::locationsAt(const CppTools::CursorInEditor & const QByteArray filePath = data.filePath().toString().toLatin1(); const ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(filePath.constData()); - ClangRefactoring::SourceLocations usages = m_symbolQuery.locationsAt(filePathId, line, - 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; + return m_symbolQuery.sourceUsagesAt(filePathId, line, column + 1); } void RefactoringEngine::globalRename(const CppTools::CursorInEditor &data, diff --git a/src/plugins/clangrefactoring/symbolqueryinterface.h b/src/plugins/clangrefactoring/symbolqueryinterface.h index c59f1f9c28e..1e0ab915924 100644 --- a/src/plugins/clangrefactoring/symbolqueryinterface.h +++ b/src/plugins/clangrefactoring/symbolqueryinterface.h @@ -27,12 +27,15 @@ #include "sourcelocations.h" +#include + namespace ClangRefactoring { class SymbolQueryInterface { public: 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 diff --git a/tests/unit/unittest/mocksymbolquery.h b/tests/unit/unittest/mocksymbolquery.h index 07282897280..5c954fd7e98 100644 --- a/tests/unit/unittest/mocksymbolquery.h +++ b/tests/unit/unittest/mocksymbolquery.h @@ -32,5 +32,6 @@ class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface { 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)); }; diff --git a/tests/unit/unittest/refactoringengine-test.cpp b/tests/unit/unittest/refactoringengine-test.cpp index e1d5e3cd5c0..1a7c0d3b920 100644 --- a/tests/unit/unittest/refactoringengine-test.cpp +++ b/tests/unit/unittest/refactoringengine-test.cpp @@ -105,21 +105,21 @@ TEST_F(RefactoringEngine, AfterSendRequestSourceLocationsForRenamingMessageIsUnu ASSERT_FALSE(engine.isRefactoringEngineAvailable()); } -TEST_F(RefactoringEngine, ExpectLocationsAtInFindUsages) +TEST_F(RefactoringEngine, ExpectSourceUsagesAtInFindUsages) { cursor.setPosition(11); - EXPECT_CALL(mockSymbolQuery, locationsAt(_, 2, 5)); + EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, 2, 5)); engine.findUsages(CppTools::CursorInEditor{cursor, filePath}, [](const CppTools::Usages &) {}); } -TEST_F(RefactoringEngine, ExpectLocationsAtInGlobalRename) +TEST_F(RefactoringEngine, ExpectSourceUsagesAtInGlobalRename) { cursor.setPosition(11); - EXPECT_CALL(mockSymbolQuery, locationsAt(_, 2, 5)); + EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, 2, 5)); engine.globalRename(CppTools::CursorInEditor{cursor, filePath}, [](const CppTools::Usages &) {}, QString());