cppmodelmanager.h 8.33 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
    void updateCppEditorDocuments() const;
95 96
    WorkingCopy workingCopy() const;
    QByteArray codeModelConfiguration() const;
97

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

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

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

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

124
    static bool isCppEditor(Core::IEditor *editor);
125
    bool isClangCodeModelActive() const;
126

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

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

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

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

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

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

147
    void activateClangCodeModel(ModelManagerSupportProvider *modelManagerSupportProvider);
148
    CppCompletionAssistProvider *completionAssistProvider() const;
149
    BaseEditorDocumentProcessor *editorDocumentProcessor(
150
        TextEditor::TextDocument *baseTextDocument) const;
151

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

155
    QStringList projectFiles();
156

157
    ProjectPartHeaderPaths headerPaths();
158

159
    // Use this *only* for auto tests
160
    void setHeaderPaths(const ProjectPartHeaderPaths &headerPaths);
161

162
    QByteArray definedMacros();
163

164 165
    void enableGarbageCollector(bool enable);

166 167
    SymbolFinder *symbolFinder();

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

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

174
signals:
175 176 177 178 179 180 181
    /// 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);
182
    void projectPartsRemoved(const QStringList &projectPartIds);
183 184 185

    void globalSnapshotChanged();

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

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

191
public slots:
Nikolai Kosjar's avatar
Nikolai Kosjar committed
192 193
    void updateModifiedSourceFiles();
    void GC();
194

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

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

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

216 217
    WorkingCopy buildWorkingCopyList();

218
    void ensureUpdated();
219
    QStringList internalProjectFiles() const;
220
    ProjectPartHeaderPaths internalHeaderPaths() const;
221
    QByteArray internalDefinedMacros() const;
222

223
    void dumpModelManagerConfiguration(const QString &logFileId);
224

225
private:
226
    Internal::CppModelManagerPrivate *d;
con's avatar
con committed
227
};
228

con's avatar
con committed
229 230 231
} // namespace CppTools

#endif // CPPMODELMANAGER_H