OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / cppeditor / cppquickfix.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef CPPQUICKFIX_H
35 #define CPPQUICKFIX_H
36
37 #include "cppeditor_global.h"
38 #include "cppsemanticinfo.h"
39
40 #include <ASTfwd.h>
41 #include <cplusplus/CppDocument.h>
42 #include <texteditor/quickfix.h>
43
44 namespace CppTools {
45     class CppModelManagerInterface;
46     class CppRefactoringFile;
47     class CppRefactoringChanges;
48 } // end of namespace CppTools
49
50 namespace ExtensionSystem {
51 class IPlugin;
52 }
53
54 namespace CppEditor {
55
56 namespace Internal {
57 class CppQuickFixCollector;
58 } // end of namespace Internal
59
60 class CPPEDITOR_EXPORT CppQuickFixState: public TextEditor::QuickFixState
61 {
62     friend class Internal::CppQuickFixCollector;
63
64 public:
65     CppQuickFixState(TextEditor::BaseTextEditor *editor);
66
67     const QList<CPlusPlus::AST *> &path() const;
68     CPlusPlus::Snapshot snapshot() const;
69     CPlusPlus::Document::Ptr document() const;
70     CppEditor::Internal::SemanticInfo semanticInfo() const;
71     const CPlusPlus::LookupContext &context() const;
72
73     const CppTools::CppRefactoringFile currentFile() const;
74
75     bool isCursorOn(unsigned tokenIndex) const;
76     bool isCursorOn(const CPlusPlus::AST *ast) const;
77
78 private:
79     QList<CPlusPlus::AST *> _path;
80     CPlusPlus::Snapshot _snapshot;
81     CppEditor::Internal::SemanticInfo _semanticInfo;
82     CPlusPlus::LookupContext _context;
83 };
84
85 class CPPEDITOR_EXPORT CppQuickFixOperation: public TextEditor::QuickFixOperation
86 {
87     Q_DISABLE_COPY(CppQuickFixOperation)
88
89 public:
90     explicit CppQuickFixOperation(const CppQuickFixState &state, int priority = -1);
91     virtual ~CppQuickFixOperation();
92
93     virtual void perform();
94
95 protected:
96     virtual void performChanges(CppTools::CppRefactoringFile *currentFile,
97                                 CppTools::CppRefactoringChanges *refactoring) = 0;
98
99     QString fileName() const;
100
101     const CppQuickFixState &state() const;
102
103 private:
104     CppQuickFixState _state;
105 };
106
107 class CPPEDITOR_EXPORT CppQuickFixFactory: public TextEditor::QuickFixFactory
108 {
109     Q_OBJECT
110
111 public:
112     CppQuickFixFactory();
113     virtual ~CppQuickFixFactory();
114
115     virtual QList<TextEditor::QuickFixOperation::Ptr> matchingOperations(TextEditor::QuickFixState *state);
116     /*!
117         Implement this method to match and create the appropriate
118         CppQuickFixOperation objects.
119      */
120     virtual QList<CppQuickFixOperation::Ptr> match(const CppQuickFixState &state) = 0;
121
122 protected:
123     /*!
124         Creates a list of 1 single element: the shared-pointer to the given
125         operation. This shared-pointer takes over the ownership (meaning the
126         responsibility to delete the operation).
127      */
128     static QList<CppQuickFixOperation::Ptr> singleResult(CppQuickFixOperation *operation);
129
130     /// Utility method which creates an empty list.
131     static QList<CppQuickFixOperation::Ptr> noResult();
132 };
133
134 } // namespace CppEditor
135
136 #endif // CPPQUICKFIX_H