collectPOTBlocks function

List<POTBlock> collectPOTBlocks (List<Statement> statements)

Pump all Statement into a single list

Implementation

List<POTBlock> collectPOTBlocks(final List<Statement> statements) {
    final List<POTBlock> blocks = new List<POTBlock>();

    for(int index = 0;index < statements.length;index++) {
        final Statement statement = statements[index];

        List<CommentStatement> _getComments() {
            final List<CommentStatement> comments = new List<CommentStatement>();
            if((statements[index - 1] is CommentStatement)) {
                comments.add(statements[ index - 1]);
            } else if(index > 1 && statements[index - 1] is NewLineStatement
                && statements[index - 2] is CommentStatement){
                comments.add(statements[ index - 2]);
            }
            return comments;
        }

        if(statement is L10NStatement) {
            final List<CommentStatement> comments = _getComments();
            blocks.add(new POTBlock(comments, statement));
        }
    }

    return blocks;
}