boolean (PsiReferenceExpression ref, PsiClass targetClass) { PsiExpression qualifierExpression = ref.getQualifierExpression(); while (qualifierExpression instanceof PsiParenthesizedExpression) { qualifierExpression = ((PsiParenthesizedExpression) qualifierExpression).getExpression(); } if (qualifierExpression instanceof PsiReferenceExpression referenceExpression) { return referenceExpression.resolve() instanceof PsiClass; } else if (qualifierExpression != null) { return false; } else if (ref instanceof PsiMethodReferenceExpression) { return true; } else { assert PsiTreeUtil.isAncestor(targetClass, ref, true); PsiModifierListOwner owner = PsiTreeUtil.getParentOfType(ref, PsiModifierListOwner.class); if (owner instanceof PsiMethod method && method.isConstructor()) { //usages inside delegating constructor call PsiExpression run = ref; while (run.getParent() instanceof PsiExpression) { run = (PsiExpression)run.getParent(); } if (run.getParent() instanceof PsiExpressionList && run.getParent().getParent() instanceof PsiMethodCallExpression) { @NonNls String calleeText = ((PsiMethodCallExpression)run.getParent().getParent()).getMethodExpression().getText(); if (calleeText.equals(PsiKeyword.THIS) || calleeText.equals(PsiKeyword.SUPER)) return true; } } while (owner != null && owner != targetClass) { if (owner.hasModifierProperty(PsiModifier.STATIC)) return true; owner = PsiTreeUtil.getParentOfType(owner, PsiModifierListOwner.class); } } return false; }