Commit 205170a9 authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Erik Verbruggen

CppTools: Create ProjectInfos explicitly

...instead of going through CppModelManager::projectInfo().

Now CppModelManager::projectInfo() returns an invalid ProjectInfo in
case there is no valid data for the given Project.

Change-Id: I11908bf2ddf865b1d3d71ff176eaf4139292b21c
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent be7d63c9
......@@ -408,9 +408,7 @@ void AutotoolsProject::updateCppCodeModel()
return;
m_codeModelFuture.cancel();
CppTools::ProjectInfo pInfo = modelManager->projectInfo(this);
pInfo.clearProjectParts();
CppTools::ProjectInfo pInfo = CppTools::ProjectInfo(this);
CppTools::ProjectPartBuilder ppBuilder(pInfo);
const QStringList cflags = m_makefileParserThread->cflags();
......
......@@ -314,9 +314,7 @@ bool CMakeProject::parseCMakeLists()
CppTools::CppModelManager *modelmanager =
CppTools::CppModelManager::instance();
if (modelmanager) {
CppTools::ProjectInfo pinfo = modelmanager->projectInfo(this);
pinfo.clearProjectParts();
CppTools::ProjectInfo pinfo = CppTools::ProjectInfo(this);
CppTools::ProjectPartBuilder ppBuilder(pinfo);
foreach (const CMakeBuildTarget &cbt, m_buildTargets) {
......
......@@ -590,7 +590,7 @@ QList<ProjectInfo> CppModelManager::projectInfos() const
ProjectInfo CppModelManager::projectInfo(ProjectExplorer::Project *project) const
{
QMutexLocker locker(&d->m_projectMutex);
return d->m_projectToProjectsInfo.value(project, ProjectInfo(project));
return d->m_projectToProjectsInfo.value(project, ProjectInfo());
}
/// \brief Remove all files and their includes (recursively) of given ProjectInfo from the snapshot.
......
......@@ -94,8 +94,7 @@ public:
projectFiles << projectDir.file(file);
Project *project = modelManagerTestHelper->createProject(name);
projectInfo = CppModelManager::instance()->projectInfo(project);
QCOMPARE(projectInfo.project().data(), project);
projectInfo = ProjectInfo(project);
ProjectPart::Ptr part(new ProjectPart);
part->languageVersion = ProjectPart::CXX14;
......@@ -215,8 +214,7 @@ void CppToolsPlugin::test_modelmanager_paths_are_clean()
const MyTestDataDir testDataDir(_("testdata"));
Project *project = helper.createProject(_("test_modelmanager_paths_are_clean"));
ProjectInfo pi = mm->projectInfo(project);
QCOMPARE(pi.project().data(), project);
ProjectInfo pi = ProjectInfo(project);
typedef ProjectPart::HeaderPath HeaderPath;
......@@ -251,8 +249,7 @@ void CppToolsPlugin::test_modelmanager_framework_headers()
const MyTestDataDir testDataDir(_("testdata"));
Project *project = helper.createProject(_("test_modelmanager_framework_headers"));
ProjectInfo pi = mm->projectInfo(project);
QCOMPARE(pi.project().data(), project);
ProjectInfo pi = ProjectInfo(project);
typedef ProjectPart::HeaderPath HeaderPath;
......@@ -304,8 +301,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
Project *project = helper.createProject(
_("test_modelmanager_refresh_also_includes_of_project_files"));
ProjectInfo pi = mm->projectInfo(project);
QCOMPARE(pi.project().data(), project);
ProjectInfo pi = ProjectInfo(project);
typedef ProjectPart::HeaderPath HeaderPath;
......@@ -333,7 +329,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
// Introduce a define that will enable another define once the document is reparsed.
part->projectDefines = QByteArray("#define TEST_DEFINE 1\n");
pi.clearProjectParts();
pi = ProjectInfo(project);
pi.appendProjectPart(part);
pi.finish();
......@@ -367,8 +363,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times()
const QString testCpp(testDataDir.file(_("source.cpp")));
Project *project = helper.createProject(_("test_modelmanager_refresh_several_times"));
ProjectInfo pi = mm->projectInfo(project);
QCOMPARE(pi.project().data(), project);
ProjectInfo pi = ProjectInfo(project);
ProjectPart::Ptr part(new ProjectPart);
part->languageVersion = ProjectPart::CXX14;
......@@ -386,7 +381,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times()
QByteArray defines = "#define FIRST_DEFINE";
for (int i = 0; i < 2; ++i) {
pi.clearProjectParts();
pi = ProjectInfo(project);
ProjectPart::Ptr part(new ProjectPart);
// Simulate project configuration change by having different defines each time.
defines += "\n#define ANOTHER_DEFINE";
......@@ -434,8 +429,7 @@ void CppToolsPlugin::test_modelmanager_refresh_test_for_changes()
const QString testCpp(testDataDir.file(_("source.cpp")));
Project *project = helper.createProject(_("test_modelmanager_refresh_2"));
ProjectInfo pi = mm->projectInfo(project);
QCOMPARE(pi.project().data(), project);
ProjectInfo pi = ProjectInfo(project);
ProjectPart::Ptr part(new ProjectPart);
part->languageVersion = ProjectPart::CXX14;
......@@ -472,8 +466,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed()
const QString testCpp(testDataDir.file(_("source.cpp")));
Project *project = helper.createProject(_("test_modelmanager_refresh_3"));
ProjectInfo pi = mm->projectInfo(project);
QCOMPARE(pi.project().data(), project);
ProjectInfo pi = ProjectInfo(project);
ProjectPart::Ptr part(new ProjectPart);
part->languageVersion = ProjectPart::CXX14;
......@@ -497,7 +490,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed()
QVERIFY(snapshot.contains(testCpp));
// Now add testHeader2 and remove testHeader1
pi.clearProjectParts();
pi = ProjectInfo(project);
ProjectPart::Ptr newPart(new ProjectPart);
newPart->languageVersion = ProjectPart::CXX14;
newPart->qtVersion = ProjectPart::Qt5;
......@@ -531,15 +524,14 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_
CppModelManager *mm = CppModelManager::instance();
Project *project = helper.createProject(_("test_modelmanager_refresh_timeStampModified"));
ProjectInfo pi = mm->projectInfo(project);
QCOMPARE(pi.project().data(), project);
ProjectInfo pi = ProjectInfo(project);
ProjectPart::Ptr part(new ProjectPart);
part->languageVersion = ProjectPart::CXX14;
part->qtVersion = ProjectPart::Qt5;
foreach (const ProjectFile &file, initialProjectFiles)
part->files.append(file);
pi.clearProjectParts();
pi = ProjectInfo(project);
pi.appendProjectPart(part);
pi.finish();
......@@ -573,7 +565,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_
part->files.clear();
foreach (const ProjectFile &file, finalProjectFiles)
part->files.append(file);
pi.clearProjectParts();
pi = ProjectInfo(project);
pi.appendProjectPart(part);
pi.finish();
......@@ -844,7 +836,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
part2->headerPaths = QList<HeaderPath>()
<< HeaderPath(testDataDirectory.includeDir(false), HeaderPath::IncludePath);
ProjectInfo pi = mm->projectInfo(project);
ProjectInfo pi = ProjectInfo(project);
pi.appendProjectPart(part1);
pi.appendProjectPart(part2);
pi.finish();
......@@ -915,7 +907,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
part2->headerPaths = QList<HeaderPath>()
<< HeaderPath(testDataDirectory.includeDir(false), HeaderPath::IncludePath);
ProjectInfo pi = mm->projectInfo(project);
ProjectInfo pi = ProjectInfo(project);
pi.appendProjectPart(part1);
pi.appendProjectPart(part2);
pi.finish();
......@@ -997,7 +989,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
part2->headerPaths = QList<HeaderPath>()
<< HeaderPath(testDataDirectory.includeDir(false), HeaderPath::IncludePath);
ProjectInfo pi = mm->projectInfo(project);
ProjectInfo pi = ProjectInfo(project);
pi.appendProjectPart(part1);
pi.appendProjectPart(part2);
pi.finish();
......@@ -1081,7 +1073,7 @@ void CppToolsPlugin::test_modelmanager_updateEditorsAfterProjectUpdate()
part->languageVersion = ProjectPart::CXX11;
part->qtVersion = ProjectPart::NoQt;
ProjectInfo pi = mm->projectInfo(project);
ProjectInfo pi = ProjectInfo(project);
pi.appendProjectPart(part);
pi.finish();
updateProjectInfo(mm, &helper, pi);
......
......@@ -218,15 +218,6 @@ void ProjectInfo::finish()
}
}
void ProjectInfo::clearProjectParts()
{
m_projectParts.clear();
m_headerPaths.clear();
m_sourceFiles.clear();
m_defines.clear();
m_compilerCallData.clear();
}
const ProjectPart::HeaderPaths ProjectInfo::headerPaths() const
{
return m_headerPaths;
......
......@@ -154,7 +154,6 @@ public:
void appendProjectPart(const ProjectPart::Ptr &part);
void finish();
void clearProjectParts();
const ProjectPart::HeaderPaths headerPaths() const;
const QSet<QString> sourceFiles() const;
......
......@@ -352,9 +352,7 @@ void GenericProject::refreshCppCodeModel()
m_codeModelFuture.cancel();
CppTools::ProjectInfo pInfo = modelManager->projectInfo(this);
pInfo.clearProjectParts();
CppTools::ProjectInfo pInfo = CppTools::ProjectInfo(this);
CppTools::ProjectPartBuilder ppBuilder(pInfo);
ppBuilder.setIncludePaths(projectIncludePaths());
ppBuilder.setConfigFileName(configFileName());
......
......@@ -109,7 +109,6 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
m_qbsUpdateFutureInterface(0),
m_parsingScheduled(false),
m_cancelStatus(CancelStatusNone),
m_codeModelProjectInfo(this),
m_currentBc(0)
{
m_parsingDelay.setInterval(1000); // delay parsing by 1s.
......@@ -693,9 +692,7 @@ void QbsProject::updateCppCodeModel()
if (!modelmanager)
return;
CppTools::ProjectInfo pinfo = modelmanager->projectInfo(this);
pinfo.clearProjectParts();
CppTools::ProjectInfo pinfo = CppTools::ProjectInfo(this);
CppTools::ProjectPartBuilder ppBuilder(pinfo);
if (qtVersion) {
......@@ -791,6 +788,7 @@ void QbsProject::updateCppCodeModel()
m_codeModelFuture.cancel();
m_codeModelFuture = modelmanager->updateProjectInfo(pinfo);
m_codeModelProjectInfo = modelmanager->projectInfo(this);
QTC_CHECK(m_codeModelProjectInfo == pinfo);
}
void QbsProject::updateCppCompilerCallData()
......
......@@ -493,8 +493,8 @@ void QmakeProject::updateCppCodeModel()
FindQmakeProFiles findQmakeProFiles;
QList<QmakeProFileNode *> proFiles = findQmakeProFiles(rootProjectNode());
CppTools::ProjectInfo pinfo = modelmanager->projectInfo(this);
pinfo.clearProjectParts();
CppTools::ProjectInfo pinfo = CppTools::ProjectInfo(this);
ProjectPart::QtVersion qtVersionForPart = ProjectPart::NoQt;
if (qtVersion) {
if (qtVersion->qtVersion() < QtSupport::QtVersionNumber(5,0,0))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment