forked from qt-creator/qt-creator
CppTools: Clean up ProjectInfo
Change-Id: I5d0db45d9fdb624bb6cc55d7f04061d553f13bce Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -58,7 +58,7 @@ void completeBasicProjectInformation(Project *project, const QString &proFile, Q
|
|||||||
Project **targetProject)
|
Project **targetProject)
|
||||||
{
|
{
|
||||||
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
||||||
QList<CppTools::ProjectPart::Ptr> projParts = cppMM->projectInfo(project).projectParts();
|
QVector<CppTools::ProjectPart::Ptr> projParts = cppMM->projectInfo(project).projectParts();
|
||||||
|
|
||||||
if (displayName->isEmpty()) {
|
if (displayName->isEmpty()) {
|
||||||
foreach (const CppTools::ProjectPart::Ptr &part, projParts) {
|
foreach (const CppTools::ProjectPart::Ptr &part, projParts) {
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ static ClangBackEnd::ProjectPartContainer toProjectPartContainer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static QVector<ClangBackEnd::ProjectPartContainer> toProjectPartContainers(
|
static QVector<ClangBackEnd::ProjectPartContainer> toProjectPartContainers(
|
||||||
const QList<CppTools::ProjectPart::Ptr> projectParts)
|
const QVector<CppTools::ProjectPart::Ptr> projectParts)
|
||||||
{
|
{
|
||||||
QVector<ClangBackEnd::ProjectPartContainer> projectPartContainers;
|
QVector<ClangBackEnd::ProjectPartContainer> projectPartContainers;
|
||||||
projectPartContainers.reserve(projectParts.size());
|
projectPartContainers.reserve(projectParts.size());
|
||||||
@@ -527,7 +527,7 @@ void IpcCommunicator::registerCurrentCodeModelUiHeaders()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IpcCommunicator::registerProjectsParts(const QList<CppTools::ProjectPart::Ptr> projectParts)
|
void IpcCommunicator::registerProjectsParts(const QVector<CppTools::ProjectPart::Ptr> projectParts)
|
||||||
{
|
{
|
||||||
const auto projectPartContainers = toProjectPartContainers(projectParts);
|
const auto projectPartContainers = toProjectPartContainers(projectParts);
|
||||||
registerProjectPartsForEditor(projectPartContainers);
|
registerProjectPartsForEditor(projectPartContainers);
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public:
|
|||||||
quint32 column,
|
quint32 column,
|
||||||
const QString &projectFilePath);
|
const QString &projectFilePath);
|
||||||
|
|
||||||
void registerProjectsParts(const QList<CppTools::ProjectPart::Ptr> projectParts);
|
void registerProjectsParts(const QVector<CppTools::ProjectPart::Ptr> projectParts);
|
||||||
|
|
||||||
void updateTranslationUnitIfNotCurrentDocument(Core::IDocument *document);
|
void updateTranslationUnitIfNotCurrentDocument(Core::IDocument *document);
|
||||||
void updateTranslationUnit(Core::IDocument *document);
|
void updateTranslationUnit(Core::IDocument *document);
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
|
|||||||
return unitsToAnalyze;
|
return unitsToAnalyze;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList<ProjectPart::Ptr> projectParts)
|
static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QVector<ProjectPart::Ptr> projectParts)
|
||||||
{
|
{
|
||||||
qCDebug(LOG) << "Taking arguments for analyzing from ProjectParts.";
|
qCDebug(LOG) << "Taking arguments for analyzing from ProjectParts.";
|
||||||
|
|
||||||
@@ -396,7 +396,7 @@ static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList<ProjectPart::Ptr>
|
|||||||
}
|
}
|
||||||
|
|
||||||
static QHash<QString, ProjectPart::Ptr> generateProjectFileToProjectPartMapping(
|
static QHash<QString, ProjectPart::Ptr> generateProjectFileToProjectPartMapping(
|
||||||
const QList<ProjectPart::Ptr> &projectParts)
|
const QVector<ProjectPart::Ptr> &projectParts)
|
||||||
{
|
{
|
||||||
QHash<QString, ProjectPart::Ptr> mapping;
|
QHash<QString, ProjectPart::Ptr> mapping;
|
||||||
|
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ void Dumper::dumpProjectInfos( const QList<ProjectInfo> &projectInfos)
|
|||||||
m_out << i1 << "Project " << project->displayName()
|
m_out << i1 << "Project " << project->displayName()
|
||||||
<< " (" << project->projectFilePath().toUserOutput() << "){{{2\n";
|
<< " (" << project->projectFilePath().toUserOutput() << "){{{2\n";
|
||||||
|
|
||||||
const QList<ProjectPart::Ptr> projectParts = info.projectParts();
|
const QVector<ProjectPart::Ptr> projectParts = info.projectParts();
|
||||||
foreach (const ProjectPart::Ptr &part, projectParts) {
|
foreach (const ProjectPart::Ptr &part, projectParts) {
|
||||||
QString projectName = QLatin1String("<None>");
|
QString projectName = QLatin1String("<None>");
|
||||||
QString projectFilePath = QLatin1String("<None>");
|
QString projectFilePath = QLatin1String("<None>");
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <utils/algorithm.h>
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -683,13 +682,6 @@ void CppModelManager::removeFilesFromSnapshot(const QSet<QString> &filesToRemove
|
|||||||
d->m_snapshot.remove(i.next());
|
d->m_snapshot.remove(i.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
static QSet<QString> projectPartIds(const QSet<ProjectPart::Ptr> &projectParts)
|
|
||||||
{
|
|
||||||
return Utils::transform(projectParts, [](const ProjectPart::Ptr &projectPart) {
|
|
||||||
return projectPart->id();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class ProjectInfoComparer
|
class ProjectInfoComparer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -721,8 +713,8 @@ public:
|
|||||||
|
|
||||||
QStringList removedProjectParts()
|
QStringList removedProjectParts()
|
||||||
{
|
{
|
||||||
QSet<QString> removed = projectPartIds(m_old.projectParts().toSet());
|
QSet<QString> removed = projectPartIds(m_old.projectParts());
|
||||||
removed.subtract(projectPartIds(m_new.projectParts().toSet()));
|
removed.subtract(projectPartIds(m_new.projectParts()));
|
||||||
return removed.toList();
|
return removed.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -743,6 +735,17 @@ public:
|
|||||||
return CppModelManager::timeStampModifiedFiles(documentsToCheck);
|
return CppModelManager::timeStampModifiedFiles(documentsToCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static QSet<QString> projectPartIds(const QVector<ProjectPart::Ptr> &projectParts)
|
||||||
|
{
|
||||||
|
QSet<QString> ids;
|
||||||
|
|
||||||
|
foreach (const ProjectPart::Ptr &projectPart, projectParts)
|
||||||
|
ids.insert(projectPart->id());
|
||||||
|
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const ProjectInfo &m_old;
|
const ProjectInfo &m_old;
|
||||||
const QSet<QString> m_oldSourceFiles;
|
const QSet<QString> m_oldSourceFiles;
|
||||||
|
|||||||
@@ -29,12 +29,40 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
ProjectInfo::ProjectInfo()
|
|
||||||
{}
|
|
||||||
|
|
||||||
ProjectInfo::ProjectInfo(QPointer<ProjectExplorer::Project> project)
|
ProjectInfo::ProjectInfo(QPointer<ProjectExplorer::Project> project)
|
||||||
: m_project(project)
|
: m_project(project)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProjectInfo::isValid() const
|
||||||
|
{
|
||||||
|
return !m_project.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointer<ProjectExplorer::Project> ProjectInfo::project() const
|
||||||
|
{
|
||||||
|
return m_project;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QVector<ProjectPart::Ptr> ProjectInfo::projectParts() const
|
||||||
|
{
|
||||||
|
return m_projectParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QSet<QString> ProjectInfo::sourceFiles() const
|
||||||
|
{
|
||||||
|
return m_sourceFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProjectInfo::setCompilerCallData(const CompilerCallData &data)
|
||||||
|
{
|
||||||
|
m_compilerCallData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectInfo::CompilerCallData ProjectInfo::compilerCallData() const
|
||||||
|
{
|
||||||
|
return m_compilerCallData;
|
||||||
|
}
|
||||||
|
|
||||||
static bool operator==(const ProjectInfo::CompilerCallGroup &first,
|
static bool operator==(const ProjectInfo::CompilerCallGroup &first,
|
||||||
const ProjectInfo::CompilerCallGroup &second)
|
const ProjectInfo::CompilerCallGroup &second)
|
||||||
@@ -73,40 +101,25 @@ bool ProjectInfo::configurationOrFilesChanged(const ProjectInfo &other) const
|
|||||||
return configurationChanged(other) || m_sourceFiles != other.m_sourceFiles;
|
return configurationChanged(other) || m_sourceFiles != other.m_sourceFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectInfo::isValid() const
|
void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &projectPart)
|
||||||
{
|
{
|
||||||
return !m_project.isNull();
|
if (projectPart)
|
||||||
}
|
m_projectParts.append(projectPart);
|
||||||
|
|
||||||
QPointer<ProjectExplorer::Project> ProjectInfo::project() const
|
|
||||||
{
|
|
||||||
return m_project;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QList<ProjectPart::Ptr> ProjectInfo::projectParts() const
|
|
||||||
{
|
|
||||||
return m_projectParts;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &part)
|
|
||||||
{
|
|
||||||
if (part)
|
|
||||||
m_projectParts.append(part);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectInfo::finish()
|
void ProjectInfo::finish()
|
||||||
{
|
{
|
||||||
typedef ProjectPartHeaderPath HeaderPath;
|
QSet<ProjectPartHeaderPath> uniqueHeaderPaths;
|
||||||
|
|
||||||
QSet<HeaderPath> incs;
|
|
||||||
foreach (const ProjectPart::Ptr &part, m_projectParts) {
|
foreach (const ProjectPart::Ptr &part, m_projectParts) {
|
||||||
part->updateLanguageFeatures();
|
part->updateLanguageFeatures();
|
||||||
|
|
||||||
// Update header paths
|
// Update header paths
|
||||||
foreach (const HeaderPath &hp, part->headerPaths) {
|
foreach (const ProjectPartHeaderPath &headerPath, part->headerPaths) {
|
||||||
if (!incs.contains(hp)) {
|
const int count = uniqueHeaderPaths.count();
|
||||||
incs.insert(hp);
|
uniqueHeaderPaths.insert(headerPath);
|
||||||
m_headerPaths += hp;
|
if (count < uniqueHeaderPaths.count())
|
||||||
}
|
m_headerPaths += headerPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update source files
|
// Update source files
|
||||||
@@ -124,29 +137,4 @@ void ProjectInfo::finish()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProjectPartHeaderPaths ProjectInfo::headerPaths() const
|
|
||||||
{
|
|
||||||
return m_headerPaths;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QSet<QString> ProjectInfo::sourceFiles() const
|
|
||||||
{
|
|
||||||
return m_sourceFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QByteArray ProjectInfo::defines() const
|
|
||||||
{
|
|
||||||
return m_defines;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProjectInfo::setCompilerCallData(const CompilerCallData &data)
|
|
||||||
{
|
|
||||||
m_compilerCallData = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProjectInfo::CompilerCallData ProjectInfo::compilerCallData() const
|
|
||||||
{
|
|
||||||
return m_compilerCallData;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
|||||||
@@ -32,32 +32,21 @@
|
|||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
class CPPTOOLS_EXPORT ProjectInfo
|
class CPPTOOLS_EXPORT ProjectInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProjectInfo();
|
ProjectInfo() = default;
|
||||||
ProjectInfo(QPointer<ProjectExplorer::Project> project);
|
ProjectInfo(QPointer<ProjectExplorer::Project> project);
|
||||||
|
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
bool operator ==(const ProjectInfo &other) const;
|
|
||||||
bool operator !=(const ProjectInfo &other) const;
|
|
||||||
bool definesChanged(const ProjectInfo &other) const;
|
|
||||||
bool configurationChanged(const ProjectInfo &other) const;
|
|
||||||
bool configurationOrFilesChanged(const ProjectInfo &other) const;
|
|
||||||
|
|
||||||
QPointer<ProjectExplorer::Project> project() const;
|
QPointer<ProjectExplorer::Project> project() const;
|
||||||
const QList<ProjectPart::Ptr> projectParts() const;
|
const QVector<ProjectPart::Ptr> projectParts() const;
|
||||||
|
|
||||||
void appendProjectPart(const ProjectPart::Ptr &part);
|
|
||||||
void finish();
|
|
||||||
|
|
||||||
const ProjectPartHeaderPaths headerPaths() const;
|
|
||||||
const QSet<QString> sourceFiles() const;
|
const QSet<QString> sourceFiles() const;
|
||||||
const QByteArray defines() const;
|
|
||||||
|
|
||||||
struct CompilerCallGroup {
|
struct CompilerCallGroup {
|
||||||
using CallsPerSourceFile = QHash<QString, QList<QStringList>>;
|
using CallsPerSourceFile = QHash<QString, QList<QStringList>>;
|
||||||
@@ -69,10 +58,22 @@ public:
|
|||||||
void setCompilerCallData(const CompilerCallData &data);
|
void setCompilerCallData(const CompilerCallData &data);
|
||||||
CompilerCallData compilerCallData() const;
|
CompilerCallData compilerCallData() const;
|
||||||
|
|
||||||
|
// Comparisons
|
||||||
|
bool operator ==(const ProjectInfo &other) const;
|
||||||
|
bool operator !=(const ProjectInfo &other) const;
|
||||||
|
bool definesChanged(const ProjectInfo &other) const;
|
||||||
|
bool configurationChanged(const ProjectInfo &other) const;
|
||||||
|
bool configurationOrFilesChanged(const ProjectInfo &other) const;
|
||||||
|
|
||||||
|
// Construction
|
||||||
|
void appendProjectPart(const ProjectPart::Ptr &projectPart);
|
||||||
|
void finish();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<ProjectExplorer::Project> m_project;
|
QPointer<ProjectExplorer::Project> m_project;
|
||||||
QList<ProjectPart::Ptr> m_projectParts;
|
QVector<ProjectPart::Ptr> m_projectParts;
|
||||||
CompilerCallData m_compilerCallData;
|
CompilerCallData m_compilerCallData;
|
||||||
|
|
||||||
// The members below are (re)calculated from the project parts with finish()
|
// The members below are (re)calculated from the project parts with finish()
|
||||||
ProjectPartHeaderPaths m_headerPaths;
|
ProjectPartHeaderPaths m_headerPaths;
|
||||||
QSet<QString> m_sourceFiles;
|
QSet<QString> m_sourceFiles;
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ void GenericProjectPlugin::test_mixed1()
|
|||||||
QVERIFY(pInfo.isValid());
|
QVERIFY(pInfo.isValid());
|
||||||
QCOMPARE(pInfo.projectParts().size(), 3);
|
QCOMPARE(pInfo.projectParts().size(), 3);
|
||||||
|
|
||||||
QList<ProjectPart::Ptr> parts = pInfo.projectParts();
|
QVector<ProjectPart::Ptr> parts = pInfo.projectParts();
|
||||||
std::sort(parts.begin(), parts.end(), [](const ProjectPart::Ptr &p1,
|
std::sort(parts.begin(), parts.end(), [](const ProjectPart::Ptr &p1,
|
||||||
const ProjectPart::Ptr &p2) {
|
const ProjectPart::Ptr &p2) {
|
||||||
return p1->displayName < p2->displayName;
|
return p1->displayName < p2->displayName;
|
||||||
@@ -150,7 +150,7 @@ void GenericProjectPlugin::test_mixed2()
|
|||||||
QVERIFY(pInfo.isValid());
|
QVERIFY(pInfo.isValid());
|
||||||
QCOMPARE(pInfo.projectParts().size(), 2);
|
QCOMPARE(pInfo.projectParts().size(), 2);
|
||||||
|
|
||||||
QList<ProjectPart::Ptr> parts = pInfo.projectParts();
|
QVector<ProjectPart::Ptr> parts = pInfo.projectParts();
|
||||||
std::sort(parts.begin(), parts.end(), [](const ProjectPart::Ptr &p1,
|
std::sort(parts.begin(), parts.end(), [](const ProjectPart::Ptr &p1,
|
||||||
const ProjectPart::Ptr &p2) {
|
const ProjectPart::Ptr &p2) {
|
||||||
return p1->displayName < p2->displayName;
|
return p1->displayName < p2->displayName;
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ TEST_F(BaseProjectPartBuilder, ProjectFileKindsMatchProjectPartVersion)
|
|||||||
|
|
||||||
builder.createProjectPartsForFiles(QStringList() << "foo.h");
|
builder.createProjectPartsForFiles(QStringList() << "foo.h");
|
||||||
|
|
||||||
const QList<ProjectPart::Ptr> projectParts = projectInfo.projectParts();
|
const QVector<ProjectPart::Ptr> projectParts = projectInfo.projectParts();
|
||||||
ASSERT_THAT(projectParts.size(), Eq(4));
|
ASSERT_THAT(projectParts.size(), Eq(4));
|
||||||
ASSERT_THAT(projectParts.at(0)->languageVersion, Eq(ProjectPart::LatestCVersion));
|
ASSERT_THAT(projectParts.at(0)->languageVersion, Eq(ProjectPart::LatestCVersion));
|
||||||
ASSERT_THAT(projectParts.at(0)->files.at(0).kind, Eq(ProjectFile::CHeader));
|
ASSERT_THAT(projectParts.at(0)->files.at(0).kind, Eq(ProjectFile::CHeader));
|
||||||
|
|||||||
Reference in New Issue
Block a user