summaryrefslogtreecommitdiff
path: root/src/plugins/qmljseditor
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-03-17 14:43:08 +0100
committerChristian Kamm <christian.d.kamm@nokia.com>2011-03-17 14:43:44 +0100
commit562a619721a3c2f8065b21450d780bc336405dad (patch)
treec493cec3a180591a40bcacd6a413391755bd99c8 /src/plugins/qmljseditor
parentf488cc0af4af121de673798a79f082f33c457fd6 (diff)
downloadqt-creator-562a619721a3c2f8065b21450d780bc336405dad.tar.gz
QmlJS: Fix find usages if id and property name conflict.
Task-number: QTCREATORBUG-4097
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r--src/plugins/qmljseditor/qmljsfindreferences.cpp83
1 files changed, 57 insertions, 26 deletions
diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp
index 7197666a8f..069edae3d4 100644
--- a/src/plugins/qmljseditor/qmljsfindreferences.cpp
+++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp
@@ -363,18 +363,29 @@ private:
class FindTargetExpression: protected Visitor
{
public:
- FindTargetExpression(Document::Ptr doc)
- : _doc(doc)
+ FindTargetExpression(Document::Ptr doc, Context *context)
+ : _doc(doc), _context(context)
{
}
- QPair<Node *, QString> operator()(quint32 offset)
+ void operator()(quint32 offset)
{
- _result = qMakePair((Node *)0, QString());
+ _name = QString::null;
+ _scope = 0;
+ _objectNode = 0;
_offset = offset;
if (_doc)
Node::accept(_doc->ast(), this);
- return _result;
+ }
+
+ QString name() const
+ { return _name; }
+
+ const ObjectValue *scope()
+ {
+ if (!_scope)
+ _context->lookup(_name, &_scope);
+ return _scope;
}
protected:
@@ -398,15 +409,15 @@ protected:
virtual bool visit(IdentifierExpression *node)
{
if (containsOffset(node->identifierToken))
- _result.second = node->name->asString();
+ _name = node->name->asString();
return true;
}
virtual bool visit(FieldMemberExpression *node)
{
if (containsOffset(node->identifierToken)) {
- _result.first = node->base;
- _result.second = node->name->asString();
+ setScope(node->base);
+ _name = node->name->asString();
return false;
}
return true;
@@ -424,13 +435,29 @@ protected:
virtual bool visit(UiObjectBinding *node)
{
- return !checkBindingName(node->qualifiedId);
+ if (!checkBindingName(node->qualifiedId)) {
+ Node *oldObjectNode = _objectNode;
+ _objectNode = node;
+ accept(node->initializer);
+ _objectNode = oldObjectNode;
+ }
+ return false;
+ }
+
+ virtual bool visit(UiObjectDefinition *node)
+ {
+ Node *oldObjectNode = _objectNode;
+ _objectNode = node;
+ accept(node->initializer);
+ _objectNode = oldObjectNode;
+ return false;
}
virtual bool visit(UiPublicMember *node)
{
if (containsOffset(node->identifierToken)) {
- _result.second = node->name->asString();
+ _scope = _doc->bind()->findQmlObject(_objectNode);
+ _name = node->name->asString();
return false;
}
return true;
@@ -444,7 +471,7 @@ protected:
virtual bool visit(FunctionExpression *node)
{
if (containsOffset(node->identifierToken)) {
- _result.second = node->name->asString();
+ _name = node->name->asString();
return false;
}
return true;
@@ -453,7 +480,7 @@ protected:
virtual bool visit(VariableDeclaration *node)
{
if (containsOffset(node->identifierToken)) {
- _result.second = node->name->asString();
+ _name = node->name->asString();
return false;
}
return true;
@@ -473,14 +500,26 @@ private:
bool checkBindingName(UiQualifiedId *id)
{
if (id && id->name && !id->next && containsOffset(id->identifierToken)) {
- _result.second = id->name->asString();
+ _scope = _doc->bind()->findQmlObject(_objectNode);
+ _name = id->name->asString();
return true;
}
return false;
}
- QPair<Node *, QString> _result;
+ void setScope(Node *node)
+ {
+ Evaluate evaluate(_context);
+ const Value *v = evaluate(node);
+ if (v)
+ _scope = v->asObjectValue();
+ }
+
+ QString _name;
+ const ObjectValue *_scope;
+ Node *_objectNode;
Document::Ptr _doc;
+ Context *_context;
quint32 _offset;
};
@@ -593,21 +632,13 @@ static void find_helper(QFutureInterface<FindReferences::Usage> &future,
ScopeAstPath astPath(doc);
builder.push(astPath(offset));
- FindTargetExpression findTarget(doc);
- QPair<Node *, QString> target = findTarget(offset);
- const QString &name = target.second;
+ FindTargetExpression findTarget(doc, &context);
+ findTarget(offset);
+ const QString &name = findTarget.name();
if (name.isEmpty())
return;
- const ObjectValue *scope = 0;
- if (target.first) {
- Evaluate evaluate(&context);
- const Value *v = evaluate(target.first);
- if (v)
- scope = v->asObjectValue();
- } else {
- context.lookup(name, &scope);
- }
+ const ObjectValue *scope = findTarget.scope();
if (!scope)
return;
scope->lookupMember(name, &context, &scope);