package mb.nabl2.terms.stratego;

import java.io.IOException;
import java.util.Iterator;
import java.util.Optional;

import org.spoofax.interpreter.terms.IStrategoList;
import org.spoofax.interpreter.terms.IStrategoTerm;
import org.spoofax.interpreter.terms.ITermPrinter;
import org.spoofax.terms.AbstractSimpleTerm;
import org.spoofax.terms.AbstractTermFactory;
import org.spoofax.terms.util.EmptyIterator;

public class StrategoBlob extends AbstractSimpleTerm implements IStrategoTerm {
    private static final long serialVersionUID = 1L;

    private final Object value;

    public StrategoBlob(Object obj) {
        this.value = obj;
    }

    public Object value() {
        return value;
    }
    
    // IStrategoTerm implementation

    @Override public boolean isList() {
        return false;
    }

    @Override public Iterator<IStrategoTerm> iterator() {
        return new EmptyIterator<>();
    }

    @Override public int getSubtermCount() {
        return 0;
    }

    @Override public IStrategoTerm getSubterm(int index) {
        throw new IndexOutOfBoundsException();
    }

    @Override public IStrategoTerm[] getAllSubterms() {
        return new IStrategoTerm[0];
    }

    @Override public int getTermType() {
        return IStrategoTerm.BLOB;
    }

    @SuppressWarnings("deprecation") @Override public IStrategoList getAnnotations() {
        return AbstractTermFactory.EMPTY_LIST;
    }

    @Override public boolean match(IStrategoTerm second) {
        return false;
    }

    @Override public void prettyPrint(ITermPrinter pp) {
        pp.print(toString());
    }

    @Override public String toString(int maxDepth) {
        return toString();
    }

    @Override public void writeAsString(Appendable output, int maxDepth) throws IOException {
        output.append(toString());
    }

    @Override public String toString() {
        return value.getClass().getSimpleName();
    }

    @SuppressWarnings("unchecked") public static <T> Optional<T> match(IStrategoTerm term, Class<T> blobClass) {
        if(term instanceof StrategoBlob) {
            StrategoBlob blob = (StrategoBlob) term;
            if(blobClass.isInstance(blob.value)) {
                return Optional.of((T) blob.value);
            } else {
                return Optional.empty();
            }
        } else {
            return Optional.empty();
        }
    }
    
}
@@ -72,24 +72,77 @@
 va.util.
-Iterator
+Collections;%0Aimport java.util.Iterator;%0Aimport java.util.List
 ;%0Aimport
@@ -1238,32 +1238,140 @@
 Term%5B0%5D;%0A    %7D%0A%0A
+    @Override%0A    public List%3CIStrategoTerm%3E getSubterms() %7B%0A        return Collections.emptyList();%0A    %7D%0A%0A
     @Override pu

Add IStrategoTerm.getSubterms() that returns a list