| 27 | import org.dynjs.runtime.Types; |
| 28 | |
| 29 | public class BlockStatement extends AbstractStatement { |
| 30 | |
| 31 | private final List<Statement> blockContent; |
| 32 | private List<FunctionDeclaration> functionDeclarations = null; |
| 33 | private List<VariableDeclaration> variableDeclarations = null; |
| 34 | |
| 35 | public BlockStatement(final List<Statement> blockContent) { |
| 36 | this.blockContent = blockContent; |
| 37 | } |
| 38 | |
| 39 | public Position getPosition() { |
| 40 | if ( blockContent.isEmpty() ) { |
| 41 | return null; |
| 42 | } |
| 43 | |
| 44 | return blockContent.get(0).getPosition(); |
| 45 | } |
| 46 | |
| 47 | public List<Statement> getBlockContent() { |
| 48 | return this.blockContent; |
| 49 | } |
| 50 | |
| 51 | public List<BlockStatement> getAsChunks(int chunkSize) { |
| 52 | if (this.blockContent.size() <= chunkSize) { |
| 53 | return Collections.singletonList(this); |
| 54 | } |
| 55 | |
| 56 | List<BlockStatement> chunks = new ArrayList<>(); |
| 57 | |
| 58 | int chunkStart = 0; |
| 59 | int totalStatements = this.blockContent.size(); |
| 60 | |
| 61 | while (chunkStart < totalStatements) { |
| 62 | int chunkEnd = chunkStart + chunkSize; |
| 63 | if (chunkEnd > totalStatements) { |
| 64 | chunkEnd = totalStatements; |
| 65 | } |
| 66 | |
| 67 | chunks.add(new BlockStatement(this.blockContent.subList(chunkStart, chunkEnd))); |
| 68 | |
| 69 | chunkStart = chunkEnd; |
| 70 | } |
| 71 | |
| 72 | return chunks; |
| 73 | } |
| 74 | |
| 75 | public List<FunctionDeclaration> getFunctionDeclarations() { |
| 76 | if (this.functionDeclarations != null) { |
| 77 | return this.functionDeclarations; |
| 78 | } |
| 79 | |
| 80 | if (this.blockContent == null) { |
| 81 | return Collections.emptyList(); |
| 82 | } |
| 83 | |
| 84 | List<FunctionDeclaration> decls = new ArrayList<>(); |
| 85 | |
| 86 | for (Statement each : this.blockContent) { |
nothing calls this directly
no outgoing calls
no test coverage detected