PythonTreeMaker { public ImportStatement importStatement(StatementWithSeparator statementWithSeparator) { AstNode astNode = statementWithSeparator.statement(); Separators separators = statementWithSeparator.separator(); AstNode importStmt = astNode.getFirstChild(); if (importStmt.is(PythonGrammar.IMPORT_NAME)) { return importName(importStmt, separators); } return importFromStatement(importStmt, 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 importStatement() { setRootRule(PythonGrammar.IMPORT_STMT); AstNode astNode = p.parse("import foo"); StatementWithSeparator statementWithSeparator = new StatementWithSeparator(astNode, null); ImportName importStatement = (ImportName) treeMaker.importStatement(statementWithSeparator); assertThat(importStatement.firstToken().value()).isEqualTo("import"); assertThat(importStatement.lastToken().value()).isEqualTo("foo"); assertThat(importStatement).isNotNull(); assertThat(importStatement.importKeyword().value()).isEqualTo("import"); assertThat(importStatement.modules()).hasSize(1); AliasedName importedName1 = importStatement.modules().get(0); assertThat(importedName1.dottedName().names()).hasSize(1); assertThat(importedName1.dottedName().names().get(0).name()).isEqualTo("foo"); assertThat(importStatement.children()).hasSize(2); astNode = p.parse("import foo as f"); statementWithSeparator = new StatementWithSeparator(astNode, null); importStatement = (ImportName) treeMaker.importStatement(statementWithSeparator); assertThat(importStatement).isNotNull(); assertThat(importStatement.firstToken().value()).isEqualTo("import"); assertThat(importStatement.lastToken().value()).isEqualTo("f"); assertThat(importStatement.importKeyword().value()).isEqualTo("import"); assertThat(importStatement.modules()).hasSize(1); importedName1 = importStatement.modules().get(0); assertThat(importedName1.firstToken().value()).isEqualTo("foo"); assertThat(importedName1.lastToken().value()).isEqualTo("f"); assertThat(importedName1.dottedName().names()).hasSize(1); assertThat(importedName1.dottedName().names().get(0).name()).isEqualTo("foo"); assertThat(importedName1.asKeyword().value()).isEqualTo("as"); assertThat(importedName1.alias().name()).isEqualTo("f"); assertThat(importStatement.children()).hasSize(2); astNode = p.parse("import foo.bar"); statementWithSeparator = new StatementWithSeparator(astNode, null); importStatement = (ImportName) treeMaker.importStatement(statementWithSeparator); assertThat(importStatement).isNotNull(); assertThat(importStatement.importKeyword().value()).isEqualTo("import"); assertThat(importStatement.modules()).hasSize(1); importedName1 = importStatement.modules().get(0); assertThat(importedName1.dottedName().names()).hasSize(2); assertThat(importedName1.dottedName().names().get(0).name()).isEqualTo("foo"); assertThat(importedName1.dottedName().names().get(1).name()).isEqualTo("bar"); assertThat(importStatement.children()).hasSize(2); astNode = p.parse("import foo, bar"); statementWithSeparator = new StatementWithSeparator(astNode, null); importStatement = (ImportName) treeMaker.importStatement(statementWithSeparator); assertThat(importStatement).isNotNull(); assertThat(importStatement.importKeyword().value()).isEqualTo("import"); assertThat(importStatement.modules()).hasSize(2); importedName1 = importStatement.modules().get(0); assertThat(importedName1.dottedName().names()).hasSize(1); assertThat(importedName1.dottedName().names().get(0).name()).isEqualTo("foo"); AliasedName importedName2 = importStatement.modules().get(1); assertThat(importedName2.dottedName().names()).hasSize(1); assertThat(importedName2.dottedName().names().get(0).name()).isEqualTo("bar"); assertThat(importStatement.children()).hasSize(3); }