forked from qt-creator/qt-creator
Initial groundwork for the QML context lookups.
This commit is contained in:
@@ -4,7 +4,8 @@ include(../../qtcreatorplugin.pri)
|
||||
include(duieditor_dependencies.pri)
|
||||
include(parser/parser.pri)
|
||||
include(rewriter/rewriter.pri)
|
||||
DEFINES += DUIEDITOR_LIBRARY QT_CREATOR
|
||||
DEFINES += DUIEDITOR_LIBRARY \
|
||||
QT_CREATOR
|
||||
INCLUDEPATH += parser \
|
||||
rewriter
|
||||
HEADERS += duieditor.h \
|
||||
@@ -22,7 +23,10 @@ HEADERS += duieditor.h \
|
||||
duimodelmanager.h \
|
||||
duicodeformatter.h \
|
||||
navigationtokenfinder.h \
|
||||
idcollector.h
|
||||
idcollector.h \
|
||||
qmlexpressionundercursor.h \
|
||||
qmllookupcontext.h \
|
||||
resolveqmlexpression.h
|
||||
SOURCES += duieditor.cpp \
|
||||
duieditorfactory.cpp \
|
||||
duieditorplugin.cpp \
|
||||
@@ -36,5 +40,8 @@ SOURCES += duieditor.cpp \
|
||||
duimodelmanager.cpp \
|
||||
duicodeformatter.cpp \
|
||||
navigationtokenfinder.cpp \
|
||||
idcollector.cpp
|
||||
idcollector.cpp \
|
||||
qmlexpressionundercursor.cpp \
|
||||
qmllookupcontext.cpp \
|
||||
resolveqmlexpression.cpp
|
||||
RESOURCES += duieditor.qrc
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#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
|
||||
@@ -0,0 +1,22 @@
|
||||
#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)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#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
|
||||
@@ -0,0 +1,13 @@
|
||||
#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()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user