boolean (PsiFile file, int lineStart, int lineEnd, String methodName) { if (!file.isValid()) return false; PsiElement element = file.findElementAt(lineStart); while (element != null && element.getTextRange().getStartOffset() < lineEnd) { PsiElement finalElement = element; if (finalElement instanceof PsiKeyword keyword && keyword.getTokenType().equals(JavaTokenType.CLASS_KEYWORD)) { PsiElement parent = finalElement.getParent(); if (parent instanceof PsiClass targetClass && (targetClass.getExtendsListTypes().length > 0 || targetClass.getImplementsListTypes().length > 0) && ContainerUtil.exists(targetClass.getMethods(), psiMethod -> methodName.equals(psiMethod.getName()))) { return true; } } element = PsiTreeUtil.nextLeaf(element); } return false; }