PythonTreeMaker { public CompoundAssignmentStatement compoundAssignment(StatementWithSeparator statementWithSeparator) { AstNode astNode = statementWithSeparator.statement(); Separators separators = statementWithSeparator.separator(); AstNode augAssignNodes = astNode.getFirstChild(PythonGrammar.AUGASSIGN); Expression lhsExpression = exprListOrTestList(augAssignNodes.getPreviousSibling()); AstNode rhsAstNode = augAssignNodes.getNextSibling(); Expression rhsExpression; if (rhsAstNode.is(PythonGrammar.YIELD_EXPR)) { rhsExpression = yieldExpression(rhsAstNode); } else { rhsExpression = exprListOrTestList(rhsAstNode); } return new CompoundAssignmentStatementImpl(lhsExpression, toPyToken(augAssignNodes.getToken()), rhsExpression, separators); }  FileInput fileInput(AstNode astNode); void setParents(Tree root); AnnotatedAssignment annotatedAssignment(StatementWithSeparator statementWithSeparator); PrintStatement printStatement(StatementWithSeparator statementWithSeparator); ExecStatement execStatement(StatementWithSeparator statementWithSeparator); AssertStatement assertStatement(StatementWithSeparator statementWithSeparator); PassStatement passStatement(StatementWithSeparator statementWithSeparator); DelStatement delStatement(StatementWithSeparator statementWithSeparator); ReturnStatement returnStatement(StatementWithSeparator statementWithSeparator); YieldStatement yieldStatement(StatementWithSeparator statementWithSeparator); YieldExpression yieldExpression(AstNode astNode); RaiseStatement raiseStatement(StatementWithSeparator statementWithSeparator); BreakStatement breakStatement(StatementWithSeparator statementWithSeparator); ContinueStatement continueStatement(StatementWithSeparator statementWithSeparator); ImportStatement importStatement(StatementWithSeparator statementWithSeparator); GlobalStatement globalStatement(StatementWithSeparator statementWithSeparator); NonlocalStatement nonlocalStatement(StatementWithSeparator statementWithSeparator); IfStatement ifStatement(AstNode astNode); FunctionDef funcDefStatement(AstNode astNode); ClassDef classDefStatement(AstNode astNode); ForStatement forStatement(AstNode astNode); WhileStatementImpl whileStatement(AstNode astNode); ExpressionStatement expressionStatement(StatementWithSeparator statementWithSeparator); AssignmentStatement assignment(StatementWithSeparator statementWithSeparator); CompoundAssignmentStatement compoundAssignment(StatementWithSeparator statementWithSeparator); TryStatement tryStatement(AstNode astNode); WithStatement withStatement(AstNode astNode); Expression expression(AstNode astNode); Argument argument(AstNode astNode); LambdaExpression lambdaExpression(AstNode astNode);  }
@Test public void compound_assignement_statement() { setRootRule(PythonGrammar.EXPRESSION_STMT); AstNode astNode = p.parse("x += y"); StatementWithSeparator statementWithSeparator = new StatementWithSeparator(astNode, null); CompoundAssignmentStatement pyCompoundAssignmentStatement = treeMaker.compoundAssignment(statementWithSeparator); assertThat(pyCompoundAssignmentStatement.getKind()).isEqualTo(Tree.Kind.COMPOUND_ASSIGNMENT); assertThat(pyCompoundAssignmentStatement.children()).hasSize(3); assertThat(pyCompoundAssignmentStatement.compoundAssignmentToken().value()).isEqualTo("+="); assertThat(pyCompoundAssignmentStatement.lhsExpression().getKind()).isEqualTo(Tree.Kind.NAME); assertThat(pyCompoundAssignmentStatement.rhsExpression().getKind()).isEqualTo(Tree.Kind.NAME); setRootRule(PythonGrammar.EXPRESSION_STMT); astNode = p.parse("x,y,z += 1"); statementWithSeparator = new StatementWithSeparator(astNode, null); pyCompoundAssignmentStatement = treeMaker.compoundAssignment(statementWithSeparator); assertThat(pyCompoundAssignmentStatement.firstToken().value()).isEqualTo("x"); assertThat(pyCompoundAssignmentStatement.lastToken().value()).isEqualTo("1"); assertThat(pyCompoundAssignmentStatement.getKind()).isEqualTo(Tree.Kind.COMPOUND_ASSIGNMENT); assertThat(pyCompoundAssignmentStatement.children()).hasSize(3); assertThat(pyCompoundAssignmentStatement.compoundAssignmentToken().value()).isEqualTo("+="); assertThat(pyCompoundAssignmentStatement.lhsExpression().getKind()).isEqualTo(Tree.Kind.TUPLE); assertThat(pyCompoundAssignmentStatement.rhsExpression().getKind()).isEqualTo(Tree.Kind.NUMERIC_LITERAL); setRootRule(PythonGrammar.EXPRESSION_STMT); astNode = p.parse("x += yield y"); statementWithSeparator = new StatementWithSeparator(astNode, null); pyCompoundAssignmentStatement = treeMaker.compoundAssignment(statementWithSeparator); assertThat(pyCompoundAssignmentStatement.getKind()).isEqualTo(Tree.Kind.COMPOUND_ASSIGNMENT); assertThat(pyCompoundAssignmentStatement.children()).hasSize(3); assertThat(pyCompoundAssignmentStatement.compoundAssignmentToken().value()).isEqualTo("+="); assertThat(pyCompoundAssignmentStatement.lhsExpression().getKind()).isEqualTo(Tree.Kind.NAME); assertThat(pyCompoundAssignmentStatement.rhsExpression().getKind()).isEqualTo(Tree.Kind.YIELD_EXPR); astNode = p.parse("x *= z"); statementWithSeparator = new StatementWithSeparator(astNode, null); pyCompoundAssignmentStatement = treeMaker.compoundAssignment(statementWithSeparator); assertThat(pyCompoundAssignmentStatement.getKind()).isEqualTo(Tree.Kind.COMPOUND_ASSIGNMENT); assertThat(pyCompoundAssignmentStatement.compoundAssignmentToken().value()).isEqualTo("*="); }