1 /*
2     SPDX-FileCopyrightText: 2001-2002 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
3     SPDX-FileCopyrightText: 2001-2002 Bernd Gehrmann <bernd@kdevelop.org>
4     SPDX-FileCopyrightText: 2001 Sandy Meier <smeier@kdevelop.org>
5     SPDX-FileCopyrightText: 2002 Daniel Engelschalt <daniel.engelschalt@gmx.net>
6     SPDX-FileCopyrightText: 2002 Simon Hausmann <hausmann@kde.org>
7     SPDX-FileCopyrightText: 2002-2003 Roberto Raggi <roberto@kdevelop.org>
8     SPDX-FileCopyrightText: 2003 Mario Scalas <mario.scalas@libero.it>
9     SPDX-FileCopyrightText: 2003 Harald Fernengel <harry@kdevelop.org>
10     SPDX-FileCopyrightText: 2003, 2006-2007 Hamish Rodda <rodda@kde.org>
11     SPDX-FileCopyrightText: 2004 Alexander Dymo <adymo@kdevelop.org>
12     SPDX-FileCopyrightText: 2006 Adam Treat <treat@kde.org>
13     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.org>
14 
15     SPDX-License-Identifier: LGPL-2.0-or-later
16 */
17 
18 #ifndef KDEVPLATFORM_CODECONTEXT_H
19 #define KDEVPLATFORM_CODECONTEXT_H
20 
21 #include <interfaces/context.h>
22 
23 #include <language/editor/documentrange.h>
24 #include <language/duchain/declaration.h>
25 #include <language/duchain/indexedducontext.h>
26 
27 namespace KTextEditor {
28 class View;
29 }
30 
31 namespace KDevelop {
32 class IndexedDeclaration;
33 class IndexedDUContext;
34 
35 /**
36  * A context that represents DUContexts. Before using this, first try casting to DeclarationContext, and use that if possible.
37  */
38 class KDEVPLATFORMLANGUAGE_EXPORT DUContextContext
39     : public Context
40 {
41 public:
42     explicit DUContextContext(const IndexedDUContext& context);
43     ~DUContextContext() override;
44 
45     ///Returns the represented DUContext
46     IndexedDUContext context() const;
47 
48     int type() const override;
49 
50     QList<QUrl> urls() const override;
51 
52 protected:
53     void setContext(IndexedDUContext context);
54 
55 private:
56     const QScopedPointer<class DUContextContextPrivate> d_ptr;
57     Q_DECLARE_PRIVATE(DUContextContext)
58 
59     Q_DISABLE_COPY(DUContextContext)
60 };
61 
62 /**
63    A context for definition-use chain objects.
64  */
65 class KDEVPLATFORMLANGUAGE_EXPORT DeclarationContext
66     : public DUContextContext
67 {
68 public:
69     /**Builds the context.
70      * @param declaration The represented declaration.
71      * @param use If this context represents the use of a declaration, this should contain the exact use range.
72      * @param context If this represents a use, then this should be the context
73      *              surrounding the use. Else it should be the context surrounding the declaration.
74      */
75     explicit DeclarationContext(const IndexedDeclaration& declaration,
76                                 const DocumentRange& use = DocumentRange::invalid(),
77                                 const IndexedDUContext& context = IndexedDUContext());
78     ///Computes the items under the cursor
79     DeclarationContext(KTextEditor::View* view, const KTextEditor::Cursor& position);
80 
81     /**Destructor.*/
82     ~DeclarationContext() override;
83 
84     /// Returns the type of this context.
85     int type() const override;
86 
87     ///The referenced declaration
88     IndexedDeclaration declaration() const;
89     ///If this code-context represents the use of a declaration, then this contains the exact position+range
90     ///of that use. declaration() returns the used declaration, and context() the context
91     ///that surrounds the use.
92     DocumentRange use() const;
93 
94 private:
95     // TODO: fix constructor and make const
96     QScopedPointer<class DeclarationContextPrivate> d_ptr;
97     Q_DECLARE_PRIVATE(DeclarationContext)
98 
99     Q_DISABLE_COPY(DeclarationContext)
100 };
101 }
102 
103 #endif
104