Problem with adding additional usages to the results of the standard "Find Usages" operation
I have implemented find usages by adding an extension to the com.intellij.referencesSearch extension point
it doesn't add custom usages until I implement `FindUsagesHandlerFactory`
public class CustomFindUsagesHandlerFactory extends FindUsagesHandlerFactory {
@Override
public boolean canFindUsages(PsiElement psiElement) {
return psiElement instanceOf CustomElement || psiElement instanceof PsiMethod;
}
@Nullable
@Override
public FindUsagesHandler createFindUsagesHandler(PsiElement psiElement, boolean b) {
return new CustomFindUsagesHandler(psiElement);
}
}
But After adding CustomFindUsagesHandlerFactory it stopped showing the usages for the interface's base java method as
`CustomFindUsagesHandlerFactory.canFindUsages(PsiElement)` overrides handling of java method (PsiMethod) by JavaFindUsagesHandlerFactory
Please suggest a way which prevents the overriding of java source code find usages and adds additional usages to find usages result?
Please sign in to leave a comment.
heya,
in canFindUsages you could test PsiElement type by comparing it against TokenSet defined in your language
TokenSet.create(list all your elements here).contains(type);tokensets are usually defined in XParserDefinition
if PsiElement is not element in your language elements' tokenset, return false
;)
The find usage action is invoked on a java method, so
IElementType type = PsiElement.getNode().getElementType(); returns `method` type
The `method` type is not in my custom plugin tokenSet as it is a java method, so it will never return true.
> it will never return true.
... for java methods, so other handlers will be tried - including java one.
if it returns true for your symbols, default handlers will not be tried.
or so it seems.
> ... for java methods, so other handlers will be tried - including java one.
But I want to run both my custom handler and the java handler for java methods.
How will i be able to do that with this approach?
> both my custom handler and the java handler for java methods.
does your handler find additional usages for java symbols, and you'd like both handlers (custom & default java find usage handler) to find usage of java symbols?
Yes, my custom find usages handler find additional usages for java symbols, and I'd like both handlers (custom & default java find usage handler) to find usage of java symbols.
I'd try this: CustomFindUsagesHandler extends JavaFindUsagesHandlerin these overriden methods I'd call super methods and merge the results