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>
This commit is contained in:
Vlad Seryakov
2014-12-14 21:13:35 -05:00
committed by Orgad Shaneh
parent 4320aeea18
commit af56457ab6
4 changed files with 143 additions and 2 deletions

View File

@@ -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