cppmodelmanager.h 7.75 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
** 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
Eike Ziller's avatar
Eike Ziller committed
13 14
** conditions see http://www.qt.io/licensing.  For further information
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** 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.
hjk's avatar
hjk committed
24 25 26
**
** 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
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
hjk's avatar
hjk committed
30

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

34 35 36
#include "cpptools_global.h"

#include "cppprojects.h"
37

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

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

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

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

namespace CppTools {
54

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

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

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

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

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

79 80
    static CppModelManager *instance();

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

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

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

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

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

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

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

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

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

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

124 125 126
    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
127

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

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

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

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

142
    QStringList projectFiles();
143

144
    ProjectPart::HeaderPaths headerPaths();
145

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

149
    QByteArray definedMacros();
150

151 152
    void enableGarbageCollector(bool enable);

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

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

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

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

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

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

private:
190
    void delayedGC();
191
    void recalculateFileToProjectParts();
192
    void updateVisibleEditorDocuments() const;
193

194
    void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
195 196 197
    void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
    void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);

198
    QList<EditorDocumentHandle *> cppEditors() const;
199

200 201
    WorkingCopy buildWorkingCopyList();

202
    void ensureUpdated();
203
    QStringList internalProjectFiles() const;
204
    ProjectPart::HeaderPaths internalHeaderPaths() const;
205
    QByteArray internalDefinedMacros() const;
206

207
    void dumpModelManagerConfiguration(const QString &logFileId);
208

209
private:
210
    Internal::CppModelManagerPrivate *d;
con's avatar
con committed
211
};
212

con's avatar
con committed
213 214 215
} // namespace CppTools

#endif // CPPMODELMANAGER_H