ParentContext () { PsiElement parent = myExpression.getParent(); if (parent instanceof PsiAssignmentExpression && parent.getParent() instanceof PsiExpressionStatement && !(parent.getParent().getParent() instanceof PsiSwitchLabeledRuleStatement) && ((PsiAssignmentExpression)parent).getRExpression() == myExpression) { return ParentContext.ASSIGNMENT; } if (parent instanceof PsiLocalVariable var) { if (!var.getTypeElement().isInferredType() || PsiTypesUtil.isDenotableType(var.getType(), parent)) { return ParentContext.ASSIGNMENT; } } if (parent instanceof PsiReturnStatement || parent instanceof PsiYieldStatement || parent instanceof PsiThrowStatement) { return ParentContext.RETURN; } if (parent instanceof PsiIfStatement ifStatement && ifStatement.getThenBranch() != null) { PsiStatement elseBranch = ifStatement.getElseBranch(); if (elseBranch == null) { return ParentContext.SIMPLE_IF_CONDITION; } // SIMPLE_IF_CONDITION is used now only to split 'if' with polyadic, so we may assume that at least first // operand should be kept. If the subsequent conditions in else branches are mutually exclusive with this one, // then it's still safe to split. // TODO: support splitting at other operand, not only at 0 if (!(PsiUtil.skipParenthesizedExprDown(myExpression) instanceof PsiPolyadicExpression polyadic) || !polyadic.getOperationTokenType().equals(JavaTokenType.ANDAND)) { return ParentContext.UNKNOWN; } if (isExclusiveElseBranch(polyadic.getOperands()[0], elseBranch)) { return ParentContext.SIMPLE_IF_CONDITION; } } return ParentContext.UNKNOWN; }