File indexing completed on 2024-06-16 04:23:14

0001 /*
0002     SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KDEVPLATFORM_ABSTRACTINCLUDENAVIGATIONCONTEXT_H
0008 #define KDEVPLATFORM_ABSTRACTINCLUDENAVIGATIONCONTEXT_H
0009 
0010 #include "abstractnavigationcontext.h"
0011 #include "../../util/includeitem.h"
0012 #include "../../duchain/parsingenvironment.h"
0013 #include <language/languageexport.h>
0014 
0015 namespace KDevelop {
0016 /**
0017  * Abstract navigation context for file includes.
0018  *
0019  * Example usage:
0020  * \code
0021  * namespace LANG {
0022  * class IncludeNavigationContext : public AbstractIncludeNavigationContext
0023  * {
0024  * public:
0025  *   IncludeNavigationContext(const IncludeItem& item, TopDuContextPointer topContext)
0026  *    : AbstractIncludeNavigationContext(item, topContext, KDevelop::LANGParsingEnvironment) {}
0027  * protected:
0028  *   virtual void getFileInfo(KDevelop::TopDUContext* duchain)
0029  *   {
0030  *   // write language dependent stuff via modifyHtml()
0031  *   }
0032  * };
0033  * }
0034  * \endcode
0035  */
0036 class KDEVPLATFORMLANGUAGE_EXPORT AbstractIncludeNavigationContext
0037     : public AbstractNavigationContext
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     AbstractIncludeNavigationContext(const IncludeItem& item, const TopDUContextPointer& topContext,
0043                                      const ParsingEnvironmentType& type);
0044     QString html(bool shorten) override;
0045     QString name() const override;
0046 
0047 protected:
0048     /// Overwrite this to add language dependent information for a given file.
0049     /// By default only "included by" and "includes"
0050     /// NOTE: You should always append a newline (<br />) if you write anything.
0051     virtual void getFileInfo(KDevelop::TopDUContext* duchain);
0052 
0053     ///Should return true if this declaration should be shown, and false if not
0054     ///The duchain is locked when this is called
0055     virtual bool filterDeclaration(Declaration* decl);
0056 
0057 private:
0058     /// Only environments with this type will be considered
0059     ParsingEnvironmentType m_type;
0060     using IdentifierPair = QPair<int, uint>;
0061     ///@param first must initially be true
0062     void addDeclarationsFromContext(KDevelop::DUContext* ctx, bool& first,
0063                                     QVector<IdentifierPair>& addedDeclarations,
0064                                     const QString& indent = {});
0065     IncludeItem m_item;
0066 };
0067 }
0068 
0069 #endif // KDEVPLATFORM_ABSTRACTINCLUDENAVIGATIONCONTEXT_H