PsiLocalVariable (PsiExpression expression, TerminalBlock tb, List<PsiVariable> variables) { // have only one non-final variable if (variables.size() != 1) return null; // have single expression which is either ++x or x++ or x+=1 or x=x+1 PsiReferenceExpression operand = tryCast(extractIncrementedLValue(expression), PsiReferenceExpression.class); if (operand == null) return null; PsiLocalVariable variable = tryCast(operand.resolve(), PsiLocalVariable.class); // the referred variable is the same as non-final variable and not used in intermediate operations if (variable != null && variables.contains(variable) && !tb.isReferencedInOperations(variable)) { return variable; } return null; }