2010-06-03 15:49:29 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef QMLJSQUICKFIX_H
|
|
|
|
|
#define QMLJSQUICKFIX_H
|
|
|
|
|
|
2010-06-07 12:12:07 +02:00
|
|
|
#include "qmljseditor.h"
|
2010-07-26 13:06:33 +02:00
|
|
|
#include "qmljsrefactoringchanges.h"
|
2010-06-14 14:52:43 +02:00
|
|
|
|
2010-06-03 15:49:29 +02:00
|
|
|
#include <texteditor/quickfix.h>
|
2010-06-04 11:02:01 +02:00
|
|
|
#include <qmljs/parser/qmljsastfwd_p.h>
|
2010-06-07 12:12:07 +02:00
|
|
|
#include <qmljs/qmljsdocument.h>
|
2010-06-03 15:49:29 +02:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
namespace ExtensionSystem {
|
|
|
|
|
class IPlugin;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
namespace QmlJS {
|
|
|
|
|
class ModelManagerInterface;
|
|
|
|
|
}
|
2010-06-03 15:49:29 +02:00
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
namespace QmlJSEditor {
|
2010-06-03 15:49:29 +02:00
|
|
|
|
|
|
|
|
namespace Internal {
|
2010-07-26 13:06:33 +02:00
|
|
|
class QmlJSQuickFixCollector;
|
|
|
|
|
} // end of namespace Internal
|
2010-06-03 15:49:29 +02:00
|
|
|
|
2010-07-28 17:33:21 +02:00
|
|
|
/*!
|
|
|
|
|
Specialized QuickFixState for QML/JavaScript quick-fixes.
|
|
|
|
|
|
|
|
|
|
This specialized state for QML/JavaScript quick-fixes also holds the
|
|
|
|
|
QmlJSEditor::Internal::SemanticInfo for the document in the editor.
|
|
|
|
|
*/
|
2010-07-26 17:38:13 +02:00
|
|
|
class QmlJSQuickFixState: public TextEditor::QuickFixState
|
2010-06-04 11:02:01 +02:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
friend class Internal::QmlJSQuickFixCollector;
|
2010-06-04 11:02:01 +02:00
|
|
|
|
|
|
|
|
public:
|
2010-07-28 17:33:21 +02:00
|
|
|
/// Creates a new state for the given editor.
|
2010-07-26 13:06:33 +02:00
|
|
|
QmlJSQuickFixState(TextEditor::BaseTextEditor *editor);
|
|
|
|
|
typedef Utils::ChangeSet::Range Range;
|
2010-06-04 11:02:01 +02:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
Internal::SemanticInfo semanticInfo() const;
|
2010-07-28 17:33:21 +02:00
|
|
|
|
|
|
|
|
/// \returns the snapshot holding the document of the editor.
|
2010-07-26 13:06:33 +02:00
|
|
|
QmlJS::Snapshot snapshot() const;
|
2010-07-28 17:33:21 +02:00
|
|
|
|
|
|
|
|
/// \returns the document of the editor
|
2010-06-07 12:12:07 +02:00
|
|
|
QmlJS::Document::Ptr document() const;
|
|
|
|
|
|
2010-07-28 17:33:21 +02:00
|
|
|
/*!
|
|
|
|
|
\returns the offset in the document for the start position of the given
|
|
|
|
|
source location.
|
|
|
|
|
*/
|
2010-07-26 13:06:33 +02:00
|
|
|
unsigned startPosition(const QmlJS::AST::SourceLocation &loc) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Internal::SemanticInfo _semanticInfo;
|
|
|
|
|
};
|
|
|
|
|
|
2010-07-28 17:33:21 +02:00
|
|
|
/*!
|
|
|
|
|
A quick-fix operation for the QML/JavaScript editor, which works on a
|
|
|
|
|
QmlJSQuickFixState .
|
|
|
|
|
*/
|
2010-07-26 17:38:13 +02:00
|
|
|
class QmlJSQuickFixOperation: public TextEditor::QuickFixOperation
|
2010-07-26 13:06:33 +02:00
|
|
|
{
|
|
|
|
|
Q_DISABLE_COPY(QmlJSQuickFixOperation)
|
|
|
|
|
|
|
|
|
|
public:
|
2010-07-28 17:33:21 +02:00
|
|
|
/*!
|
|
|
|
|
Creates a new QmlJSQuickFixOperation.
|
|
|
|
|
|
|
|
|
|
This operation will copy the complete state, in order to be able to perform
|
|
|
|
|
its changes later on.
|
|
|
|
|
|
|
|
|
|
\param state The state for which this operation was created.
|
|
|
|
|
\param priority The priority for this operation.
|
|
|
|
|
*/
|
2010-07-26 13:06:33 +02:00
|
|
|
QmlJSQuickFixOperation(const QmlJSQuickFixState &state, int priority = -1);
|
|
|
|
|
virtual ~QmlJSQuickFixOperation();
|
|
|
|
|
|
2010-07-28 17:33:21 +02:00
|
|
|
protected:
|
|
|
|
|
/// \returns A const-reference to the state of the operation.
|
2010-07-26 13:06:33 +02:00
|
|
|
const QmlJSQuickFixState &state() const;
|
2010-06-07 12:12:07 +02:00
|
|
|
|
2010-07-28 17:33:21 +02:00
|
|
|
/// \returns The name of the file for for which this operation is invoked.
|
2010-06-14 17:15:53 +02:00
|
|
|
QString fileName() const;
|
|
|
|
|
|
2010-07-28 17:33:21 +02:00
|
|
|
/// \returns The refactoring changes associated with this quick-fix operation.
|
2010-07-26 13:06:33 +02:00
|
|
|
QmlJSRefactoringChanges *refactoringChanges() const;
|
2010-06-14 14:52:43 +02:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
protected: // Utility functions forwarding to QmlJSQuickFixState
|
2010-07-28 17:33:21 +02:00
|
|
|
/// \see QmlJSQuickFixState#startPosition
|
2010-07-26 13:06:33 +02:00
|
|
|
unsigned startPosition(const QmlJS::AST::SourceLocation &loc) const
|
|
|
|
|
{ return state().startPosition(loc); }
|
|
|
|
|
|
2010-07-28 17:33:21 +02:00
|
|
|
/// \see QmlJSQuickFixState#range
|
2010-07-26 13:06:33 +02:00
|
|
|
static QmlJSQuickFixState::Range range(int start, int end)
|
|
|
|
|
{ return QmlJSQuickFixState::range(start, end); }
|
2010-06-07 12:12:07 +02:00
|
|
|
|
|
|
|
|
private:
|
2010-07-26 13:06:33 +02:00
|
|
|
QmlJSQuickFixState _state;
|
|
|
|
|
QScopedPointer<QmlJSRefactoringChanges> _refactoringChanges;
|
|
|
|
|
};
|
|
|
|
|
|
2010-07-26 17:38:13 +02:00
|
|
|
class QmlJSQuickFixFactory: public TextEditor::QuickFixFactory
|
2010-07-26 13:06:33 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
QmlJSQuickFixFactory();
|
|
|
|
|
virtual ~QmlJSQuickFixFactory();
|
|
|
|
|
|
|
|
|
|
virtual QList<TextEditor::QuickFixOperation::Ptr> matchingOperations(TextEditor::QuickFixState *state);
|
2010-07-28 17:33:21 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Implement this method to match and create the appropriate
|
|
|
|
|
QmlJSQuickFixOperation objects.
|
|
|
|
|
*/
|
2010-07-26 13:06:33 +02:00
|
|
|
virtual QList<QmlJSQuickFixOperation::Ptr> match(const QmlJSQuickFixState &state) = 0;
|
2010-06-04 11:02:01 +02:00
|
|
|
};
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-06-03 15:49:29 +02:00
|
|
|
class QmlJSQuickFixCollector: public TextEditor::QuickFixCollector
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
QmlJSQuickFixCollector();
|
|
|
|
|
virtual ~QmlJSQuickFixCollector();
|
|
|
|
|
|
2010-06-07 12:12:07 +02:00
|
|
|
virtual bool supportsEditor(TextEditor::ITextEditable *editor);
|
2010-07-26 13:06:33 +02:00
|
|
|
virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::BaseTextEditor *editor);
|
|
|
|
|
|
|
|
|
|
virtual QList<TextEditor::QuickFixFactory *> quickFixFactories() const;
|
|
|
|
|
|
2010-07-28 17:33:21 +02:00
|
|
|
/// Registers all quick-fixes in this plug-in as auto-released objects.
|
2010-07-26 13:06:33 +02:00
|
|
|
static void registerQuickFixes(ExtensionSystem::IPlugin *plugIn);
|
2010-06-03 15:49:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end of namespace Internal
|
|
|
|
|
} // end of namespace QmlJSEditor
|
|
|
|
|
|
|
|
|
|
#endif // QMLJSQUICKFIX_H
|