~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/cppduchain/sourcemanipulation.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright 2009 Ramón Zarazúa <killerfox512+kde@gmail.com>
 
3
   
 
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.
 
7
 
 
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.
 
12
 
 
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.
 
17
*/
 
18
 
 
19
#ifndef CPP_SOURCEMANIPULATION_H
 
20
#define CPP_SOURCEMANIPULATION_H
 
21
 
 
22
#include <language/duchain/declaration.h>
 
23
#include <language/codegen/documentchangeset.h>
 
24
#include <language/codegen/coderepresentation.h>
 
25
#include "cppduchainexport.h"
 
26
 
 
27
namespace KDevelop {
 
28
 
 
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
 
32
{
 
33
public:
 
34
  SourceCodeInsertion(KDevelop::TopDUContext* topContext);
 
35
  virtual ~SourceCodeInsertion();
 
36
  
 
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);
 
47
 
 
48
  struct SignatureItem {
 
49
    AbstractType::Ptr type;
 
50
    QString name;
 
51
  };
 
52
 
 
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());
 
55
  
 
56
  ///Use the returned change-set to eventually let the user review the changes, and apply them.
 
57
  KDevelop::DocumentChangeSet& changes();
 
58
 
 
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;
 
62
  
 
63
  protected:
 
64
    enum InsertionKind {
 
65
      Variable,
 
66
      Function,
 
67
      Slot
 
68
    };
 
69
    
 
70
    struct InsertionPoint {
 
71
      int line;
 
72
      QString prefix;
 
73
    };
 
74
    
 
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);
 
78
    
 
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;
 
86
 
 
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;
 
90
    
 
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;
 
101
};
 
102
}
 
103
 
 
104
namespace Cpp {
 
105
 
 
106
class KDEVCPPDUCHAIN_EXPORT SourceCodeInsertion : public KDevelop::SourceCodeInsertion {
 
107
  public:
 
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);
 
113
};
 
114
 
 
115
}
 
116
 
 
117
 
 
118
#endif // CPP_SOURCEMANIPULATION_H
 
119
 
 
 
b'\\ No newline at end of file'