summaryrefslogtreecommitdiff
path: root/src/plugins/classview/classviewparser.h
blob: fb0eb651eb359725fff2600d132d5b642372bed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Denis Mingulov.
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#ifndef CLASSVIEWPARSER_H
#define CLASSVIEWPARSER_H

#include <QtCore/QObject>

#include "classviewparsertreeitem.h"

#include <QtCore/QList>
#include <QtGui/QStandardItem>
#include <QtCore/QScopedPointer>
#include <QtCore/QSharedPointer>

#include <CPlusPlusForwardDeclarations.h>
#include <cplusplus/CppDocument.h>
#include <cpptools/cppmodelmanagerinterface.h>

// might be changed to forward declaration - is not done to be less dependent
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/project.h>

namespace ClassView {
namespace Internal {

/*!
   \class Parser
   \brief Parse cpp information. Multithreading is supported.
 */

class Parser : public QObject
{
    Q_OBJECT

public:
    /*!
       \brief Constructor
     */
    explicit Parser(QObject *parent = 0);
    ~Parser();

    /*!
       \brief Lazy data population for a \a QStandardItemModel
       \param item Item which has to be checked
     */
    bool canFetchMore(QStandardItem *item) const;

    /*!
       \brief Lazy data population for a \a QStandardItemModel
       \param item Item which will be populated (if needed)
       \param skipRoot Skip root item
     */
    void fetchMore(QStandardItem *item, bool skipRoot = false) const;

signals:
    //! File list is changed
    void filesAreRemoved();

    /*!
       \brief Signal about a tree data update
     */
    void treeDataUpdate(QSharedPointer<QStandardItem> result);

    /*!
       \brief Signal that internal data
       \sa resetData, resetDataToCurrentState
     */
    void resetDataDone();

public slots:
    /*!
       \brief Request to clear full internal stored data.
     */
    void clearCacheAll();

    /*!
       \brief Request to clear internal stored data, it has to be regenerated on the next request.
     */
    void clearCache();

    /*!
       \brief Request to emit a signal with the current tree state
     */
    void requestCurrentState();

    /*!
       \brief Set file list for the parsing, files outside of this list will not be in any tree.
       \param fileList Files which must be allowed for the parsing
     */
    void setFileList(const QStringList &fileList);

    /*!
       \brief Remove some files from the file list for the parsing.
       \param fileList Files which must be removed from the parsing
     */
    void removeFiles(const QStringList &fileList);

    /*!
       \brief Fully reset internal state
       \param snapshot Code parser snapshot
     */
    void resetData(const CPlusPlus::Snapshot &snapshot);

    /*!
       \brief Fully reset internal state - to the current state
       \sa resetData
     */
    void resetDataToCurrentState();

    /*!
       \brief Parse document if it is in the project files and add a tree to the internal storage
       \param doc Document which has to be parsed
     */
    void parseDocument(const CPlusPlus::Document::Ptr &doc);

    /*!
       \brief Switch to flat mode (without subprojects)
       \param flat True to enable flat mode, false to disable
     */
    void setFlatMode(bool flat);

protected slots:
    /*!
       \brief Internal data is changed, regenerate the tree
       \sa resetDataDone
     */
    void onResetDataDone();

protected:
    /*!
       \brief Parse one particular project and add result to the tree item
       \param item Item where parsed project has to be stored
       \param fileList Files
       \param projectId Project id, is needed for prj cache
     */
    void addProject(const ParserTreeItem::Ptr &item, const QStringList &fileList,
                    const QString &projectId = QString());

    /*!
       \brief Parse one particular symbol and add result to the tree item (as a parent)
       \param item Item where parsed symbol has to be stored
       \param symbol Symbol which has to be used as a source
     */
    void addSymbol(const ParserTreeItem::Ptr &item, const CPlusPlus::Symbol *symbol);

    /*!
       \brief Parse document if it is in the project files and add a tree to the internal storage.
              Update internal cached tree for this document.
       \param doc Document which has to be parsed
       \return A tree
       \sa parseDocument
     */
    ParserTreeItem::ConstPtr getParseDocumentTree(const CPlusPlus::Document::Ptr &doc);

    /*!
       \brief Get from the cache or parse document if it is in the project files
              and add a tree to the internal storage
       \param doc Document which has to be parsed
       \return A tree
       \sa parseDocument
     */
    ParserTreeItem::ConstPtr getCachedOrParseDocumentTree(const CPlusPlus::Document::Ptr &doc);

    /*!
       \brief Parse project and add a tree to the internal storage.
              Update internal cached tree for this project.
       \param fileList Documents which has to be added to the project
       \param projectId Project id
       \return A tree
     */
    ParserTreeItem::Ptr getParseProjectTree(const QStringList &fileList, const QString &projectId);

    /*!
       \brief Get from the cache (if valid) or parse project and add a tree to the internal storage.
              Update internal cached tree for this project.
       \param fileList Documents which has to be added to the project
       \param projectId Project id
       \return A tree
     */
    ParserTreeItem::Ptr getCachedOrParseProjectTree(const QStringList &fileList,
                                                    const QString &projectId);

    /*!
       \brief Send a current tree to listeners
     */
    void emitCurrentTree();

    /*!
       \brief Parse the class and produce a new tree
       \sa addProject
     */
    ParserTreeItem::ConstPtr parse();

    /*!
       \brief Find internal node for the specified UI item
       \param item Item which has to be found
       \param skipRoot Skip root item
       \return Found internal node
     */
    ParserTreeItem::ConstPtr findItemByRoot(const QStandardItem *item, bool skipRoot = false) const;

    /*!
       \brief Generate projects like Project Explorer
       \param item Item
       \param node Root node
       \return List of projects which were added to the item
     */
    QStringList addProjectNode(const ParserTreeItem::Ptr &item,
                               const ProjectExplorer::ProjectNode *node);

    /*!
       \brief Generate project node file list
       \param node Root node
     */
    QStringList projectNodeFileList(const ProjectExplorer::FolderNode *node) const;

    /*!
       \brief Get the current project list
       \return Project list
     */
    QList<ProjectExplorer::Project *> getProjectList() const;

    /*!
       \brief Create flat tree from different projects
       \param projectList List of projects
       \return Flat tree
     */
    ParserTreeItem::Ptr createFlatTree(const QStringList &projectList);

private:
    //! Private class data pointer
    QScopedPointer<struct ParserPrivate> d_ptr;
};

} // namespace Internal
} // namespace ClassView

#endif // CLASSVIEWPARSER_H