1 /*
2     SPDX-FileCopyrightText: 2009 David Nolden <david.nolden.kdevelop@art-master.de>
3     SPDX-FileCopyrightText: 2014 Kevin Funk <kfunk@kde.org>
4 
5     SPDX-License-Identifier: LGPL-2.0-only
6 */
7 
8 #ifndef SIGNATUREASSISTANT_H
9 #define SIGNATUREASSISTANT_H
10 
11 #include "adaptsignatureaction.h"
12 #include "clangprivateexport.h"
13 
14 #include <language/assistant/staticassistant.h>
15 #include <language/duchain/identifier.h>
16 #include <language/duchain/topducontext.h>
17 
18 #include <QPointer>
19 
20 namespace KTextEditor {
21 class View;
22 }
23 
24 class KDEVCLANGPRIVATE_EXPORT AdaptSignatureAssistant : public KDevelop::StaticAssistant
25 {
26     Q_OBJECT
27 
28 public:
29     explicit AdaptSignatureAssistant(KDevelop::ILanguageSupport* supportedLanguage);
30 
31     QString title() const override;
32     void textChanged(KTextEditor::Document* doc, const KTextEditor::Range& invocationRange, const QString& removedText = QString()) override;
33     bool isUseful() const override;
34     KTextEditor::Range displayRange() const override;
35 
36 private:
37     ///Compare @a newSignature to m_oldSignature and put differences in @a oldPositions
38     ///@returns whether or not there are any differences
39     bool getSignatureChanges(const Signature &newSignature, QList<int> &oldPositions) const;
40     ///Set default params in @a newSignature based on m_oldSignature's defaults and @a oldPositions
41     void setDefaultParams(Signature &newSignature, const QList<int> &oldPositions) const;
42     ///@returns RenameActions for each parameter in newSignature that has been renamed
43     QList<KDevelop::RenameAction*> getRenameActions(const Signature &newSignature, const QList<int> &oldPositions) const;
44 
45     // If this is true, the user is editing on the definition side,
46     // and the declaration should be updated
47     bool m_editingDefinition = false;
48     KDevelop::Identifier m_declarationName;
49     KDevelop::DeclarationId m_otherSideId;
50     KDevelop::ReferencedTopDUContext m_otherSideTopContext;
51     KDevelop::DUContextPointer m_otherSideContext;
52     KTextEditor::Cursor m_lastEditPosition;
53     //old signature of the _other_side
54     Signature m_oldSignature;
55     QPointer<KTextEditor::Document> m_document;
56     QPointer<KTextEditor::View> m_view;
57 
58 private Q_SLOTS:
59     void updateReady(const KDevelop::IndexedString& document, const KDevelop::ReferencedTopDUContext& context) override;
60     void reset();
61 };
62 
63 #endif // SIGNATUREASSISTANT_H
64