From 5f50a6ae343574bc247eb631c0a2314273f50add Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Fri, 3 Dec 2010 13:49:35 +0100 Subject: C++: Move the ModelManagerInterface from CppTools to CPlusPlus. --- src/plugins/cpptools/abstracteditorsupport.cpp | 4 +- src/plugins/cpptools/abstracteditorsupport.h | 67 ++++++++ src/plugins/cpptools/cppfindreferences.cpp | 20 +-- src/plugins/cpptools/cppfindreferences.h | 8 +- src/plugins/cpptools/cppmodelmanager.cpp | 11 +- src/plugins/cpptools/cppmodelmanager.h | 12 +- src/plugins/cpptools/cppmodelmanagerinterface.h | 185 ----------------------- src/plugins/cpptools/cpprefactoringchanges.cpp | 3 +- src/plugins/cpptools/cpprefactoringchanges.h | 6 +- src/plugins/cpptools/cpptools.pro | 4 +- src/plugins/cpptools/uicodecompletionsupport.cpp | 5 +- src/plugins/cpptools/uicodecompletionsupport.h | 8 +- 12 files changed, 114 insertions(+), 219 deletions(-) create mode 100644 src/plugins/cpptools/abstracteditorsupport.h delete mode 100644 src/plugins/cpptools/cppmodelmanagerinterface.h (limited to 'src/plugins/cpptools') diff --git a/src/plugins/cpptools/abstracteditorsupport.cpp b/src/plugins/cpptools/abstracteditorsupport.cpp index f032b9b482..2c0e3043ad 100644 --- a/src/plugins/cpptools/abstracteditorsupport.cpp +++ b/src/plugins/cpptools/abstracteditorsupport.cpp @@ -31,7 +31,7 @@ ** **************************************************************************/ -#include "cppmodelmanagerinterface.h" +#include "abstracteditorsupport.h" #include "cpptoolsconstants.h" #include "cppfilesettingspage.h" @@ -46,6 +46,8 @@ #include #include +using namespace CPlusPlus; + namespace CppTools { AbstractEditorSupport::AbstractEditorSupport(CppModelManagerInterface *modelmanager) : diff --git a/src/plugins/cpptools/abstracteditorsupport.h b/src/plugins/cpptools/abstracteditorsupport.h new file mode 100644 index 0000000000..d78c43ae12 --- /dev/null +++ b/src/plugins/cpptools/abstracteditorsupport.h @@ -0,0 +1,67 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef ABSTRACTEDITORSUPPORT_H +#define ABSTRACTEDITORSUPPORT_H + +#include "cpptools_global.h" + +#include + +namespace CppTools { + +class CPPTOOLS_EXPORT AbstractEditorSupport +{ +public: + explicit AbstractEditorSupport(CPlusPlus::CppModelManagerInterface *modelmanager); + virtual ~AbstractEditorSupport(); + + virtual QByteArray contents() const = 0; + virtual QString fileName() const = 0; + + void updateDocument(); + + // TODO: find a better place for common utility functions + static QString functionAt(const CPlusPlus::CppModelManagerInterface *mm, + const QString &fileName, + int line, int column); + + static QString licenseTemplate(const QString &file = QString(), const QString &className = QString()); + +private: + CPlusPlus::CppModelManagerInterface *m_modelmanager; +}; + +} + +#endif // ABSTRACTEDITORSUPPORT_H diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index 99726282e6..c1ef4ddae0 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -32,7 +32,6 @@ **************************************************************************/ #include "cppfindreferences.h" -#include "cppmodelmanagerinterface.h" #include "cpptoolsconstants.h" #include @@ -54,6 +53,7 @@ #include #include +#include #include #include #include @@ -72,7 +72,7 @@ using namespace CppTools::Internal; using namespace CPlusPlus; static QString getSource(const QString &fileName, - const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy) + const CppModelManagerInterface::WorkingCopy &workingCopy) { if (workingCopy.contains(fileName)) { return workingCopy.source(fileName); @@ -89,13 +89,13 @@ namespace { class ProcessFile: public std::unary_function > { - const CppTools::CppModelManagerInterface::WorkingCopy workingCopy; + const CppModelManagerInterface::WorkingCopy workingCopy; const Snapshot snapshot; Document::Ptr symbolDocument; Symbol *symbol; public: - ProcessFile(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy, + ProcessFile(const CppModelManagerInterface::WorkingCopy &workingCopy, const Snapshot snapshot, Document::Ptr symbolDocument, Symbol *symbol) @@ -157,7 +157,7 @@ public: } // end of anonymous namespace -CppFindReferences::CppFindReferences(CppTools::CppModelManagerInterface *modelManager) +CppFindReferences::CppFindReferences(CppModelManagerInterface *modelManager) : QObject(modelManager), _modelManager(modelManager), _resultWindow(Find::SearchResultWindow::instance()) @@ -183,7 +183,7 @@ QList CppFindReferences::references(Symbol *symbol, const LookupContext &co } static void find_helper(QFutureInterface &future, - const CppTools::CppModelManagerInterface::WorkingCopy workingCopy, + const CppModelManagerInterface::WorkingCopy workingCopy, const LookupContext context, CppFindReferences *findRefs, Symbol *symbol) @@ -260,7 +260,7 @@ void CppFindReferences::findAll_helper(Symbol *symbol, const LookupContext &cont _resultWindow->popup(true); - const CppTools::CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy(); + const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy(); Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); @@ -321,12 +321,12 @@ namespace { class FindMacroUsesInFile: public std::unary_function > { - const CppTools::CppModelManagerInterface::WorkingCopy workingCopy; + const CppModelManagerInterface::WorkingCopy workingCopy; const Snapshot snapshot; const Macro ¯o; public: - FindMacroUsesInFile(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy, + FindMacroUsesInFile(const CppModelManagerInterface::WorkingCopy &workingCopy, const Snapshot snapshot, const Macro ¯o) : workingCopy(workingCopy), snapshot(snapshot), macro(macro) @@ -388,7 +388,7 @@ public: } // end of anonymous namespace static void findMacroUses_helper(QFutureInterface &future, - const CppTools::CppModelManagerInterface::WorkingCopy workingCopy, + const CppModelManagerInterface::WorkingCopy workingCopy, const Snapshot snapshot, CppFindReferences *findRefs, const Macro macro) diff --git a/src/plugins/cpptools/cppfindreferences.h b/src/plugins/cpptools/cppfindreferences.h index ab1378ce2a..1652851264 100644 --- a/src/plugins/cpptools/cppfindreferences.h +++ b/src/plugins/cpptools/cppfindreferences.h @@ -51,9 +51,11 @@ namespace Find { struct SearchResultItem; } // end of namespace Find -namespace CppTools { +namespace CPlusPlus { class CppModelManagerInterface; +} +namespace CppTools { namespace Internal { class CppFindReferences: public QObject @@ -61,7 +63,7 @@ class CppFindReferences: public QObject Q_OBJECT public: - CppFindReferences(CppModelManagerInterface *modelManager); + CppFindReferences(CPlusPlus::CppModelManagerInterface *modelManager); virtual ~CppFindReferences(); QList references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) const; @@ -90,7 +92,7 @@ private: void setDependencyTable(const CPlusPlus::DependencyTable &newTable); private: - QPointer _modelManager; + QPointer _modelManager; Find::SearchResultWindow *_resultWindow; QFutureWatcher m_watcher; diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index f476e86ae0..efe8175dcb 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -35,6 +35,7 @@ #include #include "cppmodelmanager.h" +#include "abstracteditorsupport.h" #ifndef ICHECK_BUILD # include "cpptoolsconstants.h" # include "cpptoolseditorsupport.h" @@ -189,7 +190,7 @@ CppPreprocessor::~CppPreprocessor() void CppPreprocessor::setRevision(unsigned revision) { m_revision = revision; } -void CppPreprocessor::setWorkingCopy(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy) +void CppPreprocessor::setWorkingCopy(const CppModelManagerInterface::WorkingCopy &workingCopy) { m_workingCopy = workingCopy; } void CppPreprocessor::setIncludePaths(const QStringList &includePaths) @@ -617,7 +618,7 @@ Document::Ptr CppPreprocessor::switchDocument(Document::Ptr doc) } #ifndef ICHECK_BUILD -void CppTools::CppModelManagerInterface::updateModifiedSourceFiles() +void CppModelManager::updateModifiedSourceFiles() { const Snapshot snapshot = this->snapshot(); QStringList sourceFiles; @@ -636,11 +637,10 @@ void CppTools::CppModelManagerInterface::updateModifiedSourceFiles() updateSourceFiles(sourceFiles); } -CppTools::CppModelManagerInterface *CppTools::CppModelManagerInterface::instance() +CppModelManager *CppModelManager::instance() { ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance(); - return pluginManager->getObject(); - + return pluginManager->getObject(); } @@ -1417,5 +1417,6 @@ void CppModelManager::GC() m_snapshot = newSnapshot; protectSnapshot.unlock(); } + #endif diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index e167832eb5..865421a16e 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -34,7 +34,8 @@ #ifndef CPPMODELMANAGER_H #define CPPMODELMANAGER_H -#include +#include "cpptools_global.h" +#include #ifndef ICHECK_BUILD # include #endif @@ -83,7 +84,7 @@ class CppPreprocessor; class CppFindReferences; #ifndef ICHECK_BUILD -class CppModelManager : public CppModelManagerInterface +class CppModelManager : public CPlusPlus::CppModelManagerInterface { Q_OBJECT @@ -91,6 +92,8 @@ public: CppModelManager(QObject *parent); virtual ~CppModelManager(); + static CppModelManager *instance(); + virtual QFuture updateSourceFiles(const QStringList &sourceFiles); virtual WorkingCopy workingCopy() const; @@ -139,6 +142,7 @@ Q_SIGNALS: public Q_SLOTS: void editorOpened(Core::IEditor *editor); void editorAboutToClose(Core::IEditor *editor); + virtual void updateModifiedSourceFiles(); private Q_SLOTS: // this should be executed in the GUI thread. @@ -251,7 +255,7 @@ public: virtual ~CppPreprocessor(); void setRevision(unsigned revision); - void setWorkingCopy(const CppModelManagerInterface::WorkingCopy &workingCopy); + void setWorkingCopy(const CPlusPlus::CppModelManagerInterface::WorkingCopy &workingCopy); void setIncludePaths(const QStringList &includePaths); void setFrameworkPaths(const QStringList &frameworkPaths); void addFrameworkPath(const QString &frameworkPath); @@ -299,7 +303,7 @@ private: CPlusPlus::Preprocessor preprocess; QStringList m_includePaths; QStringList m_systemIncludePaths; - CppModelManagerInterface::WorkingCopy m_workingCopy; + CPlusPlus::CppModelManagerInterface::WorkingCopy m_workingCopy; QStringList m_projectFiles; QStringList m_frameworkPaths; QSet m_included; diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h deleted file mode 100644 index 4dcc96d8a0..0000000000 --- a/src/plugins/cpptools/cppmodelmanagerinterface.h +++ /dev/null @@ -1,185 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** No Commercial Usage -** -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#ifndef CPPMODELMANAGERINTERFACE_H -#define CPPMODELMANAGERINTERFACE_H - -#include -#include -#include -#include -#include -#include -#include - -namespace Core { - class IEditor; -} - -namespace CPlusPlus { - class LookupContext; -} - -namespace ProjectExplorer { - class Project; -} - -namespace TextEditor { - class ITextEditor; -} - -namespace CppTools { - -class AbstractEditorSupport; - -namespace Internal { -class CppEditorSupport; -} - -class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject -{ - Q_OBJECT - -public: - class ProjectInfo - { - public: - ProjectInfo() - { } - - ProjectInfo(QPointer project) - : project(project) - { } - - operator bool() const - { return ! project.isNull(); } - - bool isValid() const - { return ! project.isNull(); } - - bool isNull() const - { return project.isNull(); } - - public: // attributes - QPointer project; - QString projectPath; - QByteArray defines; - QStringList sourceFiles; - QStringList includePaths; - QStringList frameworkPaths; - QStringList precompiledHeaders; - }; - - class WorkingCopy - { - public: - void insert(const QString &fileName, const QString &source, unsigned revision = 0) - { _elements.insert(fileName, qMakePair(source, revision)); } - - bool contains(const QString &fileName) const - { return _elements.contains(fileName); } - - QString source(const QString &fileName) const - { return _elements.value(fileName).first; } - - QPair get(const QString &fileName) const - { return _elements.value(fileName); } - - private: - typedef QHash > Table; - Table _elements; - }; - -public: - CppModelManagerInterface(QObject *parent = 0) : QObject(parent) {} - virtual ~CppModelManagerInterface() {} - - static CppModelManagerInterface *instance(); - - virtual bool isCppEditor(Core::IEditor *editor) const = 0; - - virtual WorkingCopy workingCopy() const = 0; - virtual CPlusPlus::Snapshot snapshot() const = 0; - - virtual QList projectInfos() const = 0; - virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const = 0; - virtual void updateProjectInfo(const ProjectInfo &pinfo) = 0; - - virtual QStringList includesInPath(const QString &path) const = 0; - - virtual void addEditorSupport(AbstractEditorSupport *editorSupport) = 0; - virtual void removeEditorSupport(AbstractEditorSupport *editorSupport) = 0; - - virtual QList references(CPlusPlus::Symbol *symbol, - const CPlusPlus::LookupContext &context) = 0; - - virtual void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context, - const QString &replacement = QString()) = 0; - virtual void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) = 0; - - virtual void findMacroUsages(const CPlusPlus::Macro ¯o) = 0; - -Q_SIGNALS: - void documentUpdated(CPlusPlus::Document::Ptr doc); - -public Q_SLOTS: - void updateModifiedSourceFiles(); - virtual QFuture updateSourceFiles(const QStringList &sourceFiles) = 0; - virtual void GC() = 0; -}; - -class CPPTOOLS_EXPORT AbstractEditorSupport -{ -public: - explicit AbstractEditorSupport(CppModelManagerInterface *modelmanager); - virtual ~AbstractEditorSupport(); - - virtual QByteArray contents() const = 0; - virtual QString fileName() const = 0; - - void updateDocument(); - - // TODO: find a better place for common utility functions - static QString functionAt(const CppModelManagerInterface *mm, - const QString &fileName, - int line, int column); - - static QString licenseTemplate(const QString &file = QString(), const QString &className = QString()); - -private: - CppModelManagerInterface *m_modelmanager; -}; - -} // namespace CppTools - -#endif // CPPMODELMANAGERINTERFACE_H diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp index 29f44a7654..7633150f15 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.cpp +++ b/src/plugins/cpptools/cpprefactoringchanges.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -47,7 +48,7 @@ using namespace Utils; CppRefactoringChanges::CppRefactoringChanges(const Snapshot &snapshot) : m_snapshot(snapshot) - , m_modelManager(CppTools::CppModelManagerInterface::instance()) + , m_modelManager(Internal::CppModelManager::instance()) { Q_ASSERT(m_modelManager); m_workingCopy = m_modelManager->workingCopy(); diff --git a/src/plugins/cpptools/cpprefactoringchanges.h b/src/plugins/cpptools/cpprefactoringchanges.h index d4add01b5e..2e86d2fec9 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.h +++ b/src/plugins/cpptools/cpprefactoringchanges.h @@ -35,10 +35,10 @@ #define CPPREFACTORINGCHANGES_H #include +#include #include #include -#include #include #include @@ -99,8 +99,8 @@ private: CPlusPlus::Document::Ptr m_thisDocument; CPlusPlus::Snapshot m_snapshot; CPlusPlus::LookupContext m_context; - CppTools::CppModelManagerInterface *m_modelManager; - CppTools::CppModelManagerInterface::WorkingCopy m_workingCopy; + CPlusPlus::CppModelManagerInterface *m_modelManager; + CPlusPlus::CppModelManagerInterface::WorkingCopy m_workingCopy; }; } // namespace CppTools diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 57507f3612..f970e74860 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -14,7 +14,6 @@ HEADERS += completionsettingspage.h \ cppcurrentdocumentfilter.h \ cppfunctionsfilter.h \ cppmodelmanager.h \ - cppmodelmanagerinterface.h \ cpplocatorfilter.h \ cpptools_global.h \ cpptoolsconstants.h \ @@ -28,7 +27,8 @@ HEADERS += completionsettingspage.h \ symbolsfindfilter.h \ uicodecompletionsupport.h \ insertionpointlocator.h \ - cpprefactoringchanges.h + cpprefactoringchanges.h \ + abstracteditorsupport.h SOURCES += completionsettingspage.cpp \ cppclassesfilter.cpp \ diff --git a/src/plugins/cpptools/uicodecompletionsupport.cpp b/src/plugins/cpptools/uicodecompletionsupport.cpp index 945425aa11..e0e2c35c2a 100644 --- a/src/plugins/cpptools/uicodecompletionsupport.cpp +++ b/src/plugins/cpptools/uicodecompletionsupport.cpp @@ -37,11 +37,12 @@ enum { debug = 0 }; using namespace CppTools; +using namespace CPlusPlus; -UiCodeModelSupport::UiCodeModelSupport(CppTools::CppModelManagerInterface *modelmanager, +UiCodeModelSupport::UiCodeModelSupport(CppModelManagerInterface *modelmanager, const QString &source, const QString &uiHeaderFile) - : CppTools::AbstractEditorSupport(modelmanager), + : AbstractEditorSupport(modelmanager), m_sourceName(source), m_fileName(uiHeaderFile), m_updateIncludingFiles(false), diff --git a/src/plugins/cpptools/uicodecompletionsupport.h b/src/plugins/cpptools/uicodecompletionsupport.h index cac8219445..9afbe967e4 100644 --- a/src/plugins/cpptools/uicodecompletionsupport.h +++ b/src/plugins/cpptools/uicodecompletionsupport.h @@ -35,17 +35,19 @@ #ifndef UICODECOMPLETIONSUPPORT_H #define UICODECOMPLETIONSUPPORT_H -#include "cppmodelmanagerinterface.h" #include "cpptools_global.h" +#include "abstracteditorsupport.h" + +#include #include namespace CppTools { -class CPPTOOLS_EXPORT UiCodeModelSupport : public CppTools::AbstractEditorSupport +class CPPTOOLS_EXPORT UiCodeModelSupport : public AbstractEditorSupport { public: - UiCodeModelSupport(CppTools::CppModelManagerInterface *modelmanager, + UiCodeModelSupport(CPlusPlus::CppModelManagerInterface *modelmanager, const QString &sourceFile, const QString &uiHeaderFile); ~UiCodeModelSupport(); -- cgit v1.2.1