Files
qt-creator/src/plugins/cpptools/cppmodelmanager.h

213 lines
7.6 KiB
C
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01:00
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
2008-12-02 15:08:31 +01:00
2008-12-02 12:01:29 +01:00
#ifndef CPPMODELMANAGER_H
#define CPPMODELMANAGER_H
#include "cpptools_global.h"
#include "cppprojects.h"
#include <projectexplorer/project.h>
#include <texteditor/basetexteditor.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/cppmodelmanagerbase.h>
#include <QFuture>
#include <QObject>
#include <QStringList>
2008-12-02 12:01:29 +01:00
namespace Core { class IEditor; }
namespace CPlusPlus { class LookupContext; }
namespace ProjectExplorer { class Project; }
namespace TextEditor { class TextDocument; }
2008-12-02 12:01:29 +01:00
namespace CppTools {
class AbstractEditorSupport;
class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider;
class EditorDocumentHandle;
class CppIndexingSupport;
class ModelManagerSupport;
class WorkingCopy;
2008-12-02 12:01:29 +01:00
namespace Internal {
class CppSourceProcessor;
class CppModelManagerPrivate;
}
2008-12-02 12:01:29 +01:00
class CPPTOOLS_EXPORT CppModelManager : public CPlusPlus::CppModelManagerBase
2008-12-02 12:01:29 +01:00
{
Q_OBJECT
public:
typedef CPlusPlus::Document Document;
2008-12-02 12:01:29 +01:00
public:
CppModelManager(QObject *parent = 0);
~CppModelManager();
2008-12-02 12:01:29 +01:00
static CppModelManager *instance();
// Documented in source file.
enum ProgressNotificationMode {
ForcedProgressNotification,
ReservedProgressNotification
};
QFuture<void> updateSourceFiles(const QSet<QString> &sourceFiles,
ProgressNotificationMode mode = ReservedProgressNotification);
WorkingCopy workingCopy() const;
QByteArray codeModelConfiguration() const;
QList<ProjectInfo> projectInfos() const;
ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
QFuture<void> updateProjectInfo(const ProjectInfo &newProjectInfo);
/// \return The project part with the given project file
ProjectPart::Ptr projectPartForProjectFile(const QString &projectFile) const;
/// \return All project parts that mention the given file name as one of the sources/headers.
QList<ProjectPart::Ptr> projectPart(const QString &fileName) const;
/// This is a fall-back function: find all files that includes the file directly or indirectly,
/// and return its \c ProjectPart list for use with this file.
QList<ProjectPart::Ptr> projectPartFromDependencies(const QString &fileName) const;
/// \return A synthetic \c ProjectPart which consists of all defines/includes/frameworks from
/// all loaded projects.
ProjectPart::Ptr fallbackProjectPart() const;
CPlusPlus::Snapshot snapshot() const;
Document::Ptr document(const QString &fileName) const;
bool replaceDocument(Document::Ptr newDoc);
2008-12-02 12:01:29 +01:00
void emitDocumentUpdated(CPlusPlus::Document::Ptr doc);
bool isCppEditor(Core::IEditor *editor) const;
void addExtraEditorSupport(AbstractEditorSupport *editorSupport);
void removeExtraEditorSupport(AbstractEditorSupport *editorSupport);
C++: Base parsing on editor document instead of widget This mainly takes CppEditorSupport apart. * Parsing is now invoked by CPPEditorDocument itself by listening to QTextDocument::contentsChanged(). * Upon construction and destruction CPPEditorDocument creates and deletes an EditorDocumentHandle for (un)registration in the model manager. This handle provides everything to generate the working copy and to access the editor document processor. * A CPPEditorDocument owns a BaseEditorDocumentProcessor instance that controls parsing, semantic info recalculation and the semantic highlighting for the document. This is more or less what is left from CppEditorSupport and can be considered as the backend of a CPPEditorDocument. CPPEditorDocument itself is quite small. * BuiltinEditorDocumentProcessor and ClangEditorDocumentProcessor derive from BaseEditorDocumentProcessor and implement the gaps. * Since the semantic info calculation was bound to the widget, it also calculated the local uses, which depend on the cursor position. This calculation got moved into the extracted class UseSeletionsUpdater in the cppeditor plugin, which is run once the cursor position changes or the semantic info document is updated. * Some more logic got extracted: - SemanticInfoUpdater (logic was in CppEditorSupport) - SemanticHighlighter (logic was in CppEditorSupport) * The *Parser and *Processor classes can be easily accessed by the static function get(). * CppHighlightingSupport is gone since it turned out to be useless. * The editor dependency in CompletionAssistProviders is gone since we actually only need the file path now. Change-Id: I49d3a7bd138c5ed9620123e34480772535156508 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
2014-08-19 15:59:29 +02:00
EditorDocumentHandle *editorDocument(const QString &filePath);
void registerEditorDocument(EditorDocumentHandle *editorDocument);
void unregisterEditorDocument(const QString &filePath);
QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
const QString &replacement = QString());
void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
2009-08-07 13:02:36 +02:00
void findMacroUsages(const CPlusPlus::Macro &macro);
void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement);
void finishedRefreshingSourceFiles(const QSet<QString> &files);
void addModelManagerSupport(ModelManagerSupport *modelManagerSupport);
ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const;
CppCompletionAssistProvider *completionAssistProvider(const QString &mimeType) const;
BaseEditorDocumentProcessor *editorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) const;
void setIndexingSupport(CppIndexingSupport *indexingSupport);
CppIndexingSupport *indexingSupport();
QStringList projectFiles();
2008-12-04 17:07:43 +01:00
ProjectPart::HeaderPaths headerPaths();
2008-12-04 17:07:43 +01:00
// Use this *only* for auto tests
void setHeaderPaths(const ProjectPart::HeaderPaths &headerPaths);
2008-12-04 17:07:43 +01:00
QByteArray definedMacros();
2008-12-04 17:07:43 +01:00
void enableGarbageCollector(bool enable);
static QSet<QString> timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck);
static Internal::CppSourceProcessor *createSourceProcessor();
static QString configurationFileName();
static QString editorConfigurationFileName();
signals:
/// Project data might be locked while this is emitted.
void aboutToRemoveFiles(const QStringList &files);
void documentUpdated(CPlusPlus::Document::Ptr doc);
void sourceFilesRefreshed(const QSet<QString> &files);
/// \brief Emitted after updateProjectInfo function is called on the model-manager.
///
/// Other classes can use this to get notified when the \c ProjectExplorer has updated the parts.
void projectPartsUpdated(ProjectExplorer::Project *project);
void globalSnapshotChanged();
void gcFinished(); // Needed for tests.
public slots:
virtual void updateModifiedSourceFiles();
virtual void GC();
private slots:
// This should be executed in the GUI thread.
void onAboutToLoadSession();
void onAboutToUnloadSession();
void onProjectAdded(ProjectExplorer::Project *project);
void onAboutToRemoveProject(ProjectExplorer::Project *project);
void onSourceFilesRefreshed() const;
void onCoreAboutToClose();
private:
void delayedGC();
void recalculateFileToProjectParts();
void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);
C++: Base parsing on editor document instead of widget This mainly takes CppEditorSupport apart. * Parsing is now invoked by CPPEditorDocument itself by listening to QTextDocument::contentsChanged(). * Upon construction and destruction CPPEditorDocument creates and deletes an EditorDocumentHandle for (un)registration in the model manager. This handle provides everything to generate the working copy and to access the editor document processor. * A CPPEditorDocument owns a BaseEditorDocumentProcessor instance that controls parsing, semantic info recalculation and the semantic highlighting for the document. This is more or less what is left from CppEditorSupport and can be considered as the backend of a CPPEditorDocument. CPPEditorDocument itself is quite small. * BuiltinEditorDocumentProcessor and ClangEditorDocumentProcessor derive from BaseEditorDocumentProcessor and implement the gaps. * Since the semantic info calculation was bound to the widget, it also calculated the local uses, which depend on the cursor position. This calculation got moved into the extracted class UseSeletionsUpdater in the cppeditor plugin, which is run once the cursor position changes or the semantic info document is updated. * Some more logic got extracted: - SemanticInfoUpdater (logic was in CppEditorSupport) - SemanticHighlighter (logic was in CppEditorSupport) * The *Parser and *Processor classes can be easily accessed by the static function get(). * CppHighlightingSupport is gone since it turned out to be useless. * The editor dependency in CompletionAssistProviders is gone since we actually only need the file path now. Change-Id: I49d3a7bd138c5ed9620123e34480772535156508 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
2014-08-19 15:59:29 +02:00
QList<EditorDocumentHandle *> cppEditors() const;
WorkingCopy buildWorkingCopyList();
void ensureUpdated();
2008-12-08 14:48:51 +01:00
QStringList internalProjectFiles() const;
ProjectPart::HeaderPaths internalHeaderPaths() const;
2008-12-08 14:48:51 +01:00
QByteArray internalDefinedMacros() const;
2008-12-04 17:07:43 +01:00
void dumpModelManagerConfiguration(const QString &logFileId);
private:
Internal::CppModelManagerPrivate *d;
2008-12-02 12:01:29 +01:00
};
2008-12-02 12:01:29 +01:00
} // namespace CppTools
#endif // CPPMODELMANAGER_H