diff options
author | Vlad Seryakov <vseryakov@gmail.com> | 2014-12-14 21:13:35 -0500 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2016-05-20 10:07:58 +0000 |
commit | af56457ab6fdb027f9e3ab58e9a6957fc822d955 (patch) | |
tree | f6fe18672ae6af73da3631bba4b18a0b316b1d1e /src/plugins/qmljstools/qmljslocatordata.cpp | |
parent | 4320aeea18a38715ef1551b773ce701ad168f03b (diff) |
Add support for new javascript methods to QML/JS outline
Extened AST visitor for outline, declaration and locator to include
Javascript methods, prototype functions with formal parameters for
better readability.
Change-Id: Ifbb2b157699c929412196f356b0c28ae0564f866
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/plugins/qmljstools/qmljslocatordata.cpp')
-rw-r--r-- | src/plugins/qmljstools/qmljslocatordata.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/plugins/qmljstools/qmljslocatordata.cpp b/src/plugins/qmljstools/qmljslocatordata.cpp index 5806e577b5..c0febafdc7 100644 --- a/src/plugins/qmljstools/qmljslocatordata.cpp +++ b/src/plugins/qmljstools/qmljslocatordata.cpp @@ -171,6 +171,46 @@ protected: accept(ast->initializer, contextString(context)); return false; } + + bool visit(AST::BinaryExpression *ast) + { + auto fieldExpr = AST::cast<AST::FieldMemberExpression *>(ast->left); + auto funcExpr = AST::cast<AST::FunctionExpression *>(ast->right); + + if (fieldExpr && funcExpr && funcExpr->body && (ast->op == QSOperator::Assign)) { + LocatorData::Entry entry = basicEntry(ast->operatorToken); + + entry.type = LocatorData::Function; + entry.displayName = fieldExpr->name.toString(); + while (fieldExpr) { + if (auto field = AST::cast<AST::FieldMemberExpression *>(fieldExpr->base)) { + entry.displayName.prepend(field->name.toString() + QLatin1Char('.')); + fieldExpr = field; + } else { + if (auto ident = AST::cast<AST::IdentifierExpression *>(fieldExpr->base)) + entry.displayName.prepend(ident->name.toString() + QLatin1Char('.')); + break; + } + } + + entry.displayName += QLatin1Char('('); + for (FormalParameterList *it = funcExpr->formals; it; it = it->next) { + if (it != funcExpr->formals) + entry.displayName += QLatin1String(", "); + if (!it->name.isEmpty()) + entry.displayName += it->name.toString(); + } + entry.displayName += QLatin1Char(')'); + entry.symbolName = entry.displayName; + + m_entries += entry; + + accept(funcExpr->body, contextString(QString::fromLatin1("function %1").arg(entry.displayName))); + return false; + } + + return true; + } }; } // anonymous namespace |