boolean (PsiExpression condition, PsiElement ref) { while(ref != condition) { PsiElement parent = ref.getParent(); if(parent instanceof PsiPolyadicExpression polyadicExpression) { IElementType type = polyadicExpression.getOperationTokenType(); if ((type.equals(JavaTokenType.ANDAND) || type.equals(JavaTokenType.OROR)) && polyadicExpression.getOperands()[0] != ref) { return false; } } if(parent instanceof PsiConditionalExpression && ((PsiConditionalExpression)parent).getCondition() != ref) { return false; } ref = parent; } return true; }