diff options
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r-- | src/plugins/cpptools/cppprojectfilecategorizer.cpp | 89 | ||||
-rw-r--r-- | src/plugins/cpptools/cppprojectfilecategorizer.h | 68 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptools.pro | 7 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptools.qbs | 1 | ||||
-rw-r--r-- | src/plugins/cpptools/projectpartbuilder.cpp | 88 |
5 files changed, 164 insertions, 89 deletions
diff --git a/src/plugins/cpptools/cppprojectfilecategorizer.cpp b/src/plugins/cpptools/cppprojectfilecategorizer.cpp new file mode 100644 index 0000000000..6116e164d0 --- /dev/null +++ b/src/plugins/cpptools/cppprojectfilecategorizer.cpp @@ -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 diff --git a/src/plugins/cpptools/cppprojectfilecategorizer.h b/src/plugins/cpptools/cppprojectfilecategorizer.h new file mode 100644 index 0000000000..23fae9669e --- /dev/null +++ b/src/plugins/cpptools/cppprojectfilecategorizer.h @@ -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 diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 750c63f1de..3795db2aca 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -77,7 +77,9 @@ HEADERS += \ projectinfo.h \ projectpartbuilder.h \ compileroptionsbuilder.h \ - refactoringengineinterface.h + refactoringengineinterface.h \ + cppprojectfilecategorizer.h + SOURCES += \ abstracteditorsupport.cpp \ baseeditordocumentparser.cpp \ @@ -148,7 +150,8 @@ SOURCES += \ projectpart.cpp \ projectinfo.cpp \ projectpartbuilder.cpp \ - compileroptionsbuilder.cpp + compileroptionsbuilder.cpp \ + cppprojectfilecategorizer.cpp FORMS += \ clangdiagnosticconfigswidget.ui \ diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs index db2a45c7f3..565d43a1c3 100644 --- a/src/plugins/cpptools/cpptools.qbs +++ b/src/plugins/cpptools/cpptools.qbs @@ -104,6 +104,7 @@ Project { "symbolfinder.cpp", "symbolfinder.h", "symbolsfindfilter.cpp", "symbolsfindfilter.h", "typehierarchybuilder.cpp", "typehierarchybuilder.h", + "cppprojectfilecategorizer.cpp", "cppprojectfilecategorizer.h", ] Group { diff --git a/src/plugins/cpptools/projectpartbuilder.cpp b/src/plugins/cpptools/projectpartbuilder.cpp index 98169f7d23..eaaa048b93 100644 --- a/src/plugins/cpptools/projectpartbuilder.cpp +++ b/src/plugins/cpptools/projectpartbuilder.cpp @@ -26,6 +26,7 @@ #include "projectpartbuilder.h" #include "cppprojectfile.h" +#include "cppprojectfilecategorizer.h" #include "cpptoolsconstants.h" #include <projectexplorer/abi.h> @@ -42,93 +43,6 @@ 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) : m_templatePart(new ProjectPart) , m_pInfo(pInfo) |