PythonTreeMaker { public ExecStatement execStatement(StatementWithSeparator statementWithSeparator) { AstNode astNode = statementWithSeparator.statement(); Expression expression = expression(astNode.getFirstChild(PythonGrammar.EXPR)); List<Expression> expressions = expressionsFromTest(astNode); Separators separators = statementWithSeparator.separator(); if (expressions.isEmpty()) { return new ExecStatementImpl(toPyToken(astNode.getTokens()).get(0), expression, separators); } Token inToken = toPyToken(astNode.getFirstChild(PythonKeyword.IN).getToken()); Expression globalsExpression = expressions.get(0); Token commaToken = null; Expression localsExpression = null; if (expressions.size() == 2) { commaToken = toPyToken(astNode.getFirstChild(PythonPunctuator.COMMA).getToken()); localsExpression = expressions.get(1); } return new ExecStatementImpl(toPyToken(astNode.getTokens().get(0)), expression, inToken, globalsExpression, commaToken, localsExpression, 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 execStatement() { setRootRule(PythonGrammar.EXEC_STMT); AstNode astNode = p.parse("exec 'foo'"); StatementWithSeparator statementWithSeparator = new StatementWithSeparator(astNode, null); ExecStatement execStatement = treeMaker.execStatement(statementWithSeparator); assertThat(execStatement).isNotNull(); assertThat(execStatement.execKeyword().value()).isEqualTo("exec"); assertThat(execStatement.expression()).isNotNull(); assertThat(execStatement.globalsExpression()).isNull(); assertThat(execStatement.localsExpression()).isNull(); assertThat(execStatement.children()).hasSize(2); astNode = p.parse("exec 'foo' in globals"); statementWithSeparator = new StatementWithSeparator(astNode, null); execStatement = treeMaker.execStatement(statementWithSeparator); assertThat(execStatement).isNotNull(); assertThat(execStatement.execKeyword().value()).isEqualTo("exec"); assertThat(execStatement.expression()).isNotNull(); assertThat(execStatement.globalsExpression()).isNotNull(); assertThat(execStatement.localsExpression()).isNull(); assertThat(execStatement.children()).extracting(child -> child.firstToken().value()) .containsExactly("exec", "'foo'", "in", "globals"); astNode = p.parse("exec 'foo' in globals, locals"); statementWithSeparator = new StatementWithSeparator(astNode, null); execStatement = treeMaker.execStatement(statementWithSeparator); assertThat(execStatement).isNotNull(); assertThat(execStatement.execKeyword().value()).isEqualTo("exec"); assertThat(execStatement.expression()).isNotNull(); assertThat(execStatement.globalsExpression()).isNotNull(); assertThat(execStatement.localsExpression()).isNotNull(); assertThat(execStatement.children()).extracting(child -> child.firstToken().value()) .containsExactly("exec", "'foo'", "in", "globals", ",", "locals"); }