Commit 78dbeb4f authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Initial groundwork for the QML context lookups.

parent baf7003b
...@@ -4,7 +4,8 @@ include(../../qtcreatorplugin.pri) ...@@ -4,7 +4,8 @@ include(../../qtcreatorplugin.pri)
include(duieditor_dependencies.pri) include(duieditor_dependencies.pri)
include(parser/parser.pri) include(parser/parser.pri)
include(rewriter/rewriter.pri) include(rewriter/rewriter.pri)
DEFINES += DUIEDITOR_LIBRARY QT_CREATOR DEFINES += DUIEDITOR_LIBRARY \
QT_CREATOR
INCLUDEPATH += parser \ INCLUDEPATH += parser \
rewriter rewriter
HEADERS += duieditor.h \ HEADERS += duieditor.h \
...@@ -22,7 +23,10 @@ HEADERS += duieditor.h \ ...@@ -22,7 +23,10 @@ HEADERS += duieditor.h \
duimodelmanager.h \ duimodelmanager.h \
duicodeformatter.h \ duicodeformatter.h \
navigationtokenfinder.h \ navigationtokenfinder.h \
idcollector.h idcollector.h \
qmlexpressionundercursor.h \
qmllookupcontext.h \
resolveqmlexpression.h
SOURCES += duieditor.cpp \ SOURCES += duieditor.cpp \
duieditorfactory.cpp \ duieditorfactory.cpp \
duieditorplugin.cpp \ duieditorplugin.cpp \
...@@ -36,5 +40,8 @@ SOURCES += duieditor.cpp \ ...@@ -36,5 +40,8 @@ SOURCES += duieditor.cpp \
duimodelmanager.cpp \ duimodelmanager.cpp \
duicodeformatter.cpp \ duicodeformatter.cpp \
navigationtokenfinder.cpp \ navigationtokenfinder.cpp \
idcollector.cpp idcollector.cpp \
qmlexpressionundercursor.cpp \
qmllookupcontext.cpp \
resolveqmlexpression.cpp
RESOURCES += duieditor.qrc RESOURCES += duieditor.qrc
#include "qmljsast_p.h"
#include "qmljsengine_p.h"
#include "qmlexpressionundercursor.h"
using namespace DuiEditor;
using namespace DuiEditor::Internal;
using namespace QmlJS;
using namespace QmlJS::AST;
QmlExpressionUnderCursor::QmlExpressionUnderCursor()
{
}
void QmlExpressionUnderCursor::operator()(const QTextCursor &cursor)
{
_pos = cursor.position();
}
bool QmlExpressionUnderCursor::visit(QmlJS::AST::Block *ast)
{
_scopes.push(ast);
return true;
}
void QmlExpressionUnderCursor::endVisit(QmlJS::AST::Block *)
{
_scopes.pop();
}
bool QmlExpressionUnderCursor::visit(QmlJS::AST::UiObjectBinding *ast)
{
_scopes.push(ast);
return true;
}
void QmlExpressionUnderCursor::endVisit(QmlJS::AST::UiObjectBinding *)
{
_scopes.pop();
}
bool QmlExpressionUnderCursor::visit(QmlJS::AST::UiObjectDefinition *ast)
{
_scopes.push(ast);
return true;
}
void QmlExpressionUnderCursor::endVisit(QmlJS::AST::UiObjectDefinition *)
{
_scopes.pop();
}
bool QmlExpressionUnderCursor::visit(QmlJS::AST::UiScriptBinding *ast)
{
if (ast->firstSourceLocation().offset <= _pos && _pos <= ast->lastSourceLocation().end()) {
_expressionNode = ast;
_expressionScopes = _scopes;
}
return false;
}
#ifndef QMLEXPRESSIONUNDERCURSOR_H
#define QMLEXPRESSIONUNDERCURSOR_H
#include <QStack>
#include <QTextCursor>
#include "qmljsastvisitor_p.h"
namespace DuiEditor {
namespace Internal {
class QmlExpressionUnderCursor: protected QmlJS::AST::Visitor
{
public:
QmlExpressionUnderCursor();
void operator()(const QTextCursor &cursor);
QStack<QmlJS::AST::Node *> expressionScopes() const
{ return _expressionScopes; }
QmlJS::AST::Node *expressionNode() const
{ return _expressionNode; }
protected:
virtual bool visit(QmlJS::AST::Block *ast);
virtual bool visit(QmlJS::AST::UiObjectBinding *ast);
virtual bool visit(QmlJS::AST::UiObjectDefinition *ast);
virtual bool visit(QmlJS::AST::UiScriptBinding *ast);
virtual void endVisit(QmlJS::AST::Block *);
virtual void endVisit(QmlJS::AST::UiObjectBinding *);
virtual void endVisit(QmlJS::AST::UiObjectDefinition *);
private:
QStack<QmlJS::AST::Node *> _scopes;
QStack<QmlJS::AST::Node *> _expressionScopes;
QmlJS::AST::Node *_expressionNode;
quint32 _pos;
};
} // namespace Internal
} // namespace DuiEditor
#endif // QMLEXPRESSIONUNDERCURSOR_H
#include "qmljsast_p.h"
#include "qmljsengine_p.h"
#include "qmlexpressionundercursor.h"
#include "qmllookupcontext.h"
#include "resolveqmlexpression.h"
using namespace DuiEditor;
using namespace DuiEditor::Internal;
using namespace QmlJS;
using namespace QmlJS::AST;
QmlLookupContext::QmlLookupContext(const QStack<QmlJS::AST::Node *> &scopes,
QmlJS::AST::Node *expressionNode,
const DuiDocument::Ptr &doc,
const Snapshot &snapshot):
_scopes(scopes),
_expressionNode(expressionNode),
_doc(doc),
_snapshot(snapshot)
{
}
#ifndef QMLLOOKUPCONTEXT_H
#define QMLLOOKUPCONTEXT_H
#include <QStack>
#include "duidocument.h"
#include "qmljsastvisitor_p.h"
namespace DuiEditor {
namespace Internal {
class QmlLookupContext
{
public:
QmlLookupContext(const QStack<QmlJS::AST::Node *> &scopes,
QmlJS::AST::Node *expressionNode,
const DuiDocument::Ptr &doc,
const Snapshot &snapshot);
private:
QStack<QmlJS::AST::Node *> _scopes;
QmlJS::AST::Node *_expressionNode;
DuiDocument::Ptr _doc;
Snapshot _snapshot;
};
} // namespace Internal
} // namespace DuiEditor
#endif // QMLLOOKUPCONTEXT_H
#include "qmljsast_p.h"
#include "qmljsengine_p.h"
#include "resolveqmlexpression.h"
using namespace DuiEditor;
using namespace DuiEditor::Internal;
using namespace QmlJS;
using namespace QmlJS::AST;
ResolveQmlExpression::ResolveQmlExpression()
{
}
#ifndef RESOLVEQMLEXPRESSION_H
#define RESOLVEQMLEXPRESSION_H
#include "qmljsastvisitor_p.h"
namespace DuiEditor {
namespace Internal {
class ResolveQmlExpression: protected QmlJS::AST::Visitor
{
public:
ResolveQmlExpression();
protected:
private:
};
} // namespace Internal
} // namespace DuiEditor
#endif // RESOLVEQMLEXPRESSION_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment