summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@theqtcompany.com>2016-01-11 20:50:14 +0100
committerMarco Bubke <marco.bubke@theqtcompany.com>2016-01-12 10:21:30 +0000
commit6fe9b0ccc471dd0be161634a28e21d10a660d732 (patch)
tree91ccea669480957bf30993bd9da94ebdad8c8017 /src/plugins/cpptools
parent6157c05f14a9c80378448148059c0a046997eafd (diff)
downloadqt-creator-6fe9b0ccc471dd0be161634a28e21d10a660d732.tar.gz
CppTools: Add CppToolsBridge
We broke the dependency of BaseEditorDocumentProcessor *BaseEditorDocumentProcessor::get(const QString &filePath) It's hiding static calls and it is much easier to do it that way than to provide a reference to every user. It's also possible to exchange it with different implementations for different test cases. Change-Id: Ic74699b45948e8b48f7efb6a1b295ba2641b8951 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r--src/plugins/cpptools/baseeditordocumentprocessor.cpp12
-rw-r--r--src/plugins/cpptools/baseeditordocumentprocessor.h3
-rw-r--r--src/plugins/cpptools/cppsourceprocessor_test.cpp3
-rw-r--r--src/plugins/cpptools/cpptools.pro9
-rw-r--r--src/plugins/cpptools/cpptools.qbs3
-rw-r--r--src/plugins/cpptools/cpptoolsbridge.cpp64
-rw-r--r--src/plugins/cpptools/cpptoolsbridge.h62
-rw-r--r--src/plugins/cpptools/cpptoolsbridgeinterface.h56
-rw-r--r--src/plugins/cpptools/cpptoolsbridgeqtcreatorimplementation.cpp96
-rw-r--r--src/plugins/cpptools/cpptoolsbridgeqtcreatorimplementation.h52
-rw-r--r--src/plugins/cpptools/cpptoolsplugin.cpp4
11 files changed, 348 insertions, 16 deletions
diff --git a/src/plugins/cpptools/baseeditordocumentprocessor.cpp b/src/plugins/cpptools/baseeditordocumentprocessor.cpp
index e90a64dbd0..68dba8d044 100644
--- a/src/plugins/cpptools/baseeditordocumentprocessor.cpp
+++ b/src/plugins/cpptools/baseeditordocumentprocessor.cpp
@@ -31,6 +31,7 @@
#include "baseeditordocumentprocessor.h"
#include "cppmodelmanager.h"
+#include "cpptoolsbridge.h"
#include "editordocumenthandle.h"
#include <texteditor/quickfix.h>
@@ -62,14 +63,6 @@ BaseEditorDocumentProcessor::extraRefactoringOperations(const TextEditor::Assist
return TextEditor::QuickFixOperations();
}
-BaseEditorDocumentProcessor *BaseEditorDocumentProcessor::get(const QString &filePath)
-{
- CppModelManager *cmmi = CppModelManager::instance();
- if (CppEditorDocumentHandle *cppEditorDocument = cmmi->cppEditorDocument(filePath))
- return cppEditorDocument->processor();
- return 0;
-}
-
void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
BaseEditorDocumentParser::Ptr parser,
const WorkingCopy workingCopy)
@@ -81,8 +74,7 @@ void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
}
parser->update(workingCopy);
- CppModelManager::instance()
- ->finishedRefreshingSourceFiles(QSet<QString>() << parser->filePath());
+ CppToolsBridge::finishedRefreshingSourceFiles({parser->filePath()});
future.setProgressValue(1);
}
diff --git a/src/plugins/cpptools/baseeditordocumentprocessor.h b/src/plugins/cpptools/baseeditordocumentprocessor.h
index 353a980f11..6038e46fa3 100644
--- a/src/plugins/cpptools/baseeditordocumentprocessor.h
+++ b/src/plugins/cpptools/baseeditordocumentprocessor.h
@@ -70,9 +70,6 @@ public:
virtual TextEditor::QuickFixOperations
extraRefactoringOperations(const TextEditor::AssistInterface &assistInterface);
-public:
- static BaseEditorDocumentProcessor *get(const QString &filePath);
-
signals:
// Signal interface to implement
void codeWarningsUpdated(unsigned revision,
diff --git a/src/plugins/cpptools/cppsourceprocessor_test.cpp b/src/plugins/cpptools/cppsourceprocessor_test.cpp
index 518eece226..bdc2cf2a38 100644
--- a/src/plugins/cpptools/cppsourceprocessor_test.cpp
+++ b/src/plugins/cpptools/cppsourceprocessor_test.cpp
@@ -34,6 +34,7 @@
#include "cppmodelmanager.h"
#include "cppsourceprocessertesthelper.h"
#include "cppsourceprocessor.h"
+#include "cpptoolsbridge.h"
#include "cpptoolstestcase.h"
#include "editordocumenthandle.h"
@@ -135,7 +136,7 @@ void CppToolsPlugin::test_cppsourceprocessor_includes_cyclic()
// Check editor snapshot
const QString filePath = editor->document()->filePath().toString();
- auto *processor = BaseEditorDocumentProcessor::get(filePath);
+ auto *processor = CppToolsBridge::baseEditorDocumentProcessor(filePath);
QVERIFY(processor);
QVERIFY(TestCase::waitForProcessedEditorDocument(filePath));
Snapshot snapshot = processor->snapshot();
diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro
index b543389456..9004507bd8 100644
--- a/src/plugins/cpptools/cpptools.pro
+++ b/src/plugins/cpptools/cpptools.pro
@@ -66,7 +66,10 @@ HEADERS += \
symbolfinder.h \
symbolsfindfilter.h \
typehierarchybuilder.h \
- senddocumenttracker.h
+ senddocumenttracker.h \
+ cpptoolsbridge.h \
+ cpptoolsbridgeinterface.h \
+ cpptoolsbridgeqtcreatorimplementation.h
SOURCES += \
abstracteditorsupport.cpp \
@@ -130,7 +133,9 @@ SOURCES += \
symbolfinder.cpp \
symbolsfindfilter.cpp \
typehierarchybuilder.cpp \
- senddocumenttracker.cpp
+ senddocumenttracker.cpp \
+ cpptoolsbridge.cpp \
+ cpptoolsbridgeqtcreatorimplementation.cpp
FORMS += \
completionsettingspage.ui \
diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs
index 611316c4d9..dd4a7ce1d1 100644
--- a/src/plugins/cpptools/cpptools.qbs
+++ b/src/plugins/cpptools/cpptools.qbs
@@ -69,6 +69,9 @@ QtcPlugin {
"cppsemanticinfo.cpp", "cppsemanticinfo.h",
"cppsemanticinfoupdater.cpp", "cppsemanticinfoupdater.h",
"cppsourceprocessor.cpp", "cppsourceprocessor.h",
+ "cpptoolsbridge.cpp", "cpptoolsbridge.h",
+ "cpptoolsbridgeinterface.h",
+ "cpptoolsbridgeqtcreatorimplementation.cpp", "cpptoolsbridgeqtcreatorimplementation.h",
"cpptools.qrc",
"cpptools_global.h",
"cpptoolsconstants.h",
diff --git a/src/plugins/cpptools/cpptoolsbridge.cpp b/src/plugins/cpptools/cpptoolsbridge.cpp
new file mode 100644
index 0000000000..9aec62df33
--- /dev/null
+++ b/src/plugins/cpptools/cpptoolsbridge.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "cpptoolsbridge.h"
+
+#include "cpptoolsbridgeinterface.h"
+
+namespace CppTools {
+
+std::unique_ptr<CppToolsBridgeInterface> CppToolsBridge::m_interface;
+
+void CppToolsBridge::setCppToolsBridgeImplementation(std::unique_ptr<CppToolsBridgeInterface> &&interface)
+{
+ m_interface = std::move(interface);
+}
+
+CppTools::CppEditorDocumentHandle *CppToolsBridge::cppEditorDocument(const QString &filePath)
+{
+ return m_interface->cppEditorDocument(filePath);
+}
+
+QString CppToolsBridge::projectPartIdForFile(const QString &filePath)
+{
+ return m_interface->projectPartIdForFile(filePath);
+}
+
+BaseEditorDocumentProcessor *CppToolsBridge::baseEditorDocumentProcessor(const QString &filePath)
+{
+ return m_interface->baseEditorDocumentProcessor(filePath);
+}
+
+void CppToolsBridge::finishedRefreshingSourceFiles(const QSet<QString> &filePaths)
+{
+ m_interface->finishedRefreshingSourceFiles(filePaths);
+}
+
+} // namespace CppTools
diff --git a/src/plugins/cpptools/cpptoolsbridge.h b/src/plugins/cpptools/cpptoolsbridge.h
new file mode 100644
index 0000000000..860b6a7ee7
--- /dev/null
+++ b/src/plugins/cpptools/cpptoolsbridge.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef CPPTOOLS_CPPTOOLSBRIDGE_H
+#define CPPTOOLS_CPPTOOLSBRIDGE_H
+
+#include "cpptools_global.h"
+
+#include <QString>
+
+#include <memory>
+
+namespace CppTools {
+class CppEditorDocumentHandle;
+class BaseEditorDocumentProcessor;
+class CppToolsBridgeInterface;
+
+class CPPTOOLS_EXPORT CppToolsBridge
+{
+public:
+ static void setCppToolsBridgeImplementation(std::unique_ptr<CppToolsBridgeInterface> &&interface
+);
+
+ static CppEditorDocumentHandle *cppEditorDocument(const QString &filePath);
+ static QString projectPartIdForFile(const QString &filePath);
+ static BaseEditorDocumentProcessor *baseEditorDocumentProcessor(const QString &filePath);
+ static void finishedRefreshingSourceFiles(const QSet<QString> &filePaths);
+
+private:
+ static std::unique_ptr<CppToolsBridgeInterface> m_interface;
+};
+
+} // namespace CppTools
+
+#endif // CPPTOOLS_CPPTOOLSBRIDGE_H
diff --git a/src/plugins/cpptools/cpptoolsbridgeinterface.h b/src/plugins/cpptools/cpptoolsbridgeinterface.h
new file mode 100644
index 0000000000..cdc17aa58c
--- /dev/null
+++ b/src/plugins/cpptools/cpptoolsbridgeinterface.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef CPPTOOLSBRIDGEINTERFACE_H
+#define CPPTOOLSBRIDGEINTERFACE_H
+
+#include <QtGlobal>
+
+QT_BEGIN_NAMESPACE
+class QString;
+QT_END_NAMESPACE
+
+namespace CppTools {
+class CppEditorDocumentHandle;
+class BaseEditorDocumentProcessor;
+
+class CppToolsBridgeInterface
+{
+public:
+ virtual ~CppToolsBridgeInterface() = default;
+ virtual CppEditorDocumentHandle *cppEditorDocument(const QString &filePath) const = 0;
+ virtual QString projectPartIdForFile(const QString &filePath) const = 0;
+ virtual BaseEditorDocumentProcessor *baseEditorDocumentProcessor(const QString &filePath) const = 0;
+ virtual void finishedRefreshingSourceFiles(const QSet<QString> &filePaths) const = 0;
+};
+
+} // namespace CppTools
+
+#endif // CPPTOOLSBRIDGEINTERFACE_H
diff --git a/src/plugins/cpptools/cpptoolsbridgeqtcreatorimplementation.cpp b/src/plugins/cpptools/cpptoolsbridgeqtcreatorimplementation.cpp
new file mode 100644
index 0000000000..9edfcfddf5
--- /dev/null
+++ b/src/plugins/cpptools/cpptoolsbridgeqtcreatorimplementation.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "cpptoolsbridgeqtcreatorimplementation.h"
+
+#include "baseeditordocumentparser.h"
+#include "cppmodelmanager.h"
+#include "cppprojects.h"
+#include "editordocumenthandle.h"
+
+namespace CppTools {
+
+namespace Internal {
+
+CppEditorDocumentHandle *
+CppToolsBridgeQtCreatorImplementation::cppEditorDocument(const QString &filePath) const
+{
+ return CppModelManager::instance()->cppEditorDocument(filePath);
+}
+
+namespace {
+
+CppTools::ProjectPart::Ptr projectPartForFile(const QString &filePath)
+{
+ if (const auto parser = BaseEditorDocumentParser::get(filePath))
+ return parser->projectPart();
+
+ return CppTools::ProjectPart::Ptr();
+}
+
+bool isProjectPartValid(const CppTools::ProjectPart::Ptr projectPart)
+{
+ if (projectPart)
+ return CppTools::CppModelManager::instance()->projectPartForId(projectPart->id());
+
+ return false;
+}
+
+} // anonymous namespace
+
+QString CppToolsBridgeQtCreatorImplementation::projectPartIdForFile(const QString &filePath) const
+{
+ const CppTools::ProjectPart::Ptr projectPart = projectPartForFile(filePath);
+
+ if (isProjectPartValid(projectPart))
+ return projectPart->id(); // OK, Project Part is still loaded
+
+ return QString();
+}
+
+BaseEditorDocumentProcessor *
+CppToolsBridgeQtCreatorImplementation::baseEditorDocumentProcessor(const QString &filePath) const
+{
+ auto *document = cppEditorDocument(filePath);
+ if (document)
+ return document->processor();
+
+ return 0;
+}
+
+void CppToolsBridgeQtCreatorImplementation::finishedRefreshingSourceFiles(
+ const QSet<QString> &filePaths) const
+{
+ CppModelManager::instance()->finishedRefreshingSourceFiles(filePaths);
+}
+
+} // namespace Internal
+
+} // namespace CppTools
diff --git a/src/plugins/cpptools/cpptoolsbridgeqtcreatorimplementation.h b/src/plugins/cpptools/cpptoolsbridgeqtcreatorimplementation.h
new file mode 100644
index 0000000000..772c7f96a8
--- /dev/null
+++ b/src/plugins/cpptools/cpptoolsbridgeqtcreatorimplementation.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef CPPTOOLS_CPPTOOLSBRIDGEQTCREATORIMPLEMENTATION_H
+#define CPPTOOLS_CPPTOOLSBRIDGEQTCREATORIMPLEMENTATION_H
+
+#include "cpptoolsbridgeinterface.h"
+
+namespace CppTools {
+
+namespace Internal {
+
+class CppToolsBridgeQtCreatorImplementation final : public CppToolsBridgeInterface
+{
+public:
+ CppEditorDocumentHandle *cppEditorDocument(const QString &filePath) const override;
+ QString projectPartIdForFile(const QString &filePath) const override;
+ BaseEditorDocumentProcessor *baseEditorDocumentProcessor(const QString &filePath) const override;
+ void finishedRefreshingSourceFiles(const QSet<QString> &filePaths) const override;
+};
+
+} // namespace Internal
+} // namespace CppTools
+
+#endif // CPPTOOLS_CPPTOOLSBRIDGEQTCREATORIMPLEMENTATION_H
diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp
index f113c5fc62..6298f7a391 100644
--- a/src/plugins/cpptools/cpptoolsplugin.cpp
+++ b/src/plugins/cpptools/cpptoolsplugin.cpp
@@ -45,6 +45,8 @@
#include "cppprojectfile.h"
#include "cpplocatordata.h"
#include "cppincludesfilter.h"
+#include "cpptoolsbridge.h"
+#include "cpptoolsbridgeqtcreatorimplementation.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -88,6 +90,8 @@ CppToolsPlugin::CppToolsPlugin()
, m_codeModelSettings(new CppCodeModelSettings)
{
m_instance = this;
+ auto bridgeImplementation = std::unique_ptr<CppToolsBridgeQtCreatorImplementation>(new CppToolsBridgeQtCreatorImplementation);
+ CppToolsBridge::setCppToolsBridgeImplementation(std::move(bridgeImplementation));
}
CppToolsPlugin::~CppToolsPlugin()