cppmodelmanager.h 8.73 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
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
** 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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** 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
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company 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
#include "cpptools_global.h"

36
#include "cppmodelmanagersupport.h"
37
#include "cppprojects.h"
38

39 40 41 42 43
#include <cplusplus/cppmodelmanagerbase.h>

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

45 46 47 48 49

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

namespace CppTools {
55

56 57 58
class AbstractEditorSupport;
class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider;
59
class CppEditorDocumentHandle;
60
class CppIndexingSupport;
61
class SymbolFinder;
62
class WorkingCopy;
con's avatar
con committed
63

64
namespace Internal {
65
class CppSourceProcessor;
66
class CppModelManagerPrivate;
67 68 69
}

namespace Tests {
hjk's avatar
hjk committed
70
class ModelManagerTestHelper;
71
}
con's avatar
con committed
72

73
class CPPTOOLS_EXPORT CppModelManager : public CPlusPlus::CppModelManagerBase
con's avatar
con committed
74 75 76
{
    Q_OBJECT

77 78 79
public:
    typedef CPlusPlus::Document Document;

con's avatar
con committed
80
public:
81
    CppModelManager(QObject *parent = 0);
82
    ~CppModelManager();
con's avatar
con committed
83

84 85
    static CppModelManager *instance();

86 87 88 89 90 91 92
     // Documented in source file.
     enum ProgressNotificationMode {
        ForcedProgressNotification,
        ReservedProgressNotification
    };

    QFuture<void> updateSourceFiles(const QSet<QString> &sourceFiles,
93
        ProgressNotificationMode mode = ReservedProgressNotification);
94 95
    WorkingCopy workingCopy() const;
    QByteArray codeModelConfiguration() const;
96

97 98 99
    QList<ProjectInfo> projectInfos() const;
    ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
    QFuture<void> updateProjectInfo(const ProjectInfo &newProjectInfo);
100

101
    /// \return The project part with the given project file
102
    ProjectPart::Ptr projectPartForId(const QString &projectPartId) const;
103
    /// \return All project parts that mention the given file name as one of the sources/headers.
104 105 106
    QList<ProjectPart::Ptr> projectPart(const Utils::FileName &fileName) const;
    QList<ProjectPart::Ptr> projectPart(const QString &fileName) const
    { return projectPart(Utils::FileName::fromString(fileName)); }
107 108
    /// 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.
109
    QList<ProjectPart::Ptr> projectPartFromDependencies(const Utils::FileName &fileName) const;
110 111
    /// \return A synthetic \c ProjectPart which consists of all defines/includes/frameworks from
    ///         all loaded projects.
112
    ProjectPart::Ptr fallbackProjectPart() const;
113

114 115
    CPlusPlus::Snapshot snapshot() const;
    Document::Ptr document(const QString &fileName) const;
116
    bool replaceDocument(Document::Ptr newDoc);
con's avatar
con committed
117 118

    void emitDocumentUpdated(CPlusPlus::Document::Ptr doc);
119 120 121
    void emitAbstractEditorSupportContentsUpdated(const QString &filePath,
                                                  const QByteArray &contents);
    void emitAbstractEditorSupportRemoved(const QString &filePath);
con's avatar
con committed
122

123
    bool isCppEditor(Core::IEditor *editor) const;
124
    bool isManagedByModelManagerSupport(Core::IDocument *document, const QString &id) const;
125

126
    QSet<AbstractEditorSupport*> abstractEditorSupports() const;
127 128
    void addExtraEditorSupport(AbstractEditorSupport *editorSupport);
    void removeExtraEditorSupport(AbstractEditorSupport *editorSupport);
129

130
    QList<CppEditorDocumentHandle *> cppEditorDocuments() const;
131 132 133
    CppEditorDocumentHandle *cppEditorDocument(const QString &filePath) const;
    void registerCppEditorDocument(CppEditorDocumentHandle *cppEditorDocument);
    void unregisterCppEditorDocument(const QString &filePath);
134

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

137 138 139
    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
140

141 142
    void findMacroUsages(const CPlusPlus::Macro &macro);
    void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement);
Christian Kamm's avatar
Christian Kamm committed
143

144
    void finishedRefreshingSourceFiles(const QSet<QString> &files);
145

146
    void addModelManagerSupportProvider(ModelManagerSupportProvider *modelManagerSupportProvider);
147 148
    CppCompletionAssistProvider *completionAssistProvider(const QString &mimeType) const;
    BaseEditorDocumentProcessor *editorDocumentProcessor(
149
        TextEditor::TextDocument *baseTextDocument) const;
150

151 152
    void setIndexingSupport(CppIndexingSupport *indexingSupport);
    CppIndexingSupport *indexingSupport();
153

154
    QStringList projectFiles();
155

156
    ProjectPart::HeaderPaths headerPaths();
157

158
    // Use this *only* for auto tests
159
    void setHeaderPaths(const ProjectPart::HeaderPaths &headerPaths);
160

161
    QByteArray definedMacros();
162

163 164
    void enableGarbageCollector(bool enable);

165 166
    SymbolFinder *symbolFinder();

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

169 170 171
    static Internal::CppSourceProcessor *createSourceProcessor();
    static QString configurationFileName();
    static QString editorConfigurationFileName();
172

173
signals:
174 175 176 177 178 179 180
    /// 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);

    void projectPartsUpdated(ProjectExplorer::Project *project);
181
    void projectPartsRemoved(const QStringList &projectPartIds);
182 183 184

    void globalSnapshotChanged();

185
    void gcFinished(); // Needed for tests.
186

187 188 189
    void abstractEditorSupportContentsUpdated(const QString &filePath, const QByteArray &contents);
    void abstractEditorSupportRemoved(const QString &filePath);

190
public slots:
191 192
    void updateModifiedSourceFiles();
    void GC();
193

194 195
private slots:
    // This should be executed in the GUI thread.
196
    friend class Tests::ModelManagerTestHelper;
197
    void onAboutToLoadSession();
198
    void onAboutToUnloadSession();
199
    void renameIncludes(const QString &oldFileName, const QString &newFileName);
200
    void onProjectAdded(ProjectExplorer::Project *project);
201
    void onAboutToRemoveProject(ProjectExplorer::Project *project);
202
    void onSourceFilesRefreshed() const;
203
    void onCurrentEditorChanged(Core::IEditor *editor);
204
    void onCodeModelSettingsChanged();
205
    void onCoreAboutToClose();
206 207

private:
208
    void delayedGC();
209
    void recalculateProjectPartMappings();
210
    void updateCppEditorDocuments() const;
211

212
    void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
213 214 215
    void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
    void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);

216 217 218 219 220 221
    void handleAddedModelManagerSupports(const QSet<QString> &supportIds);
    QList<ModelManagerSupport::Ptr> handleRemovedModelManagerSupports(
            const QSet<QString> &supportIds);
    void closeCppEditorDocuments();

    ModelManagerSupport::Ptr modelManagerSupportForMimeType(const QString &mimeType) const;
222

223 224
    WorkingCopy buildWorkingCopyList();

225
    void ensureUpdated();
226
    QStringList internalProjectFiles() const;
227
    ProjectPart::HeaderPaths internalHeaderPaths() const;
228
    QByteArray internalDefinedMacros() const;
229

230
    void dumpModelManagerConfiguration(const QString &logFileId);
231

232
private:
233
    Internal::CppModelManagerPrivate *d;
con's avatar
con committed
234
};
235

con's avatar
con committed
236 237 238
} // namespace CppTools

#endif // CPPMODELMANAGER_H