cppmodelmanager.h 7.27 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 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 "cpptools_global.h"
34

35
#include "cppmodelmanagerinterface.h"
36

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

40 41
#include <QHash>
#include <QMutex>
42
#include <QTimer>
con's avatar
con committed
43

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

namespace CppTools {
48

49
class CppEditorSupport;
50 51
class CppHighlightingSupportFactory;

con's avatar
con committed
52 53
namespace Internal {

Roberto Raggi's avatar
Roberto Raggi committed
54
class CppFindReferences;
con's avatar
con committed
55

56
class CPPTOOLS_EXPORT CppModelManager : public CppTools::CppModelManagerInterface
con's avatar
con committed
57 58 59
{
    Q_OBJECT

60 61 62
public:
    typedef CPlusPlus::Document Document;

con's avatar
con committed
63
public:
64
    CppModelManager(QObject *parent = 0);
con's avatar
con committed
65 66
    virtual ~CppModelManager();

67 68
    static CppModelManager *instance();

69 70
    virtual QFuture<void> updateSourceFiles(const QStringList &sourceFiles,
        ProgressNotificationMode mode = ReservedProgressNotification);
71
    virtual WorkingCopy workingCopy() const;
72 73 74

    virtual QList<ProjectInfo> projectInfos() const;
    virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
75
    virtual QFuture<void> updateProjectInfo(const ProjectInfo &pinfo);
76
    virtual QList<CppTools::ProjectPart::Ptr> projectPart(const QString &fileName) const;
77

78
    virtual CPlusPlus::Snapshot snapshot() const;
79 80
    virtual Document::Ptr document(const QString &fileName) const;
    bool replaceDocument(Document::Ptr newDoc);
con's avatar
con committed
81 82 83

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

84 85 86 87 88 89
    virtual bool isCppEditor(Core::IEditor *editor) const;

    virtual void addExtraEditorSupport(AbstractEditorSupport *editorSupport);
    virtual void removeExtraEditorSupport(AbstractEditorSupport *editorSupport);
    virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *textEditor);
    virtual void deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor);
90

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

93 94
    virtual void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
                              const QString &replacement = QString());
95
    virtual void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
Roberto Raggi's avatar
Roberto Raggi committed
96

Christian Kamm's avatar
Christian Kamm committed
97
    virtual void findMacroUsages(const CPlusPlus::Macro &macro);
98
    virtual void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement);
Christian Kamm's avatar
Christian Kamm committed
99

100
    virtual void setExtraDiagnostics(const QString &fileName, const QString &key,
101
                                     const QList<Document::DiagnosticMessage> &diagnostics);
102

103 104
    void finishedRefreshingSourceFiles(const QStringList &files);

105
    virtual CppCompletionSupport *completionSupport(Core::IEditor *editor) const;
106
    virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider);
107

108
    virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const;
109
    virtual void setHighlightingSupportFactory(CppHighlightingSupportFactory *highlightingFactory);
110

111 112
    virtual void setIndexingSupport(CppIndexingSupport *indexingSupport);
    virtual CppIndexingSupport *indexingSupport();
113

114 115 116 117 118 119 120 121 122 123 124 125
    QStringList projectFiles()
    {
        ensureUpdated();
        return m_projectFiles;
    }

    QStringList includePaths()
    {
        ensureUpdated();
        return m_includePaths;
    }

126 127 128 129 130 131
    // Use this *only* for auto tests
    void setIncludePaths(const QStringList &includePaths)
    {
        m_includePaths = includePaths;
    }

132 133 134 135 136 137 138 139 140 141 142 143
    QStringList frameworkPaths()
    {
        ensureUpdated();
        return m_frameworkPaths;
    }

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

144
signals:
145
    void aboutToRemoveFiles(const QStringList &files);
146
    void gcFinished(); // Needed for tests.
147

148
public slots:
149
    virtual void updateModifiedSourceFiles();
150
    virtual void GC();
151

152 153
private slots:
    // This should be executed in the GUI thread.
154
    void onAboutToRemoveProject(ProjectExplorer::Project *project);
155
    void onAboutToLoadSession();
156
    void onAboutToUnloadSession();
157
    void onCoreAboutToClose();
158 159 160
    void onProjectAdded(ProjectExplorer::Project *project);

private:
161
    void delayedGC();
162
    void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
163 164
    WorkingCopy buildWorkingCopyList();

165
    void ensureUpdated();
166 167 168 169
    QStringList internalProjectFiles() const;
    QStringList internalIncludePaths() const;
    QStringList internalFrameworkPaths() const;
    QByteArray internalDefinedMacros() const;
170

171 172
    void dumpModelManagerConfiguration();

173
private:
174 175
    static QMutex m_instanceMutex;
    static CppModelManager *m_instance;
176

con's avatar
con committed
177
private:
178
    // Snapshot
179
    mutable QMutex m_snapshotMutex;
180
    CPlusPlus::Snapshot m_snapshot;
181

182
    // Project integration
183
    mutable QMutex m_projectMutex;
184 185 186
    QMap<ProjectExplorer::Project *, ProjectInfo> m_projectToProjectsInfo;
    QMap<QString, QList<CppTools::ProjectPart::Ptr> > m_fileToProjectParts;
    // The members below are cached/(re)calculated from the projects and/or their project parts
187
    bool m_dirty;
con's avatar
con committed
188
    QStringList m_projectFiles;
189 190 191
    QStringList m_includePaths;
    QStringList m_frameworkPaths;
    QByteArray m_definedMacros;
con's avatar
con committed
192

193 194 195 196
    // Editor integration
    mutable QMutex m_cppEditorSupportsMutex;
    QMap<TextEditor::BaseTextEditor *, CppEditorSupport *> m_cppEditorSupports;
    QSet<AbstractEditorSupport *> m_extraEditorSupports;
197

198
    // Completion
199 200
    CppCompletionAssistProvider *m_completionAssistProvider;
    CppCompletionAssistProvider *m_completionFallback;
201 202

    // Highlighting
203 204
    CppHighlightingSupportFactory *m_highlightingFactory;
    CppHighlightingSupportFactory *m_highlightingFallback;
205 206

    // Indexing
207
    CppIndexingSupport *m_indexingSupporter;
208
    CppIndexingSupport *m_internalIndexingSupport;
209 210 211 212 213
    bool m_indexerEnabled;

    CppFindReferences *m_findReferences;

    bool m_enableGC;
214
    QTimer *m_delayedGcTimer;
con's avatar
con committed
215
};
216

con's avatar
con committed
217 218 219 220
} // namespace Internal
} // namespace CppTools

#endif // CPPMODELMANAGER_H