C++: Move the ModelManagerInterface from CppTools to CPlusPlus.

This commit is contained in:
Christian Kamm
2010-12-03 13:49:35 +01:00
parent 5de7be5f91
commit 5f50a6ae34
45 changed files with 268 additions and 146 deletions

View File

@@ -31,7 +31,7 @@
**
**************************************************************************/
#include "cppmodelmanagerinterface.h"
#include "abstracteditorsupport.h"
#include "cpptoolsconstants.h"
#include "cppfilesettingspage.h"
@@ -46,6 +46,8 @@
#include <coreplugin/icore.h>
#include <QtCore/QDebug>
using namespace CPlusPlus;
namespace CppTools {
AbstractEditorSupport::AbstractEditorSupport(CppModelManagerInterface *modelmanager) :

View File

@@ -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 <cplusplus/ModelManagerInterface.h>
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

View File

@@ -32,7 +32,6 @@
**************************************************************************/
#include "cppfindreferences.h"
#include "cppmodelmanagerinterface.h"
#include "cpptoolsconstants.h"
#include <texteditor/basetexteditor.h>
@@ -54,6 +53,7 @@
#include <Names.h>
#include <Scope.h>
#include <cplusplus/ModelManagerInterface.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/Overview.h>
#include <cplusplus/FindUsages.h>
@@ -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<QString, QList<Usage> >
{
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<int> CppFindReferences::references(Symbol *symbol, const LookupContext &co
}
static void find_helper(QFutureInterface<Usage> &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<QString, QList<Usage> >
{
const CppTools::CppModelManagerInterface::WorkingCopy workingCopy;
const CppModelManagerInterface::WorkingCopy workingCopy;
const Snapshot snapshot;
const Macro &macro;
public:
FindMacroUsesInFile(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy,
FindMacroUsesInFile(const CppModelManagerInterface::WorkingCopy &workingCopy,
const Snapshot snapshot,
const Macro &macro)
: workingCopy(workingCopy), snapshot(snapshot), macro(macro)
@@ -388,7 +388,7 @@ public:
} // end of anonymous namespace
static void findMacroUses_helper(QFutureInterface<Usage> &future,
const CppTools::CppModelManagerInterface::WorkingCopy workingCopy,
const CppModelManagerInterface::WorkingCopy workingCopy,
const Snapshot snapshot,
CppFindReferences *findRefs,
const Macro macro)

View File

@@ -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<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) const;
@@ -90,7 +92,7 @@ private:
void setDependencyTable(const CPlusPlus::DependencyTable &newTable);
private:
QPointer<CppModelManagerInterface> _modelManager;
QPointer<CPlusPlus::CppModelManagerInterface> _modelManager;
Find::SearchResultWindow *_resultWindow;
QFutureWatcher<CPlusPlus::Usage> m_watcher;

View File

@@ -35,6 +35,7 @@
#include <cplusplus/Overview.h>
#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<CppTools::CppModelManagerInterface>();
return pluginManager->getObject<CppModelManager>();
}
@@ -1417,5 +1417,6 @@ void CppModelManager::GC()
m_snapshot = newSnapshot;
protectSnapshot.unlock();
}
#endif

View File

@@ -34,7 +34,8 @@
#ifndef CPPMODELMANAGER_H
#define CPPMODELMANAGER_H
#include <cpptools/cppmodelmanagerinterface.h>
#include "cpptools_global.h"
#include <cplusplus/ModelManagerInterface.h>
#ifndef ICHECK_BUILD
# include <projectexplorer/project.h>
#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<void> 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<QString> m_included;

View File

@@ -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 <cpptools/cpptools_global.h>
#include <cplusplus/CppDocument.h>
#include <QtCore/QObject>
#include <QtCore/QHash>
#include <QtCore/QPointer>
#include <QtCore/QStringList>
#include <QtCore/QFuture>
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<ProjectExplorer::Project> project)
: project(project)
{ }
operator bool() const
{ return ! project.isNull(); }
bool isValid() const
{ return ! project.isNull(); }
bool isNull() const
{ return project.isNull(); }
public: // attributes
QPointer<ProjectExplorer::Project> 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<QString, unsigned> get(const QString &fileName) const
{ return _elements.value(fileName); }
private:
typedef QHash<QString, QPair<QString, unsigned> > 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<ProjectInfo> 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<int> 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 &macro) = 0;
Q_SIGNALS:
void documentUpdated(CPlusPlus::Document::Ptr doc);
public Q_SLOTS:
void updateModifiedSourceFiles();
virtual QFuture<void> 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

View File

@@ -36,6 +36,7 @@
#include <TranslationUnit.h>
#include <AST.h>
#include <cpptools/cppcodeformatter.h>
#include <cpptools/cppmodelmanager.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabsettings.h>
@@ -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();

View File

@@ -35,10 +35,10 @@
#define CPPREFACTORINGCHANGES_H
#include <ASTfwd.h>
#include <cplusplus/ModelManagerInterface.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/LookupContext.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <cpptools/cpptools_global.h>
#include <texteditor/refactoringchanges.h>
@@ -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

View File

@@ -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 \

View File

@@ -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),

View File

@@ -35,17 +35,19 @@
#ifndef UICODECOMPLETIONSUPPORT_H
#define UICODECOMPLETIONSUPPORT_H
#include "cppmodelmanagerinterface.h"
#include "cpptools_global.h"
#include "abstracteditorsupport.h"
#include <cplusplus/ModelManagerInterface.h>
#include <QtCore/QDateTime>
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();