package org.spoofax.jsglr2.layoutsensitive;

import java.util.List;

import org.spoofax.jsglr2.parseforest.basic.IBasicDerivation;
import org.spoofax.jsglr2.parser.Position;

import com.google.common.collect.Lists;

public interface ILayoutSensitiveDerivation
//@formatter:off
   <ParseForest extends ILayoutSensitiveParseForest>
//@formatter:on
    extends IBasicDerivation<ParseForest> {

    Position getStartPosition();

    Position getEndPosition();

    Position getLeftPosition();

    Position getRightPosition();

    default List<PositionInterval> getLongestMatchPositions() {
        List<PositionInterval> result = Lists.newArrayList();
        if(production().isLongestMatch()) {
            result.add(new PositionInterval(getStartPosition(), getEndPosition()));
        }
        for(ParseForest pf : parseForests()) {
            if(pf instanceof ILayoutSensitiveDerivation) {
                result.addAll(((ILayoutSensitiveDerivation<ParseForest>) pf).getLongestMatchPositions());
            } else if(pf instanceof ILayoutSensitiveParseNode) {
                List<PositionInterval> positions =
                    ((ILayoutSensitiveParseNode<ParseForest, ILayoutSensitiveDerivation<ParseForest>>) pf)
                        .getLongestMatchPositions();

                result.addAll(positions);
            }
        }
        return result;
    }

}

@@ -873,26 +873,25 @@
 ensitive
-Derivation
+ParseNode
 ) %7B%0A    
@@ -920,220 +920,8 @@
 All(
-((ILayoutSensitiveDerivation%3CParseForest%3E) pf).getLongestMatchPositions());%0A            %7D else if(pf instanceof ILayoutSensitiveParseNode) %7B%0A                List%3CPositionInterval%3E positions =%0A                    
 ((IL
@@ -1023,20 +1023,16 @@
         
-    
 .getLong
@@ -1054,50 +1054,8 @@
 ns()
-;%0A%0A                result.addAll(positions
 );%0A 

Simplify ILayoutSensitiveDerivation.getLongestMatchPositions