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:
		@@ -481,7 +481,7 @@ void Dumper::dumpProjectInfos( const QList<ProjectInfo> &projectInfos)
 | 
			
		||||
        m_out << i1 << "Project " << project->displayName()
 | 
			
		||||
              << " (" << 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) {
 | 
			
		||||
            QString projectName = QLatin1String("<None>");
 | 
			
		||||
            QString projectFilePath = QLatin1String("<None>");
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,6 @@
 | 
			
		||||
#include <projectexplorer/projectexplorer.h>
 | 
			
		||||
#include <projectexplorer/session.h>
 | 
			
		||||
#include <extensionsystem/pluginmanager.h>
 | 
			
		||||
#include <utils/algorithm.h>
 | 
			
		||||
#include <utils/fileutils.h>
 | 
			
		||||
#include <utils/qtcassert.h>
 | 
			
		||||
 | 
			
		||||
@@ -683,13 +682,6 @@ void CppModelManager::removeFilesFromSnapshot(const QSet<QString> &filesToRemove
 | 
			
		||||
        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
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
@@ -721,8 +713,8 @@ public:
 | 
			
		||||
 | 
			
		||||
    QStringList removedProjectParts()
 | 
			
		||||
    {
 | 
			
		||||
        QSet<QString> removed = projectPartIds(m_old.projectParts().toSet());
 | 
			
		||||
        removed.subtract(projectPartIds(m_new.projectParts().toSet()));
 | 
			
		||||
        QSet<QString> removed = projectPartIds(m_old.projectParts());
 | 
			
		||||
        removed.subtract(projectPartIds(m_new.projectParts()));
 | 
			
		||||
        return removed.toList();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -743,6 +735,17 @@ public:
 | 
			
		||||
        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:
 | 
			
		||||
    const ProjectInfo &m_old;
 | 
			
		||||
    const QSet<QString> m_oldSourceFiles;
 | 
			
		||||
 
 | 
			
		||||
@@ -29,28 +29,56 @@
 | 
			
		||||
 | 
			
		||||
namespace CppTools {
 | 
			
		||||
 | 
			
		||||
ProjectInfo::ProjectInfo()
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
ProjectInfo::ProjectInfo(QPointer<ProjectExplorer::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,
 | 
			
		||||
                       const ProjectInfo::CompilerCallGroup &second)
 | 
			
		||||
{
 | 
			
		||||
    return first.groupId == second.groupId
 | 
			
		||||
            && first.callsPerSourceFile == second.callsPerSourceFile;
 | 
			
		||||
        && first.callsPerSourceFile == second.callsPerSourceFile;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ProjectInfo::operator ==(const ProjectInfo &other) const
 | 
			
		||||
{
 | 
			
		||||
    return m_project == other.m_project
 | 
			
		||||
            && m_projectParts == other.m_projectParts
 | 
			
		||||
            && m_compilerCallData == other.m_compilerCallData
 | 
			
		||||
            && m_headerPaths == other.m_headerPaths
 | 
			
		||||
            && m_sourceFiles == other.m_sourceFiles
 | 
			
		||||
            && m_defines == other.m_defines;
 | 
			
		||||
        && m_projectParts == other.m_projectParts
 | 
			
		||||
        && m_compilerCallData == other.m_compilerCallData
 | 
			
		||||
        && m_headerPaths == other.m_headerPaths
 | 
			
		||||
        && m_sourceFiles == other.m_sourceFiles
 | 
			
		||||
        && m_defines == other.m_defines;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ProjectInfo::operator !=(const ProjectInfo &other) const
 | 
			
		||||
@@ -73,40 +101,25 @@ bool ProjectInfo::configurationOrFilesChanged(const ProjectInfo &other) const
 | 
			
		||||
    return configurationChanged(other) || m_sourceFiles != other.m_sourceFiles;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ProjectInfo::isValid() const
 | 
			
		||||
void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &projectPart)
 | 
			
		||||
{
 | 
			
		||||
    return !m_project.isNull();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
    if (projectPart)
 | 
			
		||||
        m_projectParts.append(projectPart);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ProjectInfo::finish()
 | 
			
		||||
{
 | 
			
		||||
    typedef ProjectPartHeaderPath HeaderPath;
 | 
			
		||||
    QSet<ProjectPartHeaderPath> uniqueHeaderPaths;
 | 
			
		||||
 | 
			
		||||
    QSet<HeaderPath> incs;
 | 
			
		||||
    foreach (const ProjectPart::Ptr &part, m_projectParts) {
 | 
			
		||||
        part->updateLanguageFeatures();
 | 
			
		||||
 | 
			
		||||
        // Update header paths
 | 
			
		||||
        foreach (const HeaderPath &hp, part->headerPaths) {
 | 
			
		||||
            if (!incs.contains(hp)) {
 | 
			
		||||
                incs.insert(hp);
 | 
			
		||||
                m_headerPaths += hp;
 | 
			
		||||
            }
 | 
			
		||||
        foreach (const ProjectPartHeaderPath &headerPath, part->headerPaths) {
 | 
			
		||||
            const int count = uniqueHeaderPaths.count();
 | 
			
		||||
            uniqueHeaderPaths.insert(headerPath);
 | 
			
		||||
            if (count < uniqueHeaderPaths.count())
 | 
			
		||||
                m_headerPaths += headerPath;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 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
 | 
			
		||||
 
 | 
			
		||||
@@ -32,32 +32,21 @@
 | 
			
		||||
#include <QHash>
 | 
			
		||||
#include <QPointer>
 | 
			
		||||
#include <QSet>
 | 
			
		||||
#include <QVector>
 | 
			
		||||
 | 
			
		||||
namespace CppTools {
 | 
			
		||||
 | 
			
		||||
class CPPTOOLS_EXPORT ProjectInfo
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    ProjectInfo();
 | 
			
		||||
    ProjectInfo() = default;
 | 
			
		||||
    ProjectInfo(QPointer<ProjectExplorer::Project> project);
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    const QList<ProjectPart::Ptr> projectParts() const;
 | 
			
		||||
 | 
			
		||||
    void appendProjectPart(const ProjectPart::Ptr &part);
 | 
			
		||||
    void finish();
 | 
			
		||||
 | 
			
		||||
    const ProjectPartHeaderPaths headerPaths() const;
 | 
			
		||||
    const QVector<ProjectPart::Ptr> projectParts() const;
 | 
			
		||||
    const QSet<QString> sourceFiles() const;
 | 
			
		||||
    const QByteArray defines() const;
 | 
			
		||||
 | 
			
		||||
    struct CompilerCallGroup {
 | 
			
		||||
        using CallsPerSourceFile = QHash<QString, QList<QStringList>>;
 | 
			
		||||
@@ -69,10 +58,22 @@ public:
 | 
			
		||||
    void setCompilerCallData(const CompilerCallData &data);
 | 
			
		||||
    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:
 | 
			
		||||
    QPointer<ProjectExplorer::Project> m_project;
 | 
			
		||||
    QList<ProjectPart::Ptr> m_projectParts;
 | 
			
		||||
    QVector<ProjectPart::Ptr> m_projectParts;
 | 
			
		||||
    CompilerCallData m_compilerCallData;
 | 
			
		||||
 | 
			
		||||
    // The members below are (re)calculated from the project parts with finish()
 | 
			
		||||
    ProjectPartHeaderPaths m_headerPaths;
 | 
			
		||||
    QSet<QString> m_sourceFiles;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user