// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/node/SpockBlockNode.java
// public final class SpockBlockNode {
// 
//     private final String block;
// 
//     private SpockBlockNode(String block) {
//         this.block = block;
//     }
// 
//     public static SpockBlockNode given() {
//         return new SpockBlockNode("given");
//     }
// 
//     public static SpockBlockNode when() {
//         return new SpockBlockNode("when");
//     }
// 
//     public static SpockBlockNode then() {
//         return new SpockBlockNode("then");
//     }
// 
//     public static SpockBlockNode expect() {
//         return new SpockBlockNode("expect");
//     }
// 
//     @Override
//     public String toString() {
//         return format("%s:", block);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) {
//             return true;
//         }
//         if (o == null || getClass() != o.getClass()) {
//             return false;
//         }
//         SpockBlockNode that = (SpockBlockNode) o;
//         return Objects.equals(block, that.block);
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(block);
//     }
// }
// 
// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/node/SpockBlockNode.java
// public static SpockBlockNode given() {
//     return new SpockBlockNode("given");
// }
// 
// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/node/SpockBlockNode.java
// public static SpockBlockNode then() {
//     return new SpockBlockNode("then");
// }
// 
// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/node/SpockBlockNode.java
// public static SpockBlockNode when() {
//     return new SpockBlockNode("when");
// }
// 
// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/util/AstNodeFinder.java
// public static Optional<MethodInvocation> methodInvocation(Object bodyElement, String... methodNames) {
//     return stream(methodNames)
//             .map(methodName -> methodInvocation(bodyElement, methodName))
//             .filter(Optional::isPresent)
//             .map(Optional::get)
//             .findFirst();
// }


import com.github.opaluchlukasz.junit2spock.core.node.SpockBlockNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import static com.github.opaluchlukasz.junit2spock.core.node.SpockBlockNode.given;
import static com.github.opaluchlukasz.junit2spock.core.node.SpockBlockNode.then;
import static com.github.opaluchlukasz.junit2spock.core.node.SpockBlockNode.when;
import static com.github.opaluchlukasz.junit2spock.core.util.AstNodeFinder.methodInvocation;
import static java.lang.String.format;
import static java.util.Collections.reverseOrder;
package com.github.opaluchlukasz.junit2spock.core.model.method;




public class CommentBasedSpockBlocksStrategy implements SpockBlockApplier {

    private static final Logger LOG = LoggerFactory.getLogger(CommentBasedSpockBlocksStrategy.class);

    static final String GIVEN_BLOCK_START_MARKER_METHOD = "givenBlockStart";
    static final String WHEN_BLOCK_START_MARKER_METHOD = "whenBlockStart";
    static final String THEN_BLOCK_START_MARKER_METHOD = "thenBlockStart";

    private final List<Object> body;
    private final String methodName;

    public CommentBasedSpockBlocksStrategy(List<Object> body, String methodName) {
        this.body = body;
        this.methodName = methodName;
    }

    @Override
    public boolean apply() {
        List<Integer> givenIndexes = markerMethod(GIVEN_BLOCK_START_MARKER_METHOD);
        List<Integer> whenIndexes = markerMethod(WHEN_BLOCK_START_MARKER_METHOD);
        List<Integer> thenIndexes = markerMethod(THEN_BLOCK_START_MARKER_METHOD);

        Map<Integer, SpockBlockNode> blocksToBeAdded = new HashMap<>();
// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/node/SpockBlockNode.java
// public final class SpockBlockNode {
// 
//     private final String block;
// 
//     private SpockBlockNode(String block) {
//         this.block = block;
//     }
// 
//     public static SpockBlockNode given() {
//         return new SpockBlockNode("given");
//     }
// 
//     public static SpockBlockNode when() {
//         return new SpockBlockNode("when");
//     }
// 
//     public static SpockBlockNode then() {
//         return new SpockBlockNode("then");
//     }
// 
//     public static SpockBlockNode expect() {
//         return new SpockBlockNode("expect");
//     }
// 
//     @Override
//     public String toString() {
//         return format("%s:", block);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) {
//             return true;
//         }
//         if (o == null || getClass() != o.getClass()) {
//             return false;
//         }
//         SpockBlockNode that = (SpockBlockNode) o;
//         return Objects.equals(block, that.block);
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(block);
//     }
// }
// 
// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/node/SpockBlockNode.java
// public static SpockBlockNode given() {
//     return new SpockBlockNode("given");
// }
// 
// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/node/SpockBlockNode.java
// public static SpockBlockNode then() {
//     return new SpockBlockNode("then");
// }
// 
// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/node/SpockBlockNode.java
// public static SpockBlockNode when() {
//     return new SpockBlockNode("when");
// }
// 
// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/util/AstNodeFinder.java
// public static Optional<MethodInvocation> methodInvocation(Object bodyElement, String... methodNames) {
//     return stream(methodNames)
//             .map(methodName -> methodInvocation(bodyElement, methodName))
//             .filter(Optional::isPresent)
//             .map(Optional::get)
//             .findFirst();
// }


// Path: src/main/java/com/github/opaluchlukasz/junit2spock/core/model/method/CommentBasedSpockBlocksStrategy.java
import com.github.opaluchlukasz.junit2spock.core.node.SpockBlockNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import static com.github.opaluchlukasz.junit2spock.core.node.SpockBlockNode.given;
import static com.github.opaluchlukasz.junit2spock.core.node.SpockBlockNode.then;
import static com.github.opaluchlukasz.junit2spock.core.node.SpockBlockNode.when;
import static com.github.opaluchlukasz.junit2spock.core.util.AstNodeFinder.methodInvocation;
import static java.lang.String.format;
import static java.util.Collections.reverseOrder;

package com.github.opaluchlukasz.junit2spock.core.model.method;




public class CommentBasedSpockBlocksStrategy implements SpockBlockApplier {

    private static final Logger LOG = LoggerFactory.getLogger(CommentBasedSpockBlocksStrategy.class);

    static final String GIVEN_BLOCK_START_MARKER_METHOD = "givenBlockStart";
    static final String WHEN_BLOCK_START_MARKER_METHOD = "whenBlockStart";
    static final String THEN_BLOCK_START_MARKER_METHOD = "thenBlockStart";

    private final List<Object> body;
    private final String methodName;

    public CommentBasedSpockBlocksStrategy(List<Object> body, String methodName) {
        this.body = body;
        this.methodName = methodName;
    }

    @Override
    public boolean apply() {
        List<Integer> givenIndexes = markerMethod(GIVEN_BLOCK_START_MARKER_METHOD);
        List<Integer> whenIndexes = markerMethod(WHEN_BLOCK_START_MARKER_METHOD);
        List<Integer> thenIndexes = markerMethod(THEN_BLOCK_START_MARKER_METHOD);

        Map<Integer, SpockBlockNode> blocksToBeAdded = new HashMap<>();
        if (givenIndexes.size() > 0) {