Expressions { public static Expression singleAssignedValue(Name name) { Symbol symbol = name.symbol(); if (symbol == null) { return null; } Expression result = null; for (Usage usage : symbol.usages()) { if (usage.kind() == Usage.Kind.ASSIGNMENT_LHS) { if (result != null) { return null; } Tree parent = usage.tree().parent(); if (parent.is(Kind.EXPRESSION_LIST) && ((ExpressionList) parent).expressions().size() == 1 && parent.parent().is(Kind.ASSIGNMENT_STMT)) { result = ((AssignmentStatement) parent.parent()).assignedValue(); } else { return null; } } else if (usage.isBindingUsage()) { return null; } } return result; } private  Expressions(); static boolean isFalsy(@Nullable Expression expression); static Expression singleAssignedValue(Name name); static Expression removeParentheses(@Nullable Expression expression); static String unescape(StringLiteral stringLiteral); static String unescape(StringElement stringElement);  }
@Test public void singleAssignedValue() { assertThat(lastNameValue("x = 42; x").getKind()).isEqualTo(Kind.NUMERIC_LITERAL); assertThat(lastNameValue("x = ''; x").getKind()).isEqualTo(Kind.STRING_LITERAL); assertThat(lastNameValue("(x, y) = (42, 43); x")).isNull(); assertThat(lastNameValue("x = 42; import x; x")).isNull(); assertThat(lastNameValue("x = 42; x = 43; x")).isNull(); assertThat(lastNameValue("x = 42; y")).isNull(); }