PsiExpression (PsiAssignmentExpression assignment, PsiVariable variable, PsiCodeBlock block) { List<PsiExpression> operands = new ArrayList<>(); while (true) { if (assignment == null) return null; PsiExpression rExpression = assignment.getRExpression(); if (rExpression == null) return null; operands.add(rExpression); IElementType type = assignment.getOperationTokenType(); if (type.equals(JavaTokenType.EQ)) break; if (!type.equals(JavaTokenType.PLUSEQ)) { return null; } PsiElement[] previous = DefUseUtil.getDefs(block, variable, assignment); if (previous.length != 1) return null; PsiElement def = previous[0]; if (def instanceof PsiLocalVariable) { PsiExpression initializer = ((PsiLocalVariable)def).getInitializer(); if (initializer == null) return null; operands.add(initializer); break; } else if (def instanceof PsiReferenceExpression) { assignment = tryCast(def.getParent(), PsiAssignmentExpression.class); } else return null; } if (operands.size() == 1) { return operands.get(0); } return JavaPsiFacade.getElementFactory(block.getProject()).createExpressionFromText( StreamEx.ofReversed(operands).map(op -> ParenthesesUtils.getText(op, PsiPrecedenceUtil.ADDITIVE_PRECEDENCE)).joining("+"), assignment); }