Commit 02d8e2af authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Clean up ProjectInfo

Change-Id: I5d0db45d9fdb624bb6cc55d7f04061d553f13bce
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 20338548
......@@ -58,7 +58,7 @@ void completeBasicProjectInformation(Project *project, const QString &proFile, Q
Project **targetProject)
{
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()) {
foreach (const CppTools::ProjectPart::Ptr &part, projParts) {
......
......@@ -387,7 +387,7 @@ static ClangBackEnd::ProjectPartContainer toProjectPartContainer(
}
static QVector<ClangBackEnd::ProjectPartContainer> toProjectPartContainers(
const QList<CppTools::ProjectPart::Ptr> projectParts)
const QVector<CppTools::ProjectPart::Ptr> projectParts)
{
QVector<ClangBackEnd::ProjectPartContainer> projectPartContainers;
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);
registerProjectPartsForEditor(projectPartContainers);
......
......@@ -134,7 +134,7 @@ public:
quint32 column,
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 updateTranslationUnit(Core::IDocument *document);
......
......@@ -371,7 +371,7 @@ static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
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.";
......@@ -396,7 +396,7 @@ static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList<ProjectPart::Ptr>
}
static QHash<QString, ProjectPart::Ptr> generateProjectFileToProjectPartMapping(
const QList<ProjectPart::Ptr> &projectParts)
const QVector<ProjectPart::Ptr> &projectParts)
{
QHash<QString, ProjectPart::Ptr> mapping;
......
......@@ -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
{
return !m_project.isNull();
}
QPointer<ProjectExplorer::Project> ProjectInfo::project() const
void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &projectPart)
{
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;
......
......@@ -101,7 +101,7 @@ void GenericProjectPlugin::test_mixed1()
QVERIFY(pInfo.isValid());
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,
const ProjectPart::Ptr &p2) {
return p1->displayName < p2->displayName;
......@@ -150,7 +150,7 @@ void GenericProjectPlugin::test_mixed2()
QVERIFY(pInfo.isValid());
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,
const ProjectPart::Ptr &p2) {
return p1->displayName < p2->displayName;
......
......@@ -195,7 +195,7 @@ TEST_F(BaseProjectPartBuilder, ProjectFileKindsMatchProjectPartVersion)
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.at(0)->languageVersion, Eq(ProjectPart::LatestCVersion));
ASSERT_THAT(projectParts.at(0)->files.at(0).kind, Eq(ProjectFile::CHeader));
......
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