|
| 1 | +package jp.kusumotolab.kgenprog.project.jdt; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import java.nio.file.Paths; |
| 5 | +import java.util.List; |
| 6 | +import org.eclipse.jdt.core.dom.ASTNode; |
| 7 | +import org.eclipse.jdt.core.dom.Block; |
| 8 | +import org.junit.Test; |
| 9 | +import jp.kusumotolab.kgenprog.project.ProductSourcePath; |
| 10 | + |
| 11 | +public class StatementAndConditionVisitorTest { |
| 12 | + |
| 13 | + private static final String FILE_NAME_FOR = "For.java"; |
| 14 | + private static final String SOURCE_FOR = new StringBuilder() |
| 15 | + // Line breaks must be included to execute GeneratedJDTAST#inferLocation. |
| 16 | + .append("public class For {\n") |
| 17 | + .append(" public int method() {\n") |
| 18 | + .append(" for (int i = 0; ; i++) {\n") |
| 19 | + .append(" if(i == 10) {\n") |
| 20 | + .append(" break;\n") |
| 21 | + .append(" }\n") |
| 22 | + .append(" }\n") |
| 23 | + .append(" return i;\n") |
| 24 | + .append(" }\n") |
| 25 | + .append("}\n") |
| 26 | + .toString(); |
| 27 | + |
| 28 | + @Test |
| 29 | + public void test_consumeStatement01() { |
| 30 | + |
| 31 | + // generating an AST |
| 32 | + // ASTを作成 |
| 33 | + final ProductSourcePath productSourcePath = |
| 34 | + new ProductSourcePath(Paths.get("."), Paths.get(FILE_NAME_FOR)); |
| 35 | + final JDTASTConstruction constructor = new JDTASTConstruction(); |
| 36 | + final GeneratedJDTAST<ProductSourcePath> ast = constructor.constructAST( |
| 37 | + productSourcePath, SOURCE_FOR); |
| 38 | + |
| 39 | + // assuming that any instance of Block is not included in statements |
| 40 | + // Blockが含まれていないはず |
| 41 | + final StatementAndConditionVisitor visitor = new StatementAndConditionVisitor(); |
| 42 | + visitor.analyzeElements(ast.getRoot()); |
| 43 | + final List<ASTNode> statements = visitor.getElements(); |
| 44 | + assertThat(statements).noneMatch(s -> Block.class == s.getClass()); |
| 45 | + } |
| 46 | +} |
| 47 | + |
0 commit comments