boolean (PsiReference ref) { // copied from Java if (!(ref instanceof PsiReferenceExpression || ref instanceof KtReference)) { if (!(ref instanceof PsiElement)) { return true; } PsiElement parent = ((PsiElement) ref).getParent(); if (parent instanceof PsiNewExpression) { if (((PsiNewExpression) parent).getClassReference() != ref) { return true; } } else if (parent instanceof PsiAnonymousClass) { if (((PsiAnonymousClass) parent).getBaseClassReference() != ref) { return true; } } else if (ref instanceof LightMemberReference) { PsiElement refTarget = ref.resolve(); // Accept implicit superclass constructor reference in Java code if (!(refTarget instanceof PsiMethod && ((PsiMethod) refTarget).isConstructor())) return true; } else { return true; } } PsiElement refElement = ref.getElement(); if (PsiTreeUtil.getParentOfType(refElement, KtImportDirective.class, true) != null) return true; PsiElement element = (refElement instanceof KtElement) ? CallHierarchyUtilsKt.getCallHierarchyElement(refElement) : PsiTreeUtil.getParentOfType(refElement, PsiMethod.class, false); if (kotlinOnly && !(element instanceof KtNamedDeclaration)) return true; // If reference belongs to property initializer, show enclosing declaration instead if (element instanceof KtProperty property) { if (PsiTreeUtil.isAncestor(property.getInitializer(), refElement, false)) { element = CallHierarchyUtilsKt.getCallHierarchyElement(element.getParent()); } } if (element != null) { onAccept(ref, element); } return true; }