Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
562a6197
Commit
562a6197
authored
Mar 17, 2011
by
Christian Kamm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
QmlJS: Fix find usages if id and property name conflict.
Task-number: QTCREATORBUG-4097
parent
f488cc0a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
26 deletions
+57
-26
src/plugins/qmljseditor/qmljsfindreferences.cpp
src/plugins/qmljseditor/qmljsfindreferences.cpp
+57
-26
No files found.
src/plugins/qmljseditor/qmljsfindreferences.cpp
View file @
562a6197
...
...
@@ -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
=
t
arget
.
second
;
FindTargetExpression
findTarget
(
doc
,
&
context
);
findTarget
(
offset
);
const
QString
&
name
=
findT
arget
.
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment