boolean (@NotNull PsiReferenceExpression ref, @NotNull PsiClass targetClass) { if (!PsiTreeUtil.isAncestor(targetClass, ref, true)) { return false; } final PsiElement element = PsiTreeUtil.getParentOfType(ref, PsiClassInitializer.class, PsiMethod.class, PsiField.class); if (element instanceof PsiClassInitializer) { return true; } if (element instanceof PsiMethod && ((PsiMethod)element).isConstructor()) { return true; } return false; }