ClangRefactoring: Clear input files after collecting symbols

Change-Id: Ic4fbaac7ad3b3f80223d6cbb84a34dffa741fc4f
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2019-05-06 15:37:55 +02:00
parent 63c4428287
commit 98d7b502ca
3 changed files with 26 additions and 5 deletions

View File

@@ -129,7 +129,11 @@ bool SymbolsCollector::collectSymbols()
auto actionFactory = ClangBackEnd::newFrontendActionFactory(&m_collectSymbolsAction); auto actionFactory = ClangBackEnd::newFrontendActionFactory(&m_collectSymbolsAction);
return tool.run(actionFactory.get()) != 1; bool noErrors = tool.run(actionFactory.get()) != 1;
m_clangTool = ClangTool();
return noErrors;
} }
void SymbolsCollector::doInMainThreadAfterFinished() void SymbolsCollector::doInMainThreadAfterFinished()

View File

@@ -63,6 +63,8 @@ public:
bool isUsed() const override; bool isUsed() const override;
void setIsUsed(bool isUsed) override; void setIsUsed(bool isUsed) override;
bool isClean() const { return m_clangTool.isClean(); }
private: private:
FilePathCaching m_filePathCache; FilePathCaching m_filePathCache;
ClangTool m_clangTool; ClangTool m_clangTool;

View File

@@ -53,17 +53,18 @@ using testing::Value;
using testing::_; using testing::_;
using ClangBackEnd::FilePath; using ClangBackEnd::FilePath;
using ClangBackEnd::FilePathId;
using ClangBackEnd::FilePathCaching; using ClangBackEnd::FilePathCaching;
using ClangBackEnd::V2::FileContainers; using ClangBackEnd::FilePathId;
using ClangBackEnd::FileStatus;
using ClangBackEnd::SourceDependency; using ClangBackEnd::SourceDependency;
using ClangBackEnd::SourceLocationEntry; using ClangBackEnd::SourceLocationEntry;
using ClangBackEnd::SourceLocationKind;
using ClangBackEnd::SymbolEntry; using ClangBackEnd::SymbolEntry;
using ClangBackEnd::SymbolIndex;
using ClangBackEnd::SymbolKind; using ClangBackEnd::SymbolKind;
using ClangBackEnd::SymbolTag; using ClangBackEnd::SymbolTag;
using ClangBackEnd::SourceLocationKind;
using ClangBackEnd::SymbolIndex;
using ClangBackEnd::UsedMacro; using ClangBackEnd::UsedMacro;
using ClangBackEnd::V2::FileContainers;
using Sqlite::Database; using Sqlite::Database;
@@ -130,6 +131,9 @@ MATCHER_P(HasSymbolTag, symbolTag,
class SymbolsCollector : public testing::Test class SymbolsCollector : public testing::Test
{ {
protected: protected:
SymbolsCollector() { setFilePathCache(&filePathCache); }
~SymbolsCollector() { setFilePathCache({}); }
FilePathId filePathId(Utils::SmallStringView filePath) const FilePathId filePathId(Utils::SmallStringView filePath) const
{ {
return filePathCache.filePathId(ClangBackEnd::FilePathView{filePath}); return filePathCache.filePathId(ClangBackEnd::FilePathView{filePath});
@@ -664,4 +668,15 @@ TEST_F(SymbolsCollector, CollectReturnsFalseIfThereIsNoError)
ASSERT_TRUE(success); ASSERT_TRUE(success);
} }
TEST_F(SymbolsCollector, ClearInputFilesAfterCollectingSymbols)
{
collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main2.cpp"), {"cc"});
collector.collectSymbols();
collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"});
collector.collectSymbols();
ASSERT_TRUE(collector.isClean());
}
} // namespace } // namespace