PythonTreeMaker { public YieldStatement yieldStatement(StatementWithSeparator statementWithSeparator) { AstNode stmt = statementWithSeparator.statement(); Separators separators = statementWithSeparator.separator(); return new YieldStatementImpl(yieldExpression(stmt.getFirstChild(PythonGrammar.YIELD_EXPR)), 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 yieldStatement() { setRootRule(PythonGrammar.YIELD_STMT); AstNode astNode = p.parse("yield foo"); StatementWithSeparator statementWithSeparator = new StatementWithSeparator(astNode, null); YieldStatement yieldStatement = treeMaker.yieldStatement(statementWithSeparator); assertThat(yieldStatement).isNotNull(); assertThat(yieldStatement.children()).hasSize(1); YieldExpression yieldExpression = yieldStatement.yieldExpression(); assertThat(yieldExpression).isInstanceOf(YieldExpression.class); assertThat(yieldExpression.expressions()).hasSize(1); assertThat(yieldExpression.children()).hasSize(2); astNode = p.parse("yield foo, bar"); statementWithSeparator = new StatementWithSeparator(astNode, null); yieldStatement = treeMaker.yieldStatement(statementWithSeparator); assertThat(yieldStatement).isNotNull(); assertThat(yieldStatement.children()).hasSize(1); yieldExpression = yieldStatement.yieldExpression(); assertThat(yieldExpression).isInstanceOf(YieldExpression.class); assertThat(yieldExpression.yieldKeyword().value()).isEqualTo("yield"); assertThat(yieldExpression.fromKeyword()).isNull(); assertThat(yieldExpression.expressions()).hasSize(2); assertThat(yieldExpression.children()).hasSize(3); astNode = p.parse("yield from foo"); statementWithSeparator = new StatementWithSeparator(astNode, null); yieldStatement = treeMaker.yieldStatement(statementWithSeparator); assertThat(yieldStatement).isNotNull(); assertThat(yieldStatement.children()).hasSize(1); yieldExpression = yieldStatement.yieldExpression(); assertThat(yieldExpression).isInstanceOf(YieldExpression.class); assertThat(yieldExpression.yieldKeyword().value()).isEqualTo("yield"); assertThat(yieldExpression.fromKeyword().value()).isEqualTo("from"); assertThat(yieldExpression.expressions()).hasSize(1); assertThat(yieldExpression.children()).hasSize(3); astNode = p.parse("yield"); statementWithSeparator = new StatementWithSeparator(astNode, null); yieldStatement = treeMaker.yieldStatement(statementWithSeparator); assertThat(yieldStatement.children()).hasSize(1); assertThat(yieldStatement).isNotNull(); astNode = p.parse("yield foo(), *bar"); statementWithSeparator = new StatementWithSeparator(astNode, null); yieldStatement = treeMaker.yieldStatement(statementWithSeparator); assertThat(yieldStatement.yieldExpression().expressions()).extracting(Tree::getKind).containsExactly(Kind.CALL_EXPR, Kind.UNPACKING_EXPR); }