Package com.offbytwo.iclojure.completion

Source Code of com.offbytwo.iclojure.completion.ClojureCompletionWrapper

package com.offbytwo.iclojure.completion;

import clojure.lang.LazySeq;
import clojure.lang.RT;
import clojure.lang.Var;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;

public class ClojureCompletionWrapper {
    private Var completions;

    public ClojureCompletionWrapper() {
        try {
            RT.load("complete");
        } catch (IOException e) {
            throw new RuntimeException("Error: Unable to load complete.clj", e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Error: Unable to load complete.clj", e);
        }
        this.completions = RT.var("complete", "completions");
    }

    public List<String> getCompletionsForString(String toComplete) {
        List<String> returnThis = new ArrayList<String>();

        LazySeq results = (LazySeq) completions.invoke(toComplete);
        for (Object result : asList(results.toArray())) {
            returnThis.add((String) result);
        }

        return returnThis;
    }
}
TOP

Related Classes of com.offbytwo.iclojure.completion.ClojureCompletionWrapper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.