1 /*
2     SPDX-FileCopyrightText: 2008 David Nolden <david.nolden.kdevelop@art-master.de>
3 
4     SPDX-License-Identifier: LGPL-2.0-only
5 */
6 
7 #ifndef COMPLETIONCODEMODEL_H
8 #define COMPLETIONCODEMODEL_H
9 
10 #include "phpduchainexport.h"
11 #include <language/duchain/identifier.h>
12 #include <serialization/indexedstring.h>
13 
14 namespace KDevelop {
15 
16   class Declaration;
17   class IndexedDeclaration;
18   class DeclarationId;
19   class TopDUContext;
20   class QualifiedIdentifier;
21   class IndexedString;
22   class IndexedQualifiedIdentifier;
23 }
24 
25 namespace Php {
26   struct CompletionCodeModelItem {
CompletionCodeModelItemCompletionCodeModelItem27     CompletionCodeModelItem() : referenceCount(0), kind(Unknown) {
28     }
29     enum Kind {
30       Unknown = 0,
31       Exception = 1
32     };
33     KDevelop::IndexedQualifiedIdentifier id;
34     KDevelop::IndexedString prettyName;
35     uint referenceCount;
36     union {
37       Kind kind;
38       uint uKind;
39     };
40     bool operator<(const CompletionCodeModelItem& rhs) const {
41       return id < rhs.id;
42     }
43   };
44 
45 /**
46  * Persistent store that efficiently holds a list of identifiers and their kind for each declaration-string.
47  * */
48   class KDEVPHPDUCHAIN_EXPORT CompletionCodeModel {
49     public:
50     /// Constructor.
51     CompletionCodeModel();
52     /// Destructor.
53     ~CompletionCodeModel();
54 
55     ///There can only be one item for each identifier. If an item with this identifier already exists,
56     ///the kind is updated.
57     void addItem(const KDevelop::IndexedString& file, const KDevelop::IndexedQualifiedIdentifier& id, const KDevelop::IndexedString & prettyName, CompletionCodeModelItem::Kind kind);
58 
59     void removeItem(const KDevelop::IndexedString& file, const KDevelop::IndexedQualifiedIdentifier& id);
60 
61     ///Updates the kind for the given item. The item must already be in the symbol table.
62     void updateItem(const KDevelop::IndexedString& file, const KDevelop::IndexedQualifiedIdentifier& id, const KDevelop::IndexedString & prettyName, CompletionCodeModelItem::Kind kind);
63 
64     ///Retrieves all the global identifiers for a file-name in an efficient way.
65     ///@param count A reference that will be filled with the count of retrieved items
66     ///@param items A reference to a pointer, that will represent the array of items.
67     ///             The array may contain items with an invalid identifier, those should be ignored.
68     ///             The list is sorted by identifier-index(except for the invalid identifiers in between).
69     void items(const KDevelop::IndexedString& file, uint& count, const CompletionCodeModelItem*& items) const;
70 
71     static CompletionCodeModel& self();
72 
73     private:
74       class CompletionCodeModelPrivate* d;
75   };
76 }
77 
78 #endif
79