boolean (@NotNull PsiElement element) { PsiElement parent = element.getParent(); while (parent != null && parent != context) { if (parent instanceof PsiForStatement) { if (element != ((PsiForStatement)parent).getInitialization()) return false; } else if (parent instanceof PsiLoopStatement) return false; else if (parent instanceof PsiTryStatement) { if (element != ((PsiTryStatement)parent).getFinallyBlock()) return false; } else if (parent instanceof PsiIfStatement) { if (element != ((PsiIfStatement)parent).getCondition()) return false; } else if (parent instanceof PsiConditionalExpression) { if (element != ((PsiConditionalExpression)parent).getCondition()) return false; } else if (parent instanceof PsiSwitchBlock) { if (element != ((PsiSwitchBlock)parent).getExpression()) return false; } else if (parent instanceof PsiPolyadicExpression polyadicExpression) { IElementType tokenType = polyadicExpression.getOperationTokenType(); if (polyadicExpression.getOperands()[0] != element && (JavaTokenType.ANDAND == tokenType || JavaTokenType.OROR == tokenType)) return false; } else if (parent instanceof PsiLambdaExpression) return false; else if (parent instanceof PsiClass) return false; element = parent; parent = element.getParent(); } return true; }