summaryrefslogtreecommitdiff
path: root/src/plugins/qmljseditor
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-06-07 12:12:07 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2010-06-07 12:16:45 +0200
commitf5dae8bc9f8ab63c3f16579906d82bafcbcac5c7 (patch)
treee0f6fe29cf48f415a35247697e12033b4a024e3c /src/plugins/qmljseditor
parentc3caf282cec12d2a2db75e4b9e1a635641a3ac4a (diff)
downloadqt-creator-f5dae8bc9f8ab63c3f16579906d82bafcbcac5c7.tar.gz
Refactored the quickfix engine.
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r--src/plugins/qmljseditor/qmljseditorplugin.cpp3
-rw-r--r--src/plugins/qmljseditor/qmljsquickfix.cpp53
-rw-r--r--src/plugins/qmljseditor/qmljsquickfix.h16
3 files changed, 67 insertions, 5 deletions
diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp
index 3a85c988d6..3efbfe7115 100644
--- a/src/plugins/qmljseditor/qmljseditorplugin.cpp
+++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp
@@ -253,8 +253,9 @@ void QmlJSEditorPlugin::quickFixNow()
// qDebug() << "TODO: outdated document" << editor->documentRevision() << editor->semanticInfo().revision();
// ### FIXME: m_quickFixTimer->start(QUICKFIX_INTERVAL);
m_quickFixTimer->stop();
- }else
+ } else {
TextEditor::Internal::CompletionSupport::instance()->quickFix(m_currentTextEditable);
+ }
}
}
}
diff --git a/src/plugins/qmljseditor/qmljsquickfix.cpp b/src/plugins/qmljseditor/qmljsquickfix.cpp
index cd64160934..db4fb16ab7 100644
--- a/src/plugins/qmljseditor/qmljsquickfix.cpp
+++ b/src/plugins/qmljseditor/qmljsquickfix.cpp
@@ -29,10 +29,20 @@
#include "qmljsquickfix.h"
#include "qmljseditor.h"
+#include "qmljs/parser/qmljsast_p.h"
+#include <QtGui/QApplication>
#include <QtCore/QDebug>
using namespace QmlJSEditor::Internal;
+class QmlJSQuickFixState: public TextEditor::QuickFixState
+{
+public:
+ SemanticInfo semanticInfo;
+};
+
+
+
QmlJSQuickFixOperation::QmlJSQuickFixOperation(TextEditor::BaseTextEditor *editor)
: TextEditor::QuickFixOperation(editor)
{
@@ -42,6 +52,33 @@ QmlJSQuickFixOperation::~QmlJSQuickFixOperation()
{
}
+QmlJS::Document::Ptr QmlJSQuickFixOperation::document() const
+{
+ return _semanticInfo.document;
+}
+
+const QmlJS::Snapshot &QmlJSQuickFixOperation::snapshot() const
+{
+ return _semanticInfo.snapshot;
+}
+
+const SemanticInfo &QmlJSQuickFixOperation::semanticInfo() const
+{
+ return _semanticInfo;
+}
+
+int QmlJSQuickFixOperation::match(TextEditor::QuickFixState *state)
+{
+ QmlJSQuickFixState *s = static_cast<QmlJSQuickFixState *>(state);
+ _semanticInfo = s->semanticInfo;
+ return check();
+}
+
+unsigned QmlJSQuickFixOperation::position(const QmlJS::AST::SourceLocation &loc) const
+{
+ return position(loc.startLine, loc.startColumn);
+}
+
void QmlJSQuickFixOperation::move(const QmlJS::AST::SourceLocation &loc, int to)
{
move(position(loc.startColumn, loc.startColumn), to);
@@ -70,6 +107,14 @@ QmlJSQuickFixCollector::~QmlJSQuickFixCollector()
{
}
+bool QmlJSQuickFixCollector::supportsEditor(TextEditor::ITextEditable *editable)
+{
+ if (qobject_cast<QmlJSTextEditor *>(editable->widget()) != 0)
+ return true;
+
+ return false;
+}
+
TextEditor::QuickFixState *QmlJSQuickFixCollector::initializeCompletion(TextEditor::ITextEditable *editable)
{
if (QmlJSTextEditor *editor = qobject_cast<QmlJSTextEditor *>(editable->widget())) {
@@ -81,16 +126,16 @@ TextEditor::QuickFixState *QmlJSQuickFixCollector::initializeCompletion(TextEdit
return 0;
}
- // ### TODO create the quickfix state
- return 0;
+ QmlJSQuickFixState *state = new QmlJSQuickFixState;
+ state->semanticInfo = info;
+ return state;
}
return 0;
}
-QList<TextEditor::QuickFixOperation::Ptr> QmlJSQuickFixCollector::quickFixOperations(TextEditor::BaseTextEditor *) const
+QList<TextEditor::QuickFixOperation::Ptr> QmlJSQuickFixCollector::quickFixOperations(TextEditor::BaseTextEditor *editor) const
{
QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations;
-
return quickFixOperations;
}
diff --git a/src/plugins/qmljseditor/qmljsquickfix.h b/src/plugins/qmljseditor/qmljsquickfix.h
index 12274a1baa..03a917998a 100644
--- a/src/plugins/qmljseditor/qmljsquickfix.h
+++ b/src/plugins/qmljseditor/qmljsquickfix.h
@@ -30,8 +30,10 @@
#ifndef QMLJSQUICKFIX_H
#define QMLJSQUICKFIX_H
+#include "qmljseditor.h"
#include <texteditor/quickfix.h>
#include <qmljs/parser/qmljsastfwd_p.h>
+#include <qmljs/qmljsdocument.h>
namespace QmlJSEditor {
@@ -47,6 +49,13 @@ public:
QmlJSQuickFixOperation(TextEditor::BaseTextEditor *editor);
virtual ~QmlJSQuickFixOperation();
+ QmlJS::Document::Ptr document() const;
+ const QmlJS::Snapshot &snapshot() const;
+ const SemanticInfo &semanticInfo() const;
+
+ virtual int check() = 0;
+ virtual int match(TextEditor::QuickFixState *state);
+
protected:
using TextEditor::QuickFixOperation::move;
using TextEditor::QuickFixOperation::replace;
@@ -56,12 +65,18 @@ protected:
using TextEditor::QuickFixOperation::copy;
using TextEditor::QuickFixOperation::textOf;
using TextEditor::QuickFixOperation::charAt;
+ using TextEditor::QuickFixOperation::position;
+
+ unsigned position(const QmlJS::AST::SourceLocation &loc) const;
// token based operations
void move(const QmlJS::AST::SourceLocation &loc, int to);
void replace(const QmlJS::AST::SourceLocation &loc, const QString &replacement);
void remove(const QmlJS::AST::SourceLocation &loc);
void copy(const QmlJS::AST::SourceLocation &loc, int to);
+
+private:
+ SemanticInfo _semanticInfo;
};
class QmlJSQuickFixCollector: public TextEditor::QuickFixCollector
@@ -72,6 +87,7 @@ public:
QmlJSQuickFixCollector();
virtual ~QmlJSQuickFixCollector();
+ virtual bool supportsEditor(TextEditor::ITextEditable *editor);
virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable);
virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const;
};