package org.spoofax.interpreter.library.ssl;

import io.usethesource.capsule.Set;

import org.spoofax.interpreter.core.IContext;
import org.spoofax.interpreter.library.AbstractPrimitive;
import org.spoofax.interpreter.stratego.Strategy;
import org.spoofax.interpreter.terms.IStrategoTerm;

public class SSL_immutable_relation_values_set extends AbstractPrimitive {

    protected SSL_immutable_relation_values_set() {
        super("SSL_immutable_relation_values", 0, 0);
    }

    @Override
    public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) {
        if(!(env.current() instanceof StrategoImmutableRelation)) {
            return false;
        }

        final StrategoImmutableRelation map = (StrategoImmutableRelation) env.current();
        final Set.Transient<IStrategoTerm> result = Set.Transient.of();
        for(IStrategoTerm value : map.backingRelation.inverse().keySet()) {
            result.__insert(value);
        }

        env.setCurrent(new StrategoImmutableSet(result.freeze()));
        return true;
    }
}

@@ -455,16 +455,20 @@
 n_values
+_set
 %22, 0, 0)
@@ -849,34 +849,27 @@
     
-for(IStrategoTerm value : 
+result.__insertAll(
 map.
@@ -907,56 +907,9 @@
 t())
- %7B%0A            result.__insert(value);%0A        %7D
+;
 %0A%0A  

Fix bug where two primitives use the same name