File indexing completed on 2024-05-12 04:38:02

0001 /*
0002     SPDX-FileCopyrightText: 2008 David Nolden <david.nolden.kdevelop@art-master.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KDEVPLATFORM_IMPORTERS_H
0008 #define KDEVPLATFORM_IMPORTERS_H
0009 
0010 #include <language/languageexport.h>
0011 #include "declarationid.h"
0012 
0013 namespace KDevelop {
0014 class DeclarationId;
0015 class IndexedDUContext;
0016 
0017 /**
0018  * Global mapping of Declaration-Ids to contexts that import the associated context, protected through DUChainLock.
0019  * This is used as an alternative to the local importers list within DUContext, only for indirect imports(Across different files, or with templates).
0020  *
0021  * This has the advantage that imports stay valid even if the imported context is deleted temporarily, and stored top-contexts don't need to be
0022  * changed just because imports were added.
0023  *
0024  * To retrieve the actual uses, query the duchain for the files.
0025  * */
0026 class KDEVPLATFORMLANGUAGE_EXPORT Importers
0027 {
0028     Q_DISABLE_COPY_MOVE(Importers)
0029     Importers();
0030 public:
0031     /**
0032      * Adds a top-context to the users-list of the given id
0033      * */
0034     void addImporter(const DeclarationId& id, const IndexedDUContext& use);
0035     /**
0036      * Removes the given top-context from the list of uses
0037      * */
0038     void removeImporter(const DeclarationId& id, const IndexedDUContext& use);
0039 
0040     ///Gets the top-contexts of all users assigned to the declaration-id
0041     KDevVarLengthArray<IndexedDUContext> importers(const DeclarationId& id) const;
0042 
0043     static Importers& self();
0044 };
0045 }
0046 
0047 #endif