inverse of resolve() + efficiency question
Hi all,
Q1/ Given a PsiMember (field, method, class), how can I obtain all the
references to it?
Q2/ Is it - Q1 - the most efficient way to locate fields/methods/classes
that are annotated with "@TestOnly", but are only used by test code?
Context:
I've created a @TestOnly annotation, to tag fields/methods/classes that
can only be accessed by test code (== code in test source tree).
I want to create an inspection that locates all the f/m/c that are not
yet annotated but could be, because they are only used by test code).
In the IG code I found the VariableAccessVisitor, that works the other
way around by counting accesses in a map, but it looks less efficient
for my purpose (because of the hashCode() usage and the big structure
building). Am I wrong, on this last assumption?
TIA
Alain
Please sign in to leave a comment.
Alain Ravet wrote:
>
>
Stupid me. I must be blind to have missed
x.getReferences ()
Q2 remains, though.
Alain
Alain Ravet wrote:
>>
>> Q1/ Given a PsiMember (field, method, class), how can I obtain all the
>> references to it?
>>
I don't think getReferences does what you want. I feel pretty sure that
getReferences returns any references contained in the element, like
"System" and "out" and "println" and "var" in System.out.println(var).
>
>
answer:
public static PsiReference[] referencesTo (PsiMember
i_psiMember, boolean i_ignoreAccessScope)
{
PsiSearchHelper searchHelper =
i_psiMember.getManager().getSearchHelper();
SearchScope searchUseScope = i_psiMember.getUseScope();
return searchHelper.findReferences(i_psiMember,
searchUseScope, i_ignoreAccessScope);
}