1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef QMLJSQUICKFIX_H
35 #define QMLJSQUICKFIX_H
37 #include "qmljseditor.h"
39 #include <texteditor/quickfix.h>
40 #include <qmljs/parser/qmljsastfwd_p.h>
41 #include <qmljs/qmljsdocument.h>
42 #include <qmljstools/qmljsrefactoringchanges.h>
44 namespace ExtensionSystem {
49 class ModelManagerInterface;
52 namespace QmlJSEditor {
55 class QmlJSQuickFixCollector;
56 } // namespace Internal
59 Specialized QuickFixState for QML/JavaScript quick-fixes.
61 This specialized state for QML/JavaScript quick-fixes also holds the
62 QmlJSEditor::Internal::SemanticInfo for the document in the editor.
64 class QmlJSQuickFixState: public TextEditor::QuickFixState
66 friend class Internal::QmlJSQuickFixCollector;
69 /// Creates a new state for the given editor.
70 QmlJSQuickFixState(TextEditor::BaseTextEditorWidget *editor);
72 SemanticInfo semanticInfo() const;
74 /// \returns the snapshot holding the document of the editor.
75 QmlJS::Snapshot snapshot() const;
77 /// \returns the document of the editor
78 QmlJS::Document::Ptr document() const;
80 const QmlJSTools::QmlJSRefactoringFile currentFile() const;
83 SemanticInfo _semanticInfo;
87 A quick-fix operation for the QML/JavaScript editor, which works on a
90 class QmlJSQuickFixOperation: public TextEditor::QuickFixOperation
92 Q_DISABLE_COPY(QmlJSQuickFixOperation)
96 Creates a new QmlJSQuickFixOperation.
98 This operation will copy the complete state, in order to be able to perform
101 \param state The state for which this operation was created.
102 \param priority The priority for this operation.
104 explicit QmlJSQuickFixOperation(const QmlJSQuickFixState &state, int priority = -1);
105 virtual ~QmlJSQuickFixOperation();
107 virtual void perform();
110 typedef Utils::ChangeSet::Range Range;
112 virtual void performChanges(QmlJSTools::QmlJSRefactoringFile *currentFile,
113 QmlJSTools::QmlJSRefactoringChanges *refactoring) = 0;
115 /// \returns A const-reference to the state of the operation.
116 const QmlJSQuickFixState &state() const;
118 /// \returns The name of the file for for which this operation is invoked.
119 QString fileName() const;
122 QmlJSQuickFixState _state;
125 class QmlJSQuickFixFactory: public TextEditor::QuickFixFactory
130 QmlJSQuickFixFactory();
131 virtual ~QmlJSQuickFixFactory();
133 virtual QList<TextEditor::QuickFixOperation::Ptr> matchingOperations(TextEditor::QuickFixState *state);
136 Implement this method to match and create the appropriate
137 QmlJSQuickFixOperation objects.
139 virtual QList<QmlJSQuickFixOperation::Ptr> match(const QmlJSQuickFixState &state) = 0;
141 static QList<QmlJSQuickFixOperation::Ptr> noResult();
142 static QList<QmlJSQuickFixOperation::Ptr> singleResult(QmlJSQuickFixOperation *operation);
147 class QmlJSQuickFixCollector: public TextEditor::QuickFixCollector
152 QmlJSQuickFixCollector();
153 virtual ~QmlJSQuickFixCollector();
155 virtual bool supportsEditor(TextEditor::ITextEditor *editor) const;
156 virtual bool supportsPolicy(TextEditor::CompletionPolicy policy) const;
157 virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::BaseTextEditorWidget *editor);
159 virtual QList<TextEditor::QuickFixFactory *> quickFixFactories() const;
161 /// Registers all quick-fixes in this plug-in as auto-released objects.
162 static void registerQuickFixes(ExtensionSystem::IPlugin *plugIn);
165 } // namespace Internal
166 } // namespace QmlJSEditor
168 #endif // QMLJSQUICKFIX_H