forked from qt-creator/qt-creator
ClangRefactoring: use sourceUsagesAt instead of locationsAt
Change-Id: I085b243b6e0ea4b786ce5c5f5a6894345f9d87eb Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -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,
|
||||||
|
@@ -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
|
||||||
|
@@ -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));
|
||||||
};
|
};
|
||||||
|
@@ -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());
|
||||||
|
Reference in New Issue
Block a user