PythonTreeMaker { public NonlocalStatement nonlocalStatement(StatementWithSeparator statementWithSeparator) { AstNode astNode = statementWithSeparator.statement(); Separators separators = statementWithSeparator.separator(); Token nonlocalKeyword = toPyToken(astNode.getFirstChild(PythonKeyword.NONLOCAL).getToken()); List<Name> variables = astNode.getChildren(PythonGrammar.NAME).stream() .map(PythonTreeMaker::variable) .collect(Collectors.toList()); return new NonlocalStatementImpl(nonlocalKeyword, variables, 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 nonlocalStatement() { setRootRule(PythonGrammar.NONLOCAL_STMT); AstNode astNode = p.parse("nonlocal foo"); StatementWithSeparator statementWithSeparator = new StatementWithSeparator(astNode, null); NonlocalStatement nonlocalStatement = treeMaker.nonlocalStatement(statementWithSeparator); assertThat(nonlocalStatement.nonlocalKeyword().value()).isEqualTo("nonlocal"); assertThat(nonlocalStatement.variables()).hasSize(1); assertThat(nonlocalStatement.variables().get(0).name()).isEqualTo("foo"); assertThat(nonlocalStatement.children()).hasSize(2); astNode = p.parse("nonlocal foo, bar"); statementWithSeparator = new StatementWithSeparator(astNode, null); nonlocalStatement = treeMaker.nonlocalStatement(statementWithSeparator); assertThat(nonlocalStatement.nonlocalKeyword().value()).isEqualTo("nonlocal"); assertThat(nonlocalStatement.variables()).hasSize(2); assertThat(nonlocalStatement.variables().get(0).name()).isEqualTo("foo"); assertThat(nonlocalStatement.variables().get(1).name()).isEqualTo("bar"); assertThat(nonlocalStatement.children()).hasSize(3); }