PsiExpression (PsiExpression initializer, PsiAssignmentExpression assignment) { PsiExpression initializerExpression; PsiJavaToken sign = assignment.getOperationSign(); final IElementType compoundOp = assignment.getOperationTokenType(); final PsiExpression rExpression = assignment.getRExpression(); if (rExpression == null) return null; if (compoundOp == JavaTokenType.EQ) { return rExpression; } if (initializer == null) return null; String opSign = sign.getText().replace("=", ""); IElementType simpleOp = TypeConversionUtil.convertEQtoOperation(compoundOp); if (simpleOp == null) return null; final Project project = assignment.getProject(); final String rightText = rExpression.getText(); String initializerText; if (isIdentity(initializer, opSign)) { initializerText = rightText; } else if (isIdentity(rExpression, opSign)) { initializerText = initializer.getText(); } else { boolean parenthesesForLhs = PsiPrecedenceUtil.getPrecedence(initializer) > PsiPrecedenceUtil.getPrecedenceForOperator(simpleOp); boolean parenthesesForRhs = PsiPrecedenceUtil.areParenthesesNeeded(sign, rExpression); initializerText = (parenthesesForLhs ? "(" + initializer.getText() + ")" : initializer.getText()) + opSign + (parenthesesForRhs ? "(" + rExpression.getText() + ")" : rExpression.getText()); } initializerExpression = JavaPsiFacade.getElementFactory(project).createExpressionFromText(initializerText, assignment); return (PsiExpression)CodeStyleManager.getInstance(project).reformat(initializerExpression); }