forked from qt-creator/qt-creator
CppTools: Extract ProjectFileCategorizer
Change-Id: Ib7a5c3c61b0ea172cbc6a3ac7c94e77ffabc0db4 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
89
src/plugins/cpptools/cppprojectfilecategorizer.cpp
Normal file
89
src/plugins/cpptools/cppprojectfilecategorizer.cpp
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "cppprojectfilecategorizer.h"
|
||||||
|
|
||||||
|
namespace CppTools {
|
||||||
|
|
||||||
|
ProjectFileCategorizer::ProjectFileCategorizer(const QString &partName,
|
||||||
|
const QStringList &files,
|
||||||
|
ProjectPartBuilder::FileClassifier fileClassifier)
|
||||||
|
: m_partName(partName)
|
||||||
|
{
|
||||||
|
using CppTools::ProjectFile;
|
||||||
|
|
||||||
|
QVector<ProjectFile> cHeaders;
|
||||||
|
QVector<ProjectFile> cxxHeaders;
|
||||||
|
|
||||||
|
foreach (const QString &file, files) {
|
||||||
|
const ProjectFile::Kind kind = fileClassifier
|
||||||
|
? fileClassifier(file)
|
||||||
|
: ProjectFile::classify(file);
|
||||||
|
const ProjectFile projectFile(file, kind);
|
||||||
|
|
||||||
|
switch (kind) {
|
||||||
|
case ProjectFile::CSource: m_cSources += projectFile; break;
|
||||||
|
case ProjectFile::CHeader: cHeaders += projectFile; break;
|
||||||
|
case ProjectFile::CXXSource: m_cxxSources += projectFile; break;
|
||||||
|
case ProjectFile::CXXHeader: cxxHeaders += projectFile; break;
|
||||||
|
case ProjectFile::ObjCSource: m_objcSources += projectFile; break;
|
||||||
|
case ProjectFile::ObjCXXSource: m_objcxxSources += projectFile; break;
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool hasC = !m_cSources.isEmpty();
|
||||||
|
const bool hasCxx = !m_cxxSources.isEmpty();
|
||||||
|
const bool hasObjc = !m_objcSources.isEmpty();
|
||||||
|
const bool hasObjcxx = !m_objcxxSources.isEmpty();
|
||||||
|
|
||||||
|
if (hasObjcxx)
|
||||||
|
m_objcxxSources += cxxHeaders + cHeaders;
|
||||||
|
if (hasCxx)
|
||||||
|
m_cxxSources += cxxHeaders + cHeaders;
|
||||||
|
else if (!hasObjcxx)
|
||||||
|
m_cxxSources += cxxHeaders;
|
||||||
|
if (hasObjc)
|
||||||
|
m_objcSources += cHeaders;
|
||||||
|
if (hasC || (!hasObjc && !hasObjcxx && !hasCxx))
|
||||||
|
m_cSources += cHeaders;
|
||||||
|
|
||||||
|
m_partCount =
|
||||||
|
(m_cSources.isEmpty() ? 0 : 1) +
|
||||||
|
(m_cxxSources.isEmpty() ? 0 : 1) +
|
||||||
|
(m_objcSources.isEmpty() ? 0 : 1) +
|
||||||
|
(m_objcxxSources.isEmpty() ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ProjectFileCategorizer::partName(const QString &languageName) const
|
||||||
|
{
|
||||||
|
if (hasMultipleParts())
|
||||||
|
return QString::fromLatin1("%1 (%2)").arg(m_partName).arg(languageName);
|
||||||
|
|
||||||
|
return m_partName;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CppTools
|
68
src/plugins/cpptools/cppprojectfilecategorizer.h
Normal file
68
src/plugins/cpptools/cppprojectfilecategorizer.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
#include "cppprojectfile.h"
|
||||||
|
#include "projectpartbuilder.h"
|
||||||
|
|
||||||
|
namespace CppTools {
|
||||||
|
|
||||||
|
class ProjectFileCategorizer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ProjectFileCategorizer(const QString &partName,
|
||||||
|
const QStringList &files,
|
||||||
|
ProjectPartBuilder::FileClassifier fileClassifier
|
||||||
|
= ProjectPartBuilder::FileClassifier());
|
||||||
|
|
||||||
|
bool hasCSources() const { return !m_cSources.isEmpty(); }
|
||||||
|
bool hasCxxSources() const { return !m_cxxSources.isEmpty(); }
|
||||||
|
bool hasObjcSources() const { return !m_objcSources.isEmpty(); }
|
||||||
|
bool hasObjcxxSources() const { return !m_objcxxSources.isEmpty(); }
|
||||||
|
|
||||||
|
QVector<ProjectFile> cSources() const { return m_cSources; }
|
||||||
|
QVector<ProjectFile> cxxSources() const { return m_cxxSources; }
|
||||||
|
QVector<ProjectFile> objcSources() const { return m_objcSources; }
|
||||||
|
QVector<ProjectFile> objcxxSources() const { return m_objcxxSources; }
|
||||||
|
|
||||||
|
bool hasMultipleParts() const { return m_partCount > 1; }
|
||||||
|
bool hasNoParts() const { return m_partCount == 0; }
|
||||||
|
|
||||||
|
QString partName(const QString &languageName) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_partName;
|
||||||
|
QVector<ProjectFile> m_cSources;
|
||||||
|
QVector<ProjectFile> m_cxxSources;
|
||||||
|
QVector<ProjectFile> m_objcSources;
|
||||||
|
QVector<ProjectFile> m_objcxxSources;
|
||||||
|
int m_partCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace CppTools
|
@@ -77,7 +77,9 @@ HEADERS += \
|
|||||||
projectinfo.h \
|
projectinfo.h \
|
||||||
projectpartbuilder.h \
|
projectpartbuilder.h \
|
||||||
compileroptionsbuilder.h \
|
compileroptionsbuilder.h \
|
||||||
refactoringengineinterface.h
|
refactoringengineinterface.h \
|
||||||
|
cppprojectfilecategorizer.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
abstracteditorsupport.cpp \
|
abstracteditorsupport.cpp \
|
||||||
baseeditordocumentparser.cpp \
|
baseeditordocumentparser.cpp \
|
||||||
@@ -148,7 +150,8 @@ SOURCES += \
|
|||||||
projectpart.cpp \
|
projectpart.cpp \
|
||||||
projectinfo.cpp \
|
projectinfo.cpp \
|
||||||
projectpartbuilder.cpp \
|
projectpartbuilder.cpp \
|
||||||
compileroptionsbuilder.cpp
|
compileroptionsbuilder.cpp \
|
||||||
|
cppprojectfilecategorizer.cpp
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
clangdiagnosticconfigswidget.ui \
|
clangdiagnosticconfigswidget.ui \
|
||||||
|
@@ -104,6 +104,7 @@ Project {
|
|||||||
"symbolfinder.cpp", "symbolfinder.h",
|
"symbolfinder.cpp", "symbolfinder.h",
|
||||||
"symbolsfindfilter.cpp", "symbolsfindfilter.h",
|
"symbolsfindfilter.cpp", "symbolsfindfilter.h",
|
||||||
"typehierarchybuilder.cpp", "typehierarchybuilder.h",
|
"typehierarchybuilder.cpp", "typehierarchybuilder.h",
|
||||||
|
"cppprojectfilecategorizer.cpp", "cppprojectfilecategorizer.h",
|
||||||
]
|
]
|
||||||
|
|
||||||
Group {
|
Group {
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "projectpartbuilder.h"
|
#include "projectpartbuilder.h"
|
||||||
|
|
||||||
#include "cppprojectfile.h"
|
#include "cppprojectfile.h"
|
||||||
|
#include "cppprojectfilecategorizer.h"
|
||||||
#include "cpptoolsconstants.h"
|
#include "cpptoolsconstants.h"
|
||||||
|
|
||||||
#include <projectexplorer/abi.h>
|
#include <projectexplorer/abi.h>
|
||||||
@@ -42,93 +43,6 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
namespace {
|
|
||||||
class ProjectFileCategorizer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ProjectFileCategorizer(const QString &partName,
|
|
||||||
const QStringList &files,
|
|
||||||
ProjectPartBuilder::FileClassifier fileClassifier
|
|
||||||
= ProjectPartBuilder::FileClassifier())
|
|
||||||
: m_partName(partName)
|
|
||||||
{
|
|
||||||
using CppTools::ProjectFile;
|
|
||||||
|
|
||||||
QVector<ProjectFile> cHeaders;
|
|
||||||
QVector<ProjectFile> cxxHeaders;
|
|
||||||
|
|
||||||
foreach (const QString &file, files) {
|
|
||||||
const ProjectFile::Kind kind = fileClassifier
|
|
||||||
? fileClassifier(file)
|
|
||||||
: ProjectFile::classify(file);
|
|
||||||
const ProjectFile projectFile(file, kind);
|
|
||||||
|
|
||||||
switch (kind) {
|
|
||||||
case ProjectFile::CSource: m_cSources += projectFile; break;
|
|
||||||
case ProjectFile::CHeader: cHeaders += projectFile; break;
|
|
||||||
case ProjectFile::CXXSource: m_cxxSources += projectFile; break;
|
|
||||||
case ProjectFile::CXXHeader: cxxHeaders += projectFile; break;
|
|
||||||
case ProjectFile::ObjCSource: m_objcSources += projectFile; break;
|
|
||||||
case ProjectFile::ObjCXXSource: m_objcxxSources += projectFile; break;
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool hasC = !m_cSources.isEmpty();
|
|
||||||
const bool hasCxx = !m_cxxSources.isEmpty();
|
|
||||||
const bool hasObjc = !m_objcSources.isEmpty();
|
|
||||||
const bool hasObjcxx = !m_objcxxSources.isEmpty();
|
|
||||||
|
|
||||||
if (hasObjcxx)
|
|
||||||
m_objcxxSources += cxxHeaders + cHeaders;
|
|
||||||
if (hasCxx)
|
|
||||||
m_cxxSources += cxxHeaders + cHeaders;
|
|
||||||
else if (!hasObjcxx)
|
|
||||||
m_cxxSources += cxxHeaders;
|
|
||||||
if (hasObjc)
|
|
||||||
m_objcSources += cHeaders;
|
|
||||||
if (hasC || (!hasObjc && !hasObjcxx && !hasCxx))
|
|
||||||
m_cSources += cHeaders;
|
|
||||||
|
|
||||||
m_partCount =
|
|
||||||
(m_cSources.isEmpty() ? 0 : 1) +
|
|
||||||
(m_cxxSources.isEmpty() ? 0 : 1) +
|
|
||||||
(m_objcSources.isEmpty() ? 0 : 1) +
|
|
||||||
(m_objcxxSources.isEmpty() ? 0 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasCSources() const { return !m_cSources.isEmpty(); }
|
|
||||||
bool hasCxxSources() const { return !m_cxxSources.isEmpty(); }
|
|
||||||
bool hasObjcSources() const { return !m_objcSources.isEmpty(); }
|
|
||||||
bool hasObjcxxSources() const { return !m_objcxxSources.isEmpty(); }
|
|
||||||
|
|
||||||
QVector<ProjectFile> cSources() const { return m_cSources; }
|
|
||||||
QVector<ProjectFile> cxxSources() const { return m_cxxSources; }
|
|
||||||
QVector<ProjectFile> objcSources() const { return m_objcSources; }
|
|
||||||
QVector<ProjectFile> objcxxSources() const { return m_objcxxSources; }
|
|
||||||
|
|
||||||
bool hasMultipleParts() const { return m_partCount > 1; }
|
|
||||||
bool hasNoParts() const { return m_partCount == 0; }
|
|
||||||
|
|
||||||
QString partName(const QString &languageName) const
|
|
||||||
{
|
|
||||||
if (hasMultipleParts())
|
|
||||||
return QString::fromLatin1("%1 (%2)").arg(m_partName).arg(languageName);
|
|
||||||
|
|
||||||
return m_partName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_partName;
|
|
||||||
QVector<ProjectFile> m_cSources;
|
|
||||||
QVector<ProjectFile> m_cxxSources;
|
|
||||||
QVector<ProjectFile> m_objcSources;
|
|
||||||
QVector<ProjectFile> m_objcxxSources;
|
|
||||||
int m_partCount;
|
|
||||||
};
|
|
||||||
} // anonymous namespace
|
|
||||||
|
|
||||||
ProjectPartBuilder::ProjectPartBuilder(ProjectInfo &pInfo)
|
ProjectPartBuilder::ProjectPartBuilder(ProjectInfo &pInfo)
|
||||||
: m_templatePart(new ProjectPart)
|
: m_templatePart(new ProjectPart)
|
||||||
, m_pInfo(pInfo)
|
, m_pInfo(pInfo)
|
||||||
|
Reference in New Issue
Block a user