findig references: a few questions
Context:
I'm writing an inspection to locate production code that is used only by
test code, and annotate it with @TestOnly.
=> for each class, method and field of the project, the inspection:
- obtains the references to it, even in xml files (see code below)
- inspect the references.
code to find the references:
searchHelper = i_psiMember.getManager().getSearchHelper();
scope = GlobalSearchScope.projectScope
(i_psiMember.getManager ().getProject ());
// scope = i_psiMember.getUseScope();
references = searchHelper.findReferences (i_psiMember, scope,
i_ignoreAccessScope);
return references;
Q1/ this code is slow (50-100 ms/call, for each member! => it takes
minutes for a whole project)
Is there a way to optimize it?
Q2/ what's the purpose of ignoreAccessScope
Q3/ what's the difference between
GlobalSearchScope scope = GlobalSearchScope.projectScope
(i_psiMember.getManager ().getProject ());
and
SearchScope scope = i_psiMember.getUseScope();
Alain
Please sign in to leave a comment.
>
>
I'm puzzled by this slowness: the standard General inspection "find
unused declarations" is fast, although it must also find the references
to declarations, like my slow inspection do.
Why is it so much faster?
Alain
'Unused declaration' doesn't call processReferences. (Well, it indeed processes
references but only outside of the inspection scope).
Instead it builds reference graph by resolving all the references inside
inspection scope (which includes all the files in the scope).
This API isn't avaliable for plugin writers unfortunately.
-
Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"
>> references = searchHelper.findReferences (i_psiMember, scope,
>> i_ignoreAccessScope);
>>
>> Q1/ this code is slow (50-100 ms/call, for each member! => it takes
>> minutes for a whole project)
>> Is there a way to optimize it?
But has been reimplemented in MetricsReloaded, if you wish to repurpose it.
--Dave Griffith
Dave
>But has been reimplemented in MetricsReloaded, if you wish to repurpose it.
>
>
I'm afraid it can't be used in the context of inspections, as there is
no InspectionStart/End event we can listen too to fill/clear the cache,
before using the info.
Alain
Alain Ravet wrote:
>> But has been reimplemented in MetricsReloaded, if you wish to
>> repurpose it.
>>
>>
>>
I wish for this inspection context feature in 5.0 more than almost any
other feature.