Search in sources :

Example 1 with Namespace

use of clojure.lang.Namespace in project invesdwin-context by invesdwin.

the class ClojureBindings method map.

private Map<String, Object> map() {
    final Map<String, Object> map = new HashMap<String, Object>();
    final Namespace ns = Namespace.find(namespaceIntern);
    for (final Object el : ns.getMappings()) {
        final MapEntry entry = (MapEntry) el;
        final Symbol key = (Symbol) entry.key();
        final Object valAt = ns.getMappings().valAt(key);
        final Var valVar = valAt instanceof Var ? ((Var) valAt) : null;
        if (valVar == null) {
            // skip non-variables
            continue;
        }
        if (valVar.ns != ns) {
            // skip non-user vars
            continue;
        }
        if (!valVar.isBound()) {
            // skip unbound vars
            continue;
        }
        map.put(key.getName(), valVar.get());
    }
    return map;
}
Also used : MapEntry(clojure.lang.MapEntry) HashMap(java.util.HashMap) Symbol(clojure.lang.Symbol) Var(clojure.lang.Var) Namespace(clojure.lang.Namespace)

Example 2 with Namespace

use of clojure.lang.Namespace in project invesdwin-context by invesdwin.

the class ClojureBindings method clear.

@Override
public void clear() {
    final Symbol nsSymbol = namespaceIntern;
    final Namespace ns = Namespace.find(nsSymbol);
    for (final Object el : ns.getMappings()) {
        final MapEntry entry = (MapEntry) el;
        final Symbol key = (Symbol) entry.key();
        final Object valAt = ns.getMappings().valAt(key);
        final Var valVar = valAt instanceof Var ? ((Var) valAt) : null;
        if (valVar == null) {
            // skip non-variables
            continue;
        }
        if (valVar.ns != ns) {
            // skip non-user vars
            continue;
        }
        if (!valVar.isBound()) {
            // skip unbound vars
            continue;
        }
        RT.var(CORE_NS, "ns-unmap").invoke(nsSymbol, key);
    }
}
Also used : MapEntry(clojure.lang.MapEntry) Symbol(clojure.lang.Symbol) Var(clojure.lang.Var) Namespace(clojure.lang.Namespace)

Aggregations

MapEntry (clojure.lang.MapEntry)2 Namespace (clojure.lang.Namespace)2 Symbol (clojure.lang.Symbol)2 Var (clojure.lang.Var)2 HashMap (java.util.HashMap)1