cppmodelmanager.h 7.57 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30 31 32
#ifndef CPPMODELMANAGER_H
#define CPPMODELMANAGER_H

33 34 35
#include "cpptools_global.h"

#include "cppprojects.h"
36

37
#include <projectexplorer/project.h>
38 39
#include <texteditor/basetexteditor.h>

40 41 42 43 44 45
#include <cplusplus/CppDocument.h>
#include <cplusplus/cppmodelmanagerbase.h>

#include <QFuture>
#include <QObject>
#include <QStringList>
con's avatar
con committed
46

47
namespace Core { class IEditor; }
48 49 50
namespace CPlusPlus { class LookupContext; }
namespace ProjectExplorer { class Project; }
namespace TextEditor { class BaseTextDocument; }
con's avatar
con committed
51 52

namespace CppTools {
53

54 55 56 57 58 59 60
class AbstractEditorSupport;
class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider;
class EditorDocumentHandle;
class CppIndexingSupport;
class ModelManagerSupport;
class WorkingCopy;
con's avatar
con committed
61

62
namespace Internal {
63
class CppSourceProcessor;
64 65
class CppModelManagerPrivate;
}
con's avatar
con committed
66

67
class CPPTOOLS_EXPORT CppModelManager : public CPlusPlus::CppModelManagerBase
con's avatar
con committed
68 69 70
{
    Q_OBJECT

71 72 73
public:
    typedef CPlusPlus::Document Document;

con's avatar
con committed
74
public:
75
    CppModelManager(QObject *parent = 0);
76
    ~CppModelManager();
con's avatar
con committed
77

78 79
    static CppModelManager *instance();

80 81 82 83 84 85 86
     // Documented in source file.
     enum ProgressNotificationMode {
        ForcedProgressNotification,
        ReservedProgressNotification
    };

    QFuture<void> updateSourceFiles(const QSet<QString> &sourceFiles,
87
        ProgressNotificationMode mode = ReservedProgressNotification);
88 89
    WorkingCopy workingCopy() const;
    QByteArray codeModelConfiguration() const;
90

91 92 93
    QList<ProjectInfo> projectInfos() const;
    ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
    QFuture<void> updateProjectInfo(const ProjectInfo &newProjectInfo);
94

95
    /// \return The project part with the given project file
96
    ProjectPart::Ptr projectPartForProjectFile(const QString &projectFile) const;
97
    /// \return All project parts that mention the given file name as one of the sources/headers.
98
    QList<ProjectPart::Ptr> projectPart(const QString &fileName) const;
99 100
    /// 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.
101
    QList<ProjectPart::Ptr> projectPartFromDependencies(const QString &fileName) const;
102 103
    /// \return A synthetic \c ProjectPart which consists of all defines/includes/frameworks from
    ///         all loaded projects.
104
    ProjectPart::Ptr fallbackProjectPart() const;
105

106 107
    CPlusPlus::Snapshot snapshot() const;
    Document::Ptr document(const QString &fileName) const;
108
    bool replaceDocument(Document::Ptr newDoc);
con's avatar
con committed
109 110 111

    void emitDocumentUpdated(CPlusPlus::Document::Ptr doc);

112
    bool isCppEditor(Core::IEditor *editor) const;
113

114 115
    void addExtraEditorSupport(AbstractEditorSupport *editorSupport);
    void removeExtraEditorSupport(AbstractEditorSupport *editorSupport);
116

117 118 119
    EditorDocumentHandle *editorDocument(const QString &filePath);
    void registerEditorDocument(EditorDocumentHandle *editorDocument);
    void unregisterEditorDocument(const QString &filePath);
120

121
    QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
122

123 124 125
    void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
                      const QString &replacement = QString());
    void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
Roberto Raggi's avatar
Roberto Raggi committed
126

127 128
    void findMacroUsages(const CPlusPlus::Macro &macro);
    void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement);
Christian Kamm's avatar
Christian Kamm committed
129

130
    void finishedRefreshingSourceFiles(const QSet<QString> &files);
131

132 133 134 135 136
    void addModelManagerSupport(ModelManagerSupport *modelManagerSupport);
    ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const;
    CppCompletionAssistProvider *completionAssistProvider(const QString &mimeType) const;
    BaseEditorDocumentProcessor *editorDocumentProcessor(
        TextEditor::BaseTextDocument *baseTextDocument) const;
137

138 139
    void setIndexingSupport(CppIndexingSupport *indexingSupport);
    CppIndexingSupport *indexingSupport();
140

141
    QStringList projectFiles();
142

143
    ProjectPart::HeaderPaths headerPaths();
144

145
    // Use this *only* for auto tests
146
    void setHeaderPaths(const ProjectPart::HeaderPaths &headerPaths);
147

148
    QByteArray definedMacros();
149

150 151
    void enableGarbageCollector(bool enable);

152
    static QSet<QString> timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck);
153

154 155 156
    static Internal::CppSourceProcessor *createSourceProcessor();
    static QString configurationFileName();
    static QString editorConfigurationFileName();
157

158
signals:
159 160 161 162 163 164 165 166 167 168 169 170 171
    /// 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();

172
    void gcFinished(); // Needed for tests.
173

174
public slots:
175
    virtual void updateModifiedSourceFiles();
176
    virtual void GC();
177

178 179
private slots:
    // This should be executed in the GUI thread.
180
    void onAboutToLoadSession();
181 182
    void onAboutToUnloadSession();
    void onProjectAdded(ProjectExplorer::Project *project);
183
    void onAboutToRemoveProject(ProjectExplorer::Project *project);
184
    void onSourceFilesRefreshed() const;
185
    void onCoreAboutToClose();
186 187

private:
188
    void delayedGC();
189 190
    void recalculateFileToProjectParts();

191
    void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
192 193 194
    void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
    void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);

195
    QList<EditorDocumentHandle *> cppEditors() const;
196

197 198
    WorkingCopy buildWorkingCopyList();

199
    void ensureUpdated();
200
    QStringList internalProjectFiles() const;
201
    ProjectPart::HeaderPaths internalHeaderPaths() const;
202
    QByteArray internalDefinedMacros() const;
203

204
    void dumpModelManagerConfiguration(const QString &logFileId);
205

206
private:
207
    Internal::CppModelManagerPrivate *d;
con's avatar
con committed
208
};
209

con's avatar
con committed
210 211 212
} // namespace CppTools

#endif // CPPMODELMANAGER_H