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

0
5 comments
Avatar
Permanently deleted user

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?

>


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

0
Avatar
Permanently deleted user

'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?

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



0
Avatar
Permanently deleted user

But has been reimplemented in MetricsReloaded, if you wish to repurpose it.

--Dave Griffith

0
Avatar
Permanently deleted user

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

0
Avatar
Permanently deleted user

Alain Ravet wrote:

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


I wish for this inspection context feature in 5.0 more than almost any
other feature.

0

Please sign in to leave a comment.