cppmodelmanager.h 8.13 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
#include "cppmodelmanagerinterface.h"
34

35
#include <projectexplorer/project.h>
36 37
#include <texteditor/basetexteditor.h>

38 39
#include <QHash>
#include <QMutex>
40
#include <QTimer>
con's avatar
con committed
41

42
namespace Core { class IEditor; }
43
namespace TextEditor { class BaseTextEditorWidget; }
con's avatar
con committed
44 45

namespace CppTools {
46

con's avatar
con committed
47 48
namespace Internal {

Roberto Raggi's avatar
Roberto Raggi committed
49
class CppFindReferences;
50
class CppSourceProcessor;
con's avatar
con committed
51

52
class CppModelManager : public CppTools::CppModelManagerInterface
con's avatar
con committed
53 54 55
{
    Q_OBJECT

56 57 58
public:
    typedef CPlusPlus::Document Document;

con's avatar
con committed
59
public:
60
    CppModelManager(QObject *parent = 0);
con's avatar
con committed
61 62
    virtual ~CppModelManager();

63 64
    static CppModelManager *instance();

65
    virtual QFuture<void> updateSourceFiles(const QSet<QString> &sourceFiles,
66
        ProgressNotificationMode mode = ReservedProgressNotification);
67
    virtual WorkingCopy workingCopy() const;
68
    virtual QByteArray codeModelConfiguration() const;
69 70 71

    virtual QList<ProjectInfo> projectInfos() const;
    virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
72
    virtual QFuture<void> updateProjectInfo(const ProjectInfo &newProjectInfo);
73

74 75
    /// \return The project part with the given project file
    virtual ProjectPart::Ptr projectPartForProjectFile(const QString &projectFile) const;
76 77 78 79 80 81 82
    /// \return All project parts that mention the given file name as one of the sources/headers.
    virtual 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.
    virtual QList<ProjectPart::Ptr> projectPartFromDependencies(const QString &fileName) const;
    /// \return A synthetic \c ProjectPart which consists of all defines/includes/frameworks from
    ///         all loaded projects.
83
    virtual ProjectPart::Ptr fallbackProjectPart() const;
84

85
    virtual CPlusPlus::Snapshot snapshot() const;
86 87
    virtual Document::Ptr document(const QString &fileName) const;
    bool replaceDocument(Document::Ptr newDoc);
con's avatar
con committed
88 89 90

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

91 92 93 94
    virtual bool isCppEditor(Core::IEditor *editor) const;

    virtual void addExtraEditorSupport(AbstractEditorSupport *editorSupport);
    virtual void removeExtraEditorSupport(AbstractEditorSupport *editorSupport);
95 96 97 98

    virtual EditorDocumentHandle *editorDocument(const QString &filePath);
    virtual void registerEditorDocument(EditorDocumentHandle *editorDocument);
    virtual void unregisterEditorDocument(const QString &filePath);
99

100
    virtual QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
101

102 103
    virtual void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
                              const QString &replacement = QString());
104
    virtual void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
Roberto Raggi's avatar
Roberto Raggi committed
105

Christian Kamm's avatar
Christian Kamm committed
106
    virtual void findMacroUsages(const CPlusPlus::Macro &macro);
107
    virtual void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement);
Christian Kamm's avatar
Christian Kamm committed
108

109
    virtual void finishedRefreshingSourceFiles(const QSet<QString> &files);
110

111
    virtual void addModelManagerSupport(ModelManagerSupport *modelManagerSupport);
112
    virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const;
113
    virtual CppCompletionAssistProvider *completionAssistProvider(const QString &mimeType) const;
114 115
    virtual BaseEditorDocumentProcessor *editorDocumentProcessor(
                TextEditor::BaseTextDocument *baseTextDocument) const;
116

117 118
    virtual void setIndexingSupport(CppIndexingSupport *indexingSupport);
    virtual CppIndexingSupport *indexingSupport();
119

120 121 122 123 124 125
    QStringList projectFiles()
    {
        ensureUpdated();
        return m_projectFiles;
    }

126
    ProjectPart::HeaderPaths headerPaths()
127 128
    {
        ensureUpdated();
129
        return m_headerPaths;
130 131
    }

132
    // Use this *only* for auto tests
133
    void setHeaderPaths(const ProjectPart::HeaderPaths &headerPaths)
134
    {
135
        m_headerPaths = headerPaths;
136 137 138 139 140 141 142 143
    }

    QByteArray definedMacros()
    {
        ensureUpdated();
        return m_definedMacros;
    }

144 145
    void enableGarbageCollector(bool enable);

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

148 149
    static CppSourceProcessor *createSourceProcessor();

150
signals:
151
    void gcFinished(); // Needed for tests.
152

153
public slots:
154
    virtual void updateModifiedSourceFiles();
155
    virtual void GC();
156

157 158
private slots:
    // This should be executed in the GUI thread.
159
    void onAboutToLoadSession();
160 161
    void onAboutToUnloadSession();
    void onProjectAdded(ProjectExplorer::Project *project);
162
    void onAboutToRemoveProject(ProjectExplorer::Project *project);
163
    void onSourceFilesRefreshed() const;
164
    void onCoreAboutToClose();
165 166

private:
167
    void delayedGC();
168 169
    void recalculateFileToProjectParts();

170
    void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
171 172 173
    void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
    void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);

174
    QList<EditorDocumentHandle *> cppEditors() const;
175

176 177
    WorkingCopy buildWorkingCopyList();

178
    void ensureUpdated();
179
    QStringList internalProjectFiles() const;
180
    ProjectPart::HeaderPaths internalHeaderPaths() const;
181
    QByteArray internalDefinedMacros() const;
182

183
    void dumpModelManagerConfiguration(const QString &logFileId);
184

185
private:
186 187
    static QMutex m_instanceMutex;
    static CppModelManager *m_instance;
188

con's avatar
con committed
189
private:
190
    // Snapshot
191
    mutable QMutex m_snapshotMutex;
192
    CPlusPlus::Snapshot m_snapshot;
193

194
    // Project integration
195
    mutable QMutex m_projectMutex;
196 197
    QMap<ProjectExplorer::Project *, ProjectInfo> m_projectToProjectsInfo;
    QMap<QString, QList<CppTools::ProjectPart::Ptr> > m_fileToProjectParts;
198
    QMap<QString, CppTools::ProjectPart::Ptr> m_projectFileToProjectPart;
199
    // The members below are cached/(re)calculated from the projects and/or their project parts
200
    bool m_dirty;
con's avatar
con committed
201
    QStringList m_projectFiles;
202
    ProjectPart::HeaderPaths m_headerPaths;
203
    QByteArray m_definedMacros;
con's avatar
con committed
204

205
    // Editor integration
206 207
    mutable QMutex m_cppEditorsMutex;
    QMap<QString, EditorDocumentHandle *> m_cppEditors;
208
    QSet<AbstractEditorSupport *> m_extraEditorSupports;
209

210
    // Completion & highlighting
211
    QHash<QString, ModelManagerSupport *> m_idTocodeModelSupporter;
212
    QScopedPointer<ModelManagerSupport> m_modelManagerSupportFallback;
213 214

    // Indexing
215
    CppIndexingSupport *m_indexingSupporter;
216
    CppIndexingSupport *m_internalIndexingSupport;
217 218 219 220 221
    bool m_indexerEnabled;

    CppFindReferences *m_findReferences;

    bool m_enableGC;
222
    QTimer *m_delayedGcTimer;
con's avatar
con committed
223
};
224

con's avatar
con committed
225 226 227 228
} // namespace Internal
} // namespace CppTools

#endif // CPPMODELMANAGER_H