ExpressionUtils { public static Optional<Symbol> getAssignedSymbol(ExpressionTree exp) { Tree parent = exp.parent(); if (parent != null) { if (parent.is(Tree.Kind.ASSIGNMENT)) { return extractIdentifierSymbol(((AssignmentExpressionTree) parent).variable()); } else if (parent.is(Tree.Kind.VARIABLE)) { return Optional.of(((VariableTree) parent).simpleName().symbol()); } } return Optional.empty(); } private  ExpressionUtils(); static boolean isSimpleAssignment(AssignmentExpressionTree tree); static boolean isSelectOnThisOrSuper(AssignmentExpressionTree tree); static boolean isSelectOnThisOrSuper(MemberSelectExpressionTree tree); static IdentifierTree extractIdentifier(AssignmentExpressionTree tree); static Optional<Symbol> extractIdentifierSymbol(ExpressionTree tree); static boolean isInvocationOnVariable(MethodInvocationTree mit, @Nullable Symbol variable, boolean defaultReturn); static ExpressionTree skipParentheses(ExpressionTree tree); static boolean isNullLiteral(ExpressionTree tree); static boolean isSecuringByte(ExpressionTree expression); static IdentifierTree methodName(MethodInvocationTree mit); @CheckForNull static MethodTree getEnclosingMethod(ExpressionTree expr); static Optional<Symbol> getAssignedSymbol(ExpressionTree exp); static boolean isThis(ExpressionTree expression); @CheckForNull static Object resolveAsConstant(ExpressionTree tree);  }
@Test void test_get_assigned_symbol() throws Exception { File file = new File("src/test/files/model/ExpressionUtilsTest.java"); CompilationUnitTree tree = JParserTestUtils.parse(file); MethodTree methodTree = (MethodTree) ((ClassTree) tree.types().get(0)).members().get(1); List<AssignmentExpressionTree> assignments = findAssignmentExpressionTrees(methodTree); assertThat(assignments).hasSize(5); assertThat(ExpressionUtils.getAssignedSymbol(assignments.get(0).expression())).isPresent(); assertThat(ExpressionUtils.getAssignedSymbol(assignments.get(1).expression())).isPresent(); assertThat(ExpressionUtils.getAssignedSymbol(assignments.get(0).expression())). contains(ExpressionUtils.getAssignedSymbol(assignments.get(1).expression()).get()); assertThat(ExpressionUtils.getAssignedSymbol(assignments.get(2).expression())).isNotPresent(); assertThat(ExpressionUtils.getAssignedSymbol(assignments.get(3).expression())).isNotPresent(); assertThat(ExpressionUtils.getAssignedSymbol(assignments.get(4).expression())).isNotPresent(); List<VariableTree> variables = findVariableTrees(methodTree); assertThat(variables).hasSize(2); assertThat(ExpressionUtils.getAssignedSymbol(variables.get(1).initializer())).isPresent(); }