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

0001 /*
0002     SPDX-FileCopyrightText: 2001-2002 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
0003     SPDX-FileCopyrightText: 2001-2002 Bernd Gehrmann <bernd@kdevelop.org>
0004     SPDX-FileCopyrightText: 2001 Sandy Meier <smeier@kdevelop.org>
0005     SPDX-FileCopyrightText: 2002 Daniel Engelschalt <daniel.engelschalt@gmx.net>
0006     SPDX-FileCopyrightText: 2002 Simon Hausmann <hausmann@kde.org>
0007     SPDX-FileCopyrightText: 2002-2003 Roberto Raggi <roberto@kdevelop.org>
0008     SPDX-FileCopyrightText: 2003 Mario Scalas <mario.scalas@libero.it>
0009     SPDX-FileCopyrightText: 2003 Harald Fernengel <harry@kdevelop.org>
0010     SPDX-FileCopyrightText: 2003, 2006-2007 Hamish Rodda <rodda@kde.org>
0011     SPDX-FileCopyrightText: 2004 Alexander Dymo <adymo@kdevelop.org>
0012     SPDX-FileCopyrightText: 2006 Adam Treat <treat@kde.org>
0013     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.org>
0014 
0015     SPDX-License-Identifier: LGPL-2.0-or-later
0016 */
0017 
0018 #ifndef KDEVPLATFORM_CODECONTEXT_H
0019 #define KDEVPLATFORM_CODECONTEXT_H
0020 
0021 #include <interfaces/context.h>
0022 
0023 #include <language/editor/documentrange.h>
0024 #include <language/duchain/declaration.h>
0025 #include <language/duchain/indexedducontext.h>
0026 
0027 namespace KTextEditor {
0028 class View;
0029 }
0030 
0031 namespace KDevelop {
0032 class IndexedDeclaration;
0033 class IndexedDUContext;
0034 
0035 /**
0036  * A context that represents DUContexts. Before using this, first try casting to DeclarationContext, and use that if possible.
0037  */
0038 class KDEVPLATFORMLANGUAGE_EXPORT DUContextContext
0039     : public Context
0040 {
0041 public:
0042     explicit DUContextContext(const IndexedDUContext& context);
0043     ~DUContextContext() override;
0044 
0045     ///Returns the represented DUContext
0046     IndexedDUContext context() const;
0047 
0048     int type() const override;
0049 
0050     QList<QUrl> urls() const override;
0051 
0052 protected:
0053     void setContext(IndexedDUContext context);
0054 
0055 private:
0056     const QScopedPointer<class DUContextContextPrivate> d_ptr;
0057     Q_DECLARE_PRIVATE(DUContextContext)
0058 
0059     Q_DISABLE_COPY(DUContextContext)
0060 };
0061 
0062 /**
0063    A context for definition-use chain objects.
0064  */
0065 class KDEVPLATFORMLANGUAGE_EXPORT DeclarationContext
0066     : public DUContextContext
0067 {
0068 public:
0069     /**Builds the context.
0070      * @param declaration The represented declaration.
0071      * @param use If this context represents the use of a declaration, this should contain the exact use range.
0072      * @param context If this represents a use, then this should be the context
0073      *              surrounding the use. Else it should be the context surrounding the declaration.
0074      */
0075     explicit DeclarationContext(const IndexedDeclaration& declaration,
0076                                 const DocumentRange& use = DocumentRange::invalid(),
0077                                 const IndexedDUContext& context = IndexedDUContext());
0078     ///Computes the items under the cursor
0079     DeclarationContext(KTextEditor::View* view, const KTextEditor::Cursor& position);
0080 
0081     /**Destructor.*/
0082     ~DeclarationContext() override;
0083 
0084     /// Returns the type of this context.
0085     int type() const override;
0086 
0087     ///The referenced declaration
0088     IndexedDeclaration declaration() const;
0089     ///If this code-context represents the use of a declaration, then this contains the exact position+range
0090     ///of that use. declaration() returns the used declaration, and context() the context
0091     ///that surrounds the use.
0092     DocumentRange use() const;
0093 
0094 private:
0095     // TODO: fix constructor and make const
0096     QScopedPointer<class DeclarationContextPrivate> d_ptr;
0097     Q_DECLARE_PRIVATE(DeclarationContext)
0098 
0099     Q_DISABLE_COPY(DeclarationContext)
0100 };
0101 }
0102 
0103 #endif