2
Copyright 2009 Ramón Zarazúa <killerfox512+kde@gmail.com>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
19
#ifndef CPP_SOURCEMANIPULATION_H
20
#define CPP_SOURCEMANIPULATION_H
22
#include <language/duchain/declaration.h>
23
#include <language/codegen/documentchangeset.h>
24
#include <language/codegen/coderepresentation.h>
25
#include "cppduchainexport.h"
29
//Through the whole lifetime of this object, the duchain must be locked
30
//Note: _nothing_ will happen until you apply the resulting changes, that can be retrieved through changes()
31
class KDEVCPPDUCHAIN_EXPORT SourceCodeInsertion : public KShared
34
SourceCodeInsertion(KDevelop::TopDUContext* topContext);
35
virtual ~SourceCodeInsertion();
37
///Set a position before which any code must be inserted
38
virtual void setInsertBefore(KDevelop::SimpleCursor position);
39
///Set context into which code must be inserted. This must be called before calling modifier functions.
40
virtual void setContext(KDevelop::DUContext* context);
41
///Set optional sub-scope into which the code should be inserted, under 'context'
42
virtual void setSubScope(KDevelop::QualifiedIdentifier scope);
43
///Set optional access-policy for the inserted items
44
virtual void setAccess(KDevelop::Declaration::AccessPolicy access);
45
///Adds a variable declaration using the parameters given before
46
virtual bool insertVariableDeclaration(KDevelop::Identifier name, KDevelop::AbstractType::Ptr type);
48
struct SignatureItem {
49
AbstractType::Ptr type;
53
///@param body Optional function-body, including parens
54
virtual bool insertFunctionDeclaration(KDevelop::Identifier name, KDevelop::AbstractType::Ptr returnType, QList< KDevelop::SourceCodeInsertion::SignatureItem > signature, bool isConstant = false, QString body = QString());
56
///Use the returned change-set to eventually let the user review the changes, and apply them.
57
KDevelop::DocumentChangeSet& changes();
59
///Moves the given line-number to a position that is not part of a comment, is behind the preprocessor/#ifdef code at top of a file,
60
///and is before or equal @param line
61
virtual int firstValidCodeLineBefore(int line) const;
70
struct InsertionPoint {
75
///Returns the exact position where the item should be inserted so it is in the given line.
76
///The inserted item has to start with a newline, and does not need to end with a newline.
77
SimpleRange insertionRange(int line);
79
///Returns a pair: (line, prefix) for inserting the given kind of declaration with the given access policy
80
InsertionPoint findInsertionPoint(KDevelop::Declaration::AccessPolicy policy, InsertionKind kind) const;
81
//Should apply m_scope to the given declaration string
82
virtual QString applySubScope(QString decl) const;
83
virtual QString accessString() const;
84
virtual QString indentation() const;
85
virtual QString applyIndentation(QString decl) const;
87
///Returns an end-cursor that is guaranteed to fit into the current document. The top-context may have an invalid end-cursor if
88
///the document is not open.
89
SimpleCursor end() const;
91
KDevelop::DocumentChangeSet m_changeSet;
92
KDevelop::SimpleCursor m_insertBefore;
93
KDevelop::DUContext* m_context;
94
KDevelop::QualifiedIdentifier m_scope;
95
KDevelop::Declaration::AccessPolicy m_access;
96
KDevelop::TopDUContext* m_topContext;
97
//Represents the whole code of the manipulated top-context for reading.
98
//Changes should be done as transactions to m_changeSet.
99
///@warning This must be checked for zero before using. It is zero if the file could not be read.
100
const KDevelop::CodeRepresentation::Ptr m_codeRepresentation;
106
class KDEVCPPDUCHAIN_EXPORT SourceCodeInsertion : public KDevelop::SourceCodeInsertion {
108
SourceCodeInsertion(KDevelop::TopDUContext* topContext);
109
///setContext(..) must have been called before with the class-context
110
virtual bool insertSlot(QString name, QString normalizedSignature);
111
///If this is used, only setInsertBefore(..) needs to be called before.
112
virtual bool insertForwardDeclaration(KDevelop::Declaration* decl);
118
#endif // CPP_SOURCEMANIPULATION_H
b'\\ No newline at end of file'