PsiTypeElement (@NotNull final PsiElement startElement) { PsiElement parent = PsiTreeUtil.getParentOfType(startElement, PsiTypeElement.class, PsiVariable.class, PsiMethod.class); if (parent instanceof PsiTypeElement typeElement) { return typeElement; } if (parent instanceof PsiVariable variable) { return variable.getTypeElement(); } if (parent instanceof PsiMethod method) { return method.getReturnTypeElement(); } return null; }