OSDN Git Service

ea0f596a1244ad8a6bca041b97eecc7ac5887f1e
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmljseditor / qmljsquickfix.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 QMLJSQUICKFIX_H
35 #define QMLJSQUICKFIX_H
36
37 #include "qmljseditor.h"
38
39 #include <texteditor/quickfix.h>
40 #include <qmljs/parser/qmljsastfwd_p.h>
41 #include <qmljs/qmljsdocument.h>
42 #include <qmljstools/qmljsrefactoringchanges.h>
43
44 namespace ExtensionSystem {
45 class IPlugin;
46 }
47
48 namespace QmlJS {
49     class ModelManagerInterface;
50 }
51
52 namespace QmlJSEditor {
53
54 namespace Internal {
55 class QmlJSQuickFixCollector;
56 } // namespace Internal
57
58 /*!
59     Specialized QuickFixState for QML/JavaScript quick-fixes.
60
61     This specialized state for QML/JavaScript quick-fixes also holds the
62     QmlJSEditor::Internal::SemanticInfo for the document in the editor.
63  */
64 class QmlJSQuickFixState: public TextEditor::QuickFixState
65 {
66     friend class Internal::QmlJSQuickFixCollector;
67
68 public:
69     /// Creates a new state for the given editor.
70     QmlJSQuickFixState(TextEditor::BaseTextEditorWidget *editor);
71
72     SemanticInfo semanticInfo() const;
73
74     /// \returns the snapshot holding the document of the editor.
75     QmlJS::Snapshot snapshot() const;
76
77     /// \returns the document of the editor
78     QmlJS::Document::Ptr document() const;
79
80     const QmlJSTools::QmlJSRefactoringFile currentFile() const;
81
82 private:
83     SemanticInfo _semanticInfo;
84 };
85
86 /*!
87     A quick-fix operation for the QML/JavaScript editor, which works on a
88     QmlJSQuickFixState .
89  */
90 class QmlJSQuickFixOperation: public TextEditor::QuickFixOperation
91 {
92     Q_DISABLE_COPY(QmlJSQuickFixOperation)
93
94 public:
95     /*!
96         Creates a new QmlJSQuickFixOperation.
97
98         This operation will copy the complete state, in order to be able to perform
99         its changes later on.
100
101         \param state The state for which this operation was created.
102         \param priority The priority for this operation.
103      */
104     explicit QmlJSQuickFixOperation(const QmlJSQuickFixState &state, int priority = -1);
105     virtual ~QmlJSQuickFixOperation();
106
107     virtual void perform();
108
109 protected:
110     typedef Utils::ChangeSet::Range Range;
111
112     virtual void performChanges(QmlJSTools::QmlJSRefactoringFile *currentFile,
113                                 QmlJSTools::QmlJSRefactoringChanges *refactoring) = 0;
114
115     /// \returns A const-reference to the state of the operation.
116     const QmlJSQuickFixState &state() const;
117
118     /// \returns The name of the file for for which this operation is invoked.
119     QString fileName() const;
120
121 private:
122     QmlJSQuickFixState _state;
123 };
124
125 class QmlJSQuickFixFactory: public TextEditor::QuickFixFactory
126 {
127     Q_OBJECT
128
129 public:
130     QmlJSQuickFixFactory();
131     virtual ~QmlJSQuickFixFactory();
132
133     virtual QList<TextEditor::QuickFixOperation::Ptr> matchingOperations(TextEditor::QuickFixState *state);
134
135     /*!
136         Implement this method to match and create the appropriate
137         QmlJSQuickFixOperation objects.
138      */
139     virtual QList<QmlJSQuickFixOperation::Ptr> match(const QmlJSQuickFixState &state) = 0;
140
141     static QList<QmlJSQuickFixOperation::Ptr> noResult();
142     static QList<QmlJSQuickFixOperation::Ptr> singleResult(QmlJSQuickFixOperation *operation);
143 };
144
145 namespace Internal {
146
147 class QmlJSQuickFixCollector: public TextEditor::QuickFixCollector
148 {
149     Q_OBJECT
150
151 public:
152     QmlJSQuickFixCollector();
153     virtual ~QmlJSQuickFixCollector();
154
155     virtual bool supportsEditor(TextEditor::ITextEditor *editor) const;
156     virtual bool supportsPolicy(TextEditor::CompletionPolicy policy) const;
157     virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::BaseTextEditorWidget *editor);
158
159     virtual QList<TextEditor::QuickFixFactory *> quickFixFactories() const;
160
161     /// Registers all quick-fixes in this plug-in as auto-released objects.
162     static void registerQuickFixes(ExtensionSystem::IPlugin *plugIn);
163 };
164
165 } // namespace Internal
166 } // namespace QmlJSEditor
167
168 #endif // QMLJSQUICKFIX_H