summaryrefslogtreecommitdiff
path: root/src
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
parentc3caf282cec12d2a2db75e4b9e1a635641a3ac4a (diff)
downloadqt-creator-f5dae8bc9f8ab63c3f16579906d82bafcbcac5c7.tar.gz
Refactored the quickfix engine.
Diffstat (limited to 'src')
-rw-r--r--src/plugins/cppeditor/cppquickfix.cpp5
-rw-r--r--src/plugins/cppeditor/cppquickfix.h1
-rw-r--r--src/plugins/cpptools/cppmodelmanager.h2
-rw-r--r--src/plugins/cpptools/cppmodelmanagerinterface.h6
-rw-r--r--src/plugins/qmljseditor/qmljseditorplugin.cpp3
-rw-r--r--src/plugins/qmljseditor/qmljsquickfix.cpp53
-rw-r--r--src/plugins/qmljseditor/qmljsquickfix.h16
-rw-r--r--src/plugins/texteditor/quickfix.cpp3
-rw-r--r--src/plugins/texteditor/quickfix.h1
9 files changed, 80 insertions, 10 deletions
diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp
index f3d6bc3dc3..e1adf2d64e 100644
--- a/src/plugins/cppeditor/cppquickfix.cpp
+++ b/src/plugins/cppeditor/cppquickfix.cpp
@@ -1036,6 +1036,11 @@ CppQuickFixCollector::~CppQuickFixCollector()
{
}
+bool CppQuickFixCollector::supportsEditor(TextEditor::ITextEditable *editor)
+{
+ return CppTools::CppModelManagerInterface::instance()->isCppEditor(editor);
+}
+
TextEditor::QuickFixState *CppQuickFixCollector::initializeCompletion(TextEditor::ITextEditable *editable)
{
if (CPPEditor *editor = qobject_cast<CPPEditor *>(editable->widget())) {
diff --git a/src/plugins/cppeditor/cppquickfix.h b/src/plugins/cppeditor/cppquickfix.h
index 4b1b125718..673e50ffe5 100644
--- a/src/plugins/cppeditor/cppquickfix.h
+++ b/src/plugins/cppeditor/cppquickfix.h
@@ -116,6 +116,7 @@ public:
CppQuickFixCollector();
virtual ~CppQuickFixCollector();
+ virtual bool supportsEditor(TextEditor::ITextEditable *editor);
virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable);
virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const;
};
diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h
index 0058e4edaf..5659604141 100644
--- a/src/plugins/cpptools/cppmodelmanager.h
+++ b/src/plugins/cpptools/cppmodelmanager.h
@@ -103,7 +103,7 @@ public:
inline Core::ICore *core() const { return m_core; }
- bool isCppEditor(Core::IEditor *editor) const; // ### private
+ virtual bool isCppEditor(Core::IEditor *editor) const;
CppEditorSupport *editorSupport(TextEditor::ITextEditor *editor) const
{ return m_editorSupport.value(editor); }
diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h
index cc1177a27f..94add37863 100644
--- a/src/plugins/cpptools/cppmodelmanagerinterface.h
+++ b/src/plugins/cpptools/cppmodelmanagerinterface.h
@@ -38,6 +38,10 @@
#include <QtCore/QStringList>
#include <QtCore/QFuture>
+namespace Core {
+ class IEditor;
+}
+
namespace CPlusPlus {
class LookupContext;
}
@@ -110,6 +114,8 @@ public:
static CppModelManagerInterface *instance();
+ virtual bool isCppEditor(Core::IEditor *editor) const = 0;
+
virtual WorkingCopy workingCopy() const = 0;
virtual CPlusPlus::Snapshot snapshot() const = 0;
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;
};
diff --git a/src/plugins/texteditor/quickfix.cpp b/src/plugins/texteditor/quickfix.cpp
index 2259a03a7d..7fdb31c581 100644
--- a/src/plugins/texteditor/quickfix.cpp
+++ b/src/plugins/texteditor/quickfix.cpp
@@ -181,9 +181,6 @@ TextEditor::ITextEditable *QuickFixCollector::editor() const
int QuickFixCollector::startPosition() const
{ return _editable->position(); }
-bool QuickFixCollector::supportsEditor(TextEditor::ITextEditable *)
-{ return true; }
-
bool QuickFixCollector::triggersCompletion(TextEditor::ITextEditable *)
{ return false; }
diff --git a/src/plugins/texteditor/quickfix.h b/src/plugins/texteditor/quickfix.h
index f3393142cb..d5b9d73895 100644
--- a/src/plugins/texteditor/quickfix.h
+++ b/src/plugins/texteditor/quickfix.h
@@ -125,7 +125,6 @@ public:
virtual TextEditor::ITextEditable *editor() const;
virtual int startPosition() const;
- virtual bool supportsEditor(TextEditor::ITextEditable *editor);
virtual bool triggersCompletion(TextEditor::ITextEditable *editor);
virtual int startCompletion(TextEditor::ITextEditable *editor);
virtual void completions(QList<TextEditor::CompletionItem> *completions);