void (@NotNull PsiPolyadicExpression expression) { PsiExpression[] operands = expression.getOperands(); PsiExpression lExpr = operands[0]; IElementType tokenType = expression.getOperationTokenType(); if (!SIMPLIFIABLE_POLYADIC_TOKENS.contains(tokenType)) return; if (JavaTokenType.XOR == tokenType) { boolean negate = false; List<PsiExpression> expressions = new ArrayList<>(); for (PsiExpression operand : operands) { final Boolean constBoolean = getConstBoolean(operand); if (constBoolean != null) { markAndCheckCreateResult(); if (constBoolean == Boolean.TRUE) { negate = !negate; } continue; } expressions.add(operand); } if (expressions.isEmpty()) { resultExpression = negate ? trueExpression : falseExpression; } else { String simplifiedText = StringUtil.join(expressions, PsiElement::getText, " ^ "); if (negate) { if (expressions.size() > 1) { simplifiedText = "!(" + simplifiedText + ")"; } else { simplifiedText = BoolUtils.getNegatedExpressionText(expressions.get(0)); } } resultExpression = JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(simplifiedText, expression); } } else { for (int i = 1; i < operands.length; i++) { Boolean l = getConstBoolean(lExpr); PsiExpression operand = operands[i]; Boolean r = getConstBoolean(operand); if (l != null) { simplifyBinary(tokenType, l, operand); } else if (r != null) { simplifyBinary(tokenType, r, lExpr); } else { final PsiJavaToken javaToken = expression.getTokenBeforeOperand(operand); if (javaToken != null && !PsiTreeUtil.hasErrorElements(operand) && !PsiTreeUtil.hasErrorElements(lExpr)) { try { resultExpression = JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(lExpr.getText() + javaToken.getText() + operand.getText(), expression); } catch (IncorrectOperationException e) { resultExpression = null; } } else { resultExpression = null; } } if (resultExpression != null) { lExpr = resultExpression; } } } }