Commit ee1912a4 authored by Milian Wolff's avatar Milian Wolff

Build contexts for UiObjectInitializer nodes.

parent 3e9f4dea
......@@ -71,6 +71,11 @@ void ContextBuilder::setParseSession(ParseSession* session)
m_session = session;
}
Editor* ContextBuilder::editor() const
{
return m_editor.data();
}
bool ContextBuilder::visit(QmlJS::AST::FunctionDeclaration* node)
{
const QualifiedIdentifier functionName(node->name.toString());
......@@ -95,7 +100,16 @@ bool ContextBuilder::visit(QmlJS::AST::FunctionDeclaration* node)
return false;
}
Editor* ContextBuilder::editor() const
bool ContextBuilder::visit(QmlJS::AST::UiObjectInitializer* node)
{
return m_editor.data();
const RangeInRevision range(m_session->locationToRange(node->lbraceToken).end,
m_session->locationToRange(node->rbraceToken).start);
openContext(node, range, DUContext::Class);
return true;
}
void ContextBuilder::endVisit(QmlJS::AST::UiObjectInitializer* /*node*/)
{
closeContext();
}
......@@ -65,7 +65,10 @@ public:
void setParseSession(ParseSession* session);
using Visitor::visit;
using Visitor::endVisit;
virtual bool visit(QmlJS::AST::FunctionDeclaration* node);
virtual bool visit(QmlJS::AST::UiObjectInitializer* node);
virtual void endVisit(QmlJS::AST::UiObjectInitializer* node);
Editor* editor() const;
......
......@@ -103,4 +103,45 @@ void TestContexts::testFunctionContext_data()
<< RangeInRevision(0, 16, 1, 0);
}
void TestContexts::testQMLContext()
{
const IndexedString file("testQMLContext.qml");
ParseSession session(file, "Text {\n"
" id: main\n"
" Text {\n"
" id: child1\n"
" }\n"
" Text {\n"
" id: child2\n"
" }\n"
"}\n");
QVERIFY(session.ast());
QCOMPARE(session.language(), QmlJS::Document::QmlLanguage);
ContextBuilder builder;
builder.setParseSession(&session);
ReferencedTopDUContext top = builder.build(file, session.ast());
QVERIFY(top);
DUChainReadLocker lock;
QCOMPARE(top->type(), DUContext::Global);
QCOMPARE(top->childContexts().count(), 1);
DUContext* mainCtx = top->childContexts().first();
QCOMPARE(mainCtx->type(), DUContext::Class);
QCOMPARE(mainCtx->range(), RangeInRevision(0, 6, 8, 0));
QCOMPARE(mainCtx->childContexts().size(), 2);
DUContext* child1Ctx = mainCtx->childContexts().first();
QCOMPARE(child1Ctx->type(), DUContext::Class);
QCOMPARE(child1Ctx->range(), RangeInRevision(2, 8, 4, 2));
QCOMPARE(child1Ctx->childContexts().size(), 0);
DUContext* child2Ctx = mainCtx->childContexts().last();
QCOMPARE(child2Ctx->type(), DUContext::Class);
QCOMPARE(child2Ctx->range(), RangeInRevision(5, 8, 7, 2));
QCOMPARE(child2Ctx->childContexts().size(), 0);
}
#include "testcontexts.moc"
......@@ -33,6 +33,8 @@ private slots:
void testFunctionContext();
void testFunctionContext_data();
void testQMLContext();
};
#endif // TESTCONTEXTS_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