boolean (@NotNull PsiExpression value) { Ref<Boolean> hasFieldRefs = Ref.create(false); boolean allowed = PsiTreeUtil.processElements(value, e -> { if (!(e instanceof PsiExpression)) return true; if (e instanceof PsiInstanceOfExpression || e instanceof PsiParenthesizedExpression || e instanceof PsiLiteralExpression || e instanceof PsiPolyadicExpression || e instanceof PsiUnaryExpression || e instanceof PsiConditionalExpression || e instanceof PsiTypeCastExpression || e instanceof PsiArrayAccessExpression || e instanceof PsiLambdaExpression || e instanceof PsiMethodReferenceExpression || e instanceof PsiThisExpression) { return true; } if (e instanceof PsiReferenceExpression) { PsiElement target = ((PsiReferenceExpression)e).resolve(); if (target instanceof PsiField && !((PsiField)target).hasModifierProperty(PsiModifier.STATIC)) { hasFieldRefs.set(true); } return true; } return false; }); return allowed && hasFieldRefs.get(); }