PythonTreeMaker { public RaiseStatement raiseStatement(StatementWithSeparator statementWithSeparator) { AstNode astNode = statementWithSeparator.statement(); Separators separators = statementWithSeparator.separator(); AstNode fromKeyword = astNode.getFirstChild(PythonKeyword.FROM); List<AstNode> expressions = new ArrayList<>(); AstNode fromExpression = null; if (fromKeyword != null) { expressions.add(astNode.getFirstChild(PythonGrammar.TEST)); fromExpression = astNode.getLastChild(PythonGrammar.TEST); } else { expressions = astNode.getChildren(PythonGrammar.TEST); } List<Expression> expressionTrees = expressions.stream() .map(this::expression) .collect(Collectors.toList()); return new RaiseStatementImpl(toPyToken(astNode.getFirstChild(PythonKeyword.RAISE).getToken()), expressionTrees, fromKeyword == null ? null : toPyToken(fromKeyword.getToken()), fromExpression == null ? null : expression(fromExpression), 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 raiseStatement() { setRootRule(PythonGrammar.RAISE_STMT); AstNode astNode = p.parse("raise foo"); StatementWithSeparator statementWithSeparator = new StatementWithSeparator(astNode, null); RaiseStatement raiseStatement = treeMaker.raiseStatement(statementWithSeparator); assertThat(raiseStatement).isNotNull(); assertThat(raiseStatement.raiseKeyword().value()).isEqualTo("raise"); assertThat(raiseStatement.fromKeyword()).isNull(); assertThat(raiseStatement.fromExpression()).isNull(); assertThat(raiseStatement.expressions()).hasSize(1); assertThat(raiseStatement.children()).hasSize(2); astNode = p.parse("raise foo, bar"); statementWithSeparator = new StatementWithSeparator(astNode, null); raiseStatement = treeMaker.raiseStatement(statementWithSeparator); assertThat(raiseStatement).isNotNull(); assertThat(raiseStatement.raiseKeyword().value()).isEqualTo("raise"); assertThat(raiseStatement.fromKeyword()).isNull(); assertThat(raiseStatement.fromExpression()).isNull(); assertThat(raiseStatement.expressions()).hasSize(2); assertThat(raiseStatement.children()).hasSize(3); astNode = p.parse("raise foo from bar"); statementWithSeparator = new StatementWithSeparator(astNode, null); raiseStatement = treeMaker.raiseStatement(statementWithSeparator); assertThat(raiseStatement).isNotNull(); assertThat(raiseStatement.raiseKeyword().value()).isEqualTo("raise"); assertThat(raiseStatement.fromKeyword().value()).isEqualTo("from"); assertThat(raiseStatement.fromExpression()).isNotNull(); assertThat(raiseStatement.expressions()).hasSize(1); assertThat(raiseStatement.children()).hasSize(4); astNode = p.parse("raise"); statementWithSeparator = new StatementWithSeparator(astNode, null); raiseStatement = treeMaker.raiseStatement(statementWithSeparator); assertThat(raiseStatement).isNotNull(); assertThat(raiseStatement.raiseKeyword().value()).isEqualTo("raise"); assertThat(raiseStatement.fromKeyword()).isNull(); assertThat(raiseStatement.fromExpression()).isNull(); assertThat(raiseStatement.expressions()).isEmpty(); assertThat(raiseStatement.children()).hasSize(1); }