@@ -0,0 +1,1706 @@
+package mb.shared.namegraph;%0A%0Aimport java.util.List;%0Aimport java.util.Optional;%0Aimport java.util.Set;%0Aimport java.util.stream.Collectors;%0A%0Aimport org.spoofax.interpreter.core.IContext;%0Aimport org.spoofax.interpreter.core.InterpreterException;%0Aimport org.spoofax.interpreter.library.AbstractPrimitive;%0Aimport org.spoofax.interpreter.terms.IStrategoList;%0Aimport org.spoofax.interpreter.terms.IStrategoTerm;%0Aimport org.spoofax.interpreter.terms.ITermFactory;%0Aimport org.spoofax.terms.util.TermUtils;%0A%0Apublic class FindAllRelatedOccurrencesPrimitive extends AbstractPrimitive %7B%0A%0A    private final static String NAME = %22FindAllRelatedOccurrences%22;%0A%0A    public FindAllRelatedOccurrencesPrimitive() %7B%0A        super(NAME, 0, 0);%0A    %7D%0A%0A    @Override%0A    public boolean call(IContext env, org.spoofax.interpreter.stratego.Strategy%5B%5D svars, IStrategoTerm%5B%5D tvars)%0A            throws InterpreterException %7B%0A        return call(env.current(), env.getFactory()).map(t -%3E %7B%0A            env.setCurrent(t);%0A            return true;%0A        %7D).orElse(false);%0A    %7D%0A%0A    private Optional%3C? extends IStrategoTerm%3E call(IStrategoTerm current, ITermFactory factory)%0A            throws InterpreterException %7B%0A        NameIndex selectedOccurrence = new NameIndex(current.getSubterm(0));%0A        List%3CIStrategoTerm%3E resolutionRelation = TermUtils.toJavaList(current.getSubterm(1));%0A        NameGraph nameGraph = new NameGraph(resolutionRelation);%0A%0A        Set%3CNameIndex%3E cluster = nameGraph.find(selectedOccurrence).get();%0A        IStrategoList targetIndices = factory%0A                .makeList(cluster.stream().map(term -%3E term.getTermIndex()).collect(Collectors.toList()));%0A%0A        return Optional.of(targetIndices);%0A%0A    %7D%0A%0A%7D%0A

Implement primitive