Example #1
0
/** @author Denis Lebedev */
class FGModule extends FGAbstractModule {
  // static final String GET_CONTAINER_FN_NAME = "get-container";
  private static final Var evolverFn_ =
      clojure.lang.RT.var(FG_CORE_NAMESPACE, "app-evolve-container");
  private static final Var getContainerFn_ =
      clojure.lang.RT.var(FG_CORE_NAMESPACE, "get-container");

  public FGModule(String containerName) {
    super(containerName);
  }

  @Override
  public Object getContainer() {
    return getContainer(containerName_);
  }

  @Override
  public void evolve(List<Keyword> targetCellIds, Object inputEvent) {
    evolverFn_.invoke(containerName_, targetCellIds, inputEvent);
  }

  public static Object getContainer(String containerName) {
    return getContainerFn_.invoke(containerName);
  }
}
 public void onCreate(android.os.Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   RT.var("clojure.core", "require").invoke(Symbol.intern("hello-world.core"));
   try {
     Game game = (Game) RT.var("hello-world.core", "hello-world").deref();
     initialize(game);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #3
0
 public static void snuser_clearkb(Boolean clearall) {
   if (snuser_clearkb_fn == null) snuser_clearkb_fn = RT.var("csneps.core.snuser", "clearkb");
   try {
     snuser_clearkb_fn.invoke(clearall);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #4
0
 public static void build_unassert(IPersistentMap term) {
   if (build_unassert_fn == null) build_unassert_fn = RT.var("csneps.core.build", "unassert");
   try {
     build_unassert_fn.invoke(term);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #5
0
 public static IFn loadClojureFn(String namespace, String name) {
   try {
     clojure.lang.Compiler.eval(RT.readString("(require '" + namespace + ")"));
   } catch (Exception e) {
     // if playing from the repl and defining functions, file won't exist
   }
   return (IFn) RT.var(namespace, name).deref();
 }
Example #6
0
 public static void csneps_core_define_type(Symbol newtype, IPersistentList parents) {
   if (csneps_define_type_fn == null) csneps_define_type_fn = RT.var("csneps.core", "define-type");
   try {
     csneps_define_type_fn.invoke(newtype, parents);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #7
0
 public static IPersistentSet contexts_hyps(IPersistentMap context) {
   if (contexts_hyps_fn == null) contexts_hyps_fn = RT.var("csneps.core.contexts", "hyps");
   try {
     return (IPersistentSet) contexts_hyps_fn.invoke(context);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #8
0
 public static IPersistentMap snuser_assert(PersistentList expr) {
   if (snuser_assert_fn == null) snuser_assert_fn = RT.var("csneps.core.snuser", "assert");
   try {
     return (IPersistentMap) snuser_assert_fn.invoke(expr);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #9
0
 public static void contexts_set_current_context(IPersistentMap context) {
   if (contexts_set_current_context_fn == null)
     contexts_set_current_context_fn = RT.var("csneps.core.contexts", "setCurrentContext");
   try {
     contexts_set_current_context_fn.invoke(context);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #10
0
 public static void build_add_to_context(IPersistentMap context, IPersistentMap term) {
   if (build_add_to_context_fn == null)
     build_add_to_context_fn = RT.var("csneps.core.build", "add-to-context");
   try {
     build_add_to_context_fn.invoke(term, context);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #11
0
 public static ISeq build_find(ISeq pattern) {
   if (build_find_fn == null) build_find_fn = RT.var("csneps.core.build", "find");
   try {
     return (ISeq) build_find_fn.invoke(pattern);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #12
0
 public static void csneps_printer_print_kb_to_text_file(String fname, String header) {
   if (csneps_print_print_kb_to_text_file_fn == null)
     csneps_print_print_kb_to_text_file_fn = RT.var("csneps.core.printer", "writeKBToTextFile");
   try {
     csneps_print_print_kb_to_text_file_fn.invoke(fname, header);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #13
0
 public static IPersistentMap snuser_define_term(PersistentList expr, Keyword type) {
   if (snuser_define_term_fn == null)
     snuser_define_term_fn = RT.var("csneps.core.snuser", "defineTerm");
   try {
     return (IPersistentMap) snuser_define_term_fn.invoke(expr, type);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #14
0
 public static IPersistentMap snuser_define_caseframe(Keyword type, IPersistentList slots) {
   if (snuser_define_caseframe_fn == null)
     snuser_define_caseframe_fn = RT.var("csneps.core.snuser", "defineCaseframe");
   try {
     return (IPersistentMap) snuser_define_caseframe_fn.invoke(type, slots);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #15
0
 public static String build_term_predicate(IPersistentMap term) {
   if (build_term_predicate_fn == null)
     build_term_predicate_fn = RT.var("csneps.core.build", "term-predicate");
   try {
     return build_term_predicate_fn.invoke(term).toString();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #16
0
 public static String csneps_core_printer_term_printer(IPersistentMap term) {
   if (csneps_core_printer_term_printer_fn == null)
     csneps_core_printer_term_printer_fn = RT.var("csneps.core.printer", "term-printer");
   try {
     return csneps_core_printer_term_printer_fn.invoke(term).toString();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #17
0
 public static Boolean csneps_core_variable_term_qmark(IPersistentMap term) {
   if (csneps_core_variable_term_qmark_fn == null)
     csneps_core_variable_term_qmark_fn = RT.var("csneps.core", "variableTerm?");
   try {
     return (Boolean) csneps_core_variable_term_qmark_fn.invoke(term);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #18
0
 public static Boolean caseframes_quotedpp_qmark(IPersistentMap cf) {
   if (caseframes_quotedpp_qmark_fn == null)
     caseframes_quotedpp_qmark_fn = RT.var("csneps.core.caseframes", "quotedpp?");
   try {
     return (Boolean) caseframes_quotedpp_qmark_fn.invoke(cf);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #19
0
 public static String caseframes_caseframe_name(IPersistentMap cf) {
   if (caseframes_caseframe_name_fn == null)
     caseframes_caseframe_name_fn = RT.var("csneps.core.caseframes", "caseframe-name");
   try {
     return caseframes_caseframe_name_fn.invoke(cf).toString();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #20
0
 public static IPersistentMap contexts_asserted_qmark(
     IPersistentMap term, IPersistentMap context) {
   if (contexts_asserted_qmark_fn == null)
     contexts_asserted_qmark_fn = RT.var("csneps.core.contexts", "asserted?");
   try {
     return (IPersistentMap) contexts_asserted_qmark_fn.invoke(term, context);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
 /**
  * Gets default instance. Do not use directly: reserved for *.settings files only, i.e.
  * deserialization routines; otherwise you could get a non-deserialized instance. To obtain the
  * singleton instance, use {@link #findInstance}.
  */
 public static synchronized ReplTopComponent getDefault() {
   if (instance == null) {
     try {
       Var getIdeReplFn = RT.var("org.enclojure.ide.nb.editor.repl-win", "create-ide-repl");
       return (ReplTopComponent) getIdeReplFn.invoke(IDE_REPL);
     } catch (Exception ex) {
       Exceptions.printStackTrace(ex);
     }
   }
   return instance;
 }
Example #22
0
 public static IPersistentMap contexts_define_context(
     Symbol name, IPersistentList parents, IPersistentSet hyps) {
   if (contexts_define_context_fn == null)
     contexts_define_context_fn = RT.var("csneps.core.contexts", "defineContext");
   try {
     return (IPersistentMap)
         contexts_define_context_fn.invoke(
             name, Keyword.intern("parents"), parents, Keyword.intern("hyps"), hyps);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
  public ClojureGamer() {
    super();

    try {
      // Load the Clojure script -- as a side effect this initializes the runtime.
      RT.loadResourceScript(getClojureGamerFile() + ".clj");

      // Get a reference to the gamer-generating function.
      Var gamerVar = RT.var("gamer_namespace", getClojureGamerName());

      // Call it!
      theClojureGamer = (Gamer) gamerVar.invoke();
    } catch (Exception e) {
      GamerLogger.logError("GamePlayer", "Caught exception in Clojure initialization:");
      GamerLogger.logStackTrace("GamePlayer", e);
    }
  }
public final class UseFileNSInReplAction extends CookieAction {

  final Var loadNamespaceFn =
      RT.var("org.enclojure.ide.nb.actions.action-handler", "require-file-ns-action");

  protected void performAction(Node[] activatedNodes) {
    try {
      RT.load("org/enclojure/ide/nb/actions/action_handler");
      loadNamespaceFn.invoke(activatedNodes);
    } catch (Exception ex) {
      Exceptions.printStackTrace(ex);
    }
  }

  protected int mode() {
    return CookieAction.MODE_EXACTLY_ONE;
  }

  public String getName() {
    return NbBundle.getMessage(ChangeReplNamespaceAction.class, "CTL_UseFileNSInReplAction");
  }

  protected Class[] cookieClasses() {
    return new Class[] {EditorCookie.class};
  }

  @Override
  protected void initialize() {
    super.initialize();
    // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
    putValue("noIconInMenu", Boolean.TRUE);
  }

  public HelpCtx getHelpCtx() {
    return HelpCtx.DEFAULT_HELP;
  }

  @Override
  protected boolean asynchronous() {
    return false;
  }
}
Example #25
0
 public static IPersistentMap relations_define_slot(
     Symbol name, Keyword type, Integer min, Integer max, Symbol posadjust, Symbol negadjust) {
   if (relations_define_slot_fn == null)
     relations_define_slot_fn = RT.var("csneps.core.relations", "define-slot");
   try {
     return (IPersistentMap)
         relations_define_slot_fn.invoke(
             name,
             Keyword.intern("type"),
             type,
             Keyword.intern("min"),
             min,
             Keyword.intern("max"),
             max,
             Keyword.intern("posadjust"),
             posadjust,
             Keyword.intern("negadjust"),
             negadjust);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
/** @author magrawal */
public class CreateStandaloneReplDialog extends javax.swing.JDialog {

  static final Var nonProjectRepl =
      RT.var("org.enclojure.ide.nb.editor.repl-win", "start-stand-alone-repl-action");
  static final Var saveSettings = RT.var("org.enclojure.ide.settings.utils", "put-prefs");
  static final Var loadSettings = RT.var("org.enclojure.ide.settings.utils", "get-prefs");

  static final String ns_settings = "org.enclojure.ide.preferences.enclojure-options-category";
  /** Creates new form ClojureReplDialog */
  public CreateStandaloneReplDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();

    try {
      this.classPath.setText((String) loadSettings.invoke(ns_settings));
    } catch (Exception ex) {
      Exceptions.printStackTrace(ex);
    }

    errorLabel.setVisible(false);
    this.setLocationRelativeTo(null);
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    javaArgs = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    classPath = new javax.swing.JTextField();
    connectButton = new javax.swing.JButton();
    cancelButton = new javax.swing.JButton();
    errorLabel = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    replName = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    javaArgs.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class,
            "CreateStandaloneReplDialog.javaArgs.text")); // NOI18N
    javaArgs.setEnabled(false);

    jLabel1.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class, "CreateStandaloneReplDialog.jLabel1.text")); // NOI18N
    jLabel1.setEnabled(false);

    jLabel2.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class, "CreateStandaloneReplDialog.jLabel2.text")); // NOI18N

    classPath.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class,
            "CreateStandaloneReplDialog.classPath.text")); // NOI18N

    connectButton.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class,
            "CreateStandaloneReplDialog.connectButton.text")); // NOI18N
    connectButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            connectButtonActionPerformed(evt);
          }
        });

    cancelButton.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class,
            "CreateStandaloneReplDialog.cancelButton.text")); // NOI18N
    cancelButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            cancelButtonActionPerformed(evt);
          }
        });

    errorLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13));
    errorLabel.setForeground(new java.awt.Color(255, 0, 0));
    errorLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    errorLabel.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class,
            "CreateStandaloneReplDialog.errorLabel.text")); // NOI18N

    jLabel3.setFont(new java.awt.Font("Lucida Grande", 1, 13));
    jLabel3.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class, "CreateStandaloneReplDialog.jLabel3.text")); // NOI18N

    jLabel4.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class, "CreateStandaloneReplDialog.jLabel4.text")); // NOI18N

    replName.setText(
        org.openide.util.NbBundle.getMessage(
            CreateStandaloneReplDialog.class,
            "CreateStandaloneReplDialog.replName.text")); // NOI18N

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(
                                jLabel3,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addGroup(
                                javax.swing.GroupLayout.Alignment.LEADING,
                                layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(
                                                layout
                                                    .createSequentialGroup()
                                                    .addGroup(
                                                        layout
                                                            .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment
                                                                    .LEADING)
                                                            .addComponent(jLabel1)
                                                            .addComponent(jLabel4)
                                                            .addComponent(jLabel2))
                                                    .addGap(50, 50, 50))
                                            .addGroup(
                                                layout
                                                    .createSequentialGroup()
                                                    .addComponent(connectButton)
                                                    .addGap(18, 18, 18)))
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(
                                                replName,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                630,
                                                Short.MAX_VALUE)
                                            .addComponent(
                                                javaArgs,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                630,
                                                Short.MAX_VALUE)
                                            .addComponent(
                                                classPath,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                630,
                                                Short.MAX_VALUE)
                                            .addGroup(
                                                layout
                                                    .createSequentialGroup()
                                                    .addComponent(
                                                        cancelButton,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        Short.MAX_VALUE)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .RELATED)
                                                    .addComponent(
                                                        errorLabel,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        535,
                                                        Short.MAX_VALUE)))))
                    .addContainerGap()));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap(20, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(
                                replName,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                    .addGap(5, 5, 5)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(
                                javaArgs,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addGap(18, 18, 18)
                                    .addComponent(connectButton))
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(
                                        classPath,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(
                                                errorLabel,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                27,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(cancelButton))))
                    .addGap(91, 91, 91)));

    pack();
  } // </editor-fold>//GEN-END:initComponents

  private void connectButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_connectButtonActionPerformed
    try {
      // Connect - if failed to connet - display red error on the dalog box
      nonProjectRepl.invoke(
          this.replName.getText(), this.javaArgs.getText(), this.classPath.getText());
      this.dispose();
    } catch (Exception ex) {
      this.errorLabel.setText(ex.getMessage());
      this.errorLabel.setVisible(true);
    }

    try {
      saveSettings.invoke(this.classPath.getText());
    } catch (Exception ex) {
      Exceptions.printStackTrace(ex);
    }
  } // GEN-LAST:event_connectButtonActionPerformed

  private void cancelButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_cancelButtonActionPerformed
    this.dispose();
  } // GEN-LAST:event_cancelButtonActionPerformed

  /** @param args the command line arguments */
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(
        new Runnable() {
          public void run() {
            CreateStandaloneReplDialog dialog =
                new CreateStandaloneReplDialog(new javax.swing.JFrame(), true);
            dialog.addWindowListener(
                new java.awt.event.WindowAdapter() {
                  public void windowClosing(java.awt.event.WindowEvent e) {
                    System.exit(0);
                  }
                });
            dialog.setVisible(true);
          }
        });
  }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  public javax.swing.JButton cancelButton;
  public javax.swing.JTextField classPath;
  public javax.swing.JButton connectButton;
  private javax.swing.JLabel errorLabel;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  public javax.swing.JTextField javaArgs;
  public javax.swing.JTextField replName;
  // End of variables declaration//GEN-END:variables

}
 public PrintDupSerializer() {
   JavaBridge.requireCarbonite();
   cljRead = RT.var("carbonite.serializer", "clj-read");
   cljPrintDup = RT.var("carbonite.serializer", "clj-print-dup");
 }
/** This is raw Clojure, not JSR-223. */
public class NativeClojureSearchTests {
  private static final Symbol USER_SYM = Symbol.create("user");
  private static final Var IN_NS = RT.var("clojure.core", "in-ns");

  private void extendClasspath(File newDir) throws Exception {
    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();

    URLClassLoader urlClassLoader =
        new URLClassLoader(new URL[] {newDir.toURI().toURL()}, currentClassLoader);

    Thread.currentThread().setContextClassLoader(urlClassLoader);
  }

  private Object run(File file) throws Exception {
    Reader reader = null;

    try {
      reader = new FileReader(file);

      Var.pushThreadBindings(
          RT.map(
              RT.CURRENT_NS,
              RT.CURRENT_NS.deref(),
              RT.IN,
              new LineNumberingPushbackReader(reader),
              RT.OUT,
              new OutputStreamWriter(System.out),
              RT.ERR,
              new OutputStreamWriter(System.err)));

      IN_NS.invoke(USER_SYM);
      return Compiler.load(reader);
    } finally {
      Var.popThreadBindings();
    }
  }

  private void put(String name, Object value) {
    //	This is largely cargo-culting.
    if (name.indexOf('.') == -1) {
      String nsName = "user";
      if (name.indexOf('/') >= 0) {
        String[] names = name.split("/");
        nsName = names[0];
        name = names[1];
      }

      Var.intern(
          Namespace.findOrCreate(Symbol.create(nsName.intern())),
          Symbol.create(name.intern()),
          value);
    }
  }

  private Object find00(String name) {
    for (ISeq seq = Namespace.all(); seq != null; seq = seq.next()) {
      Namespace ns = (Namespace) seq.first();
      String nsName = ns.toString();
      if (nsName.startsWith("clojure")) continue;

      for (ISeq mseq = ns.getMappings().seq(); mseq != null; mseq = mseq.next()) {
        IMapEntry e = (IMapEntry) mseq.first();
        String k = e.getKey().toString();
        if (k.equals(name)) {
          Object val = e.getValue();
          if (val.toString().startsWith("#'clojure")) continue;
          if (val instanceof Var) {
            val = ((Var) val).deref();
            return val;
          }
        }
      }
    }

    return null;
  }

  @Test
  public void loadViaClasspath() throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle("net.loadbang.clojure.props.TEST_CONFIG");
    String baseDir = bundle.getString("TEST_SCRIPT_BASE");
    System.out.println(baseDir);
    File location = new File(baseDir, "location1");
    extendClasspath(location);
    put("injected", 12345);
    Object obj = run(new File(location, "main.clj"));
    System.out.println(obj.toString());
    Object xxx = find00("xxx");
    System.out.println(xxx.getClass().toString());
  }
}
 public ClojureSeqSerializer() {
   readSeq = RT.var("carbonite.serializer", "read-seq");
 }
@SuppressWarnings("unchecked")
public class ClojureCodeCompletionItem implements CompletionItem {

  private static final LogAdapter LOG = new LogAdapter(ClojureCodeCompletionItem.class.getName());

  static {
    SourceLoader.loadCljCodeCompletion();
  }

  static final Var getalljavaclassesfn =
      RT.var(
          "org.enclojure.ide.nb.editor.completion.cljcodecompletion",
          "get-all-java-classes-with-ns");
  static final Var getallclojurenamespacesfn =
      RT.var(
          "org.enclojure.ide.nb.editor.completion.cljcodecompletion",
          "get-all-clojure-namespaces-within-nsnode");
  static final Var addimportlistfn =
      RT.var("org.enclojure.ide.nb.editor.completion.cljcodecompletion", "add-import-list-new");

  private static Color fieldColor = Color.decode("0x0000B2");
  private static ImageIcon fieldIcon = null;
  private ImageIcon _icon;
  private int _type;
  private int _carretOffset;
  private int _dotOffset;
  private int _layout = -1;
  private String _text;
  private String _doc;

  private static final int LowercaseAfterParen = 0;
  private static final int UppercaseAfterParen = 1;
  private static final int LowercaseAfterParenWithDot = 2;
  private static final int UppercaseAfterParenWithDot = 3;
  private static final int LowercaseNoParen = 4;
  private static final int UppercaseNoParen = 5;
  private static final int LowercaseNoParenWithDot = 6;
  private static final int UppercaseNoParenWithDot = 7;
  private static final int FirstDotAfterParen = 8;
  private static final int FirstDotNoParen = 9;
  private static final int backSlashAfterParen = 10;
  private static final int backSlashNoParen = 11;
  private boolean _isStatic;
  public boolean _isClojure;
  private int _priority;
  public boolean _isMethodOrFunction;
  public boolean _isNamespaceOrPkg;
  public boolean _isConstructor;
  public String _fullclassname;
  private Hashtable _pInfo;
  public String _source;
  private boolean hasPkg = false;

  public String getText() {

    int pos = _text.indexOf("(");

    int staticPos = _text.indexOf("-->static");

    if (staticPos > -1) _isStatic = true;
    else _isStatic = false;

    if (_isClojure == true) _isStatic = true;

    if (pos > -1) return _text.substring(0, pos);
    else return _text;
  }

  public ClojureCodeCompletionItem(String text, int dotOffset, int carretOffset) {
    _text = text;
    _dotOffset = dotOffset;
    _carretOffset = carretOffset;
  }

  public ClojureCodeCompletionItem(String text, int dotOffset, int carretOffset, int layout) {
    _text = text;
    _dotOffset = dotOffset;
    _carretOffset = carretOffset;
    _layout = layout;
  }

  public ClojureCodeCompletionItem(
      String text, int dotOffset, int carretOffset, Hashtable processInfo) {
    _text = text;
    _dotOffset = dotOffset;
    _carretOffset = carretOffset;

    _pInfo = processInfo;
    _layout = (Integer) processInfo.get("layout");
    _isClojure = (Boolean) processInfo.get("isClojure");
    _priority = (Integer) processInfo.get("priority");
    _isMethodOrFunction = (Boolean) processInfo.get("isMethodOrFunction");
    _isNamespaceOrPkg = (Boolean) processInfo.get("isNamespaceOrPackage");
    _fullclassname = (String) processInfo.get("fullclassname");
    _source = (String) processInfo.get("source");
    _isConstructor = (Boolean) processInfo.get("isConstructor");
  }

  private void doSubstitute(
      final JTextComponent component, final String toAdd, final int backOffset) {

    final StyledDocument doc = (StyledDocument) component.getDocument();

    class AtomicChange implements Runnable {

      public void run() {

        int caretOffset = component.getCaretPosition();
        String cname = component.getClass().getName();

        Boolean _isReplPanel = false;

        if (cname.equals("javax.swing.JEditorPane")) _isReplPanel = true;

        String value = getText();
        String javaList = "";

        if (toAdd != null) {
          value += toAdd;
        }

        try {

          String c = component.getText(caretOffset - 1, 1);

          if (!_isClojure && _isNamespaceOrPkg) // java package containing the Class at the end
          {
            value = setValueForClass(value, component);
            javaList = getJavaImportListStr(value);

            if ((javaList.contains("(")) && (!_isReplPanel)) {
              int messageret =
                  (JOptionPane.showConfirmDialog(
                      component,
                      "Do you want to add the import " + value + " to your ns imports?",
                      "add import ?",
                      0));

              if (messageret == 0) {
                PersistentArrayMap entry = addImportList(component, javaList);
                // component.setCaretPosition(caretOffset + javaList.length());
                value = getClassPart(value);

                if (entry != null) {
                  String origNS = (String) entry.get(Keyword.intern(Symbol.create("orignodestr")));
                  String newNS = (String) entry.get(Keyword.intern(Symbol.create("newnodestr")));

                  int insertOffset = newNS.length() - origNS.length();

                  _carretOffset = _carretOffset + insertOffset;
                  _dotOffset = _dotOffset + insertOffset;
                }
              }
            }
          }

          if (!c.equals("/") && (_layout != backSlashAfterParen) && (_layout != backSlashNoParen)) {

            switch (_layout) {
              case LowercaseAfterParen:
                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case UppercaseAfterParen:
                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case UppercaseAfterParenWithDot:
                if (_isMethodOrFunction && (!_isClojure)) // java method
                {
                  if (_isConstructor) {
                    value = "";
                  } else if (Character.isLetter(value.charAt(0))) {
                    {
                      doc.remove(_dotOffset, _carretOffset - _dotOffset);
                      value = "." + value;
                    }
                  }
                } else doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case LowercaseAfterParenWithDot:
                if (_isMethodOrFunction && (!_isClojure)) // java method
                {
                  if (_isConstructor) {
                    value = "";
                  } else if (Character.isLetter(value.charAt(0))) {
                    {
                      doc.remove(_dotOffset, _carretOffset - _dotOffset);
                      value = "." + value;
                    }
                  }
                } else doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case backSlashAfterParen:
                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case FirstDotAfterParen:
                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case FirstDotNoParen:
                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case UppercaseNoParen:
                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case UppercaseNoParenWithDot:
                if (_isMethodOrFunction && (!_isClojure)) // java method
                {
                  if (_isConstructor) {
                    value = "";
                  } else if (Character.isLetter(value.charAt(0))) {
                    {
                      doc.remove(_dotOffset, _carretOffset - _dotOffset);
                      value = "." + value;
                    }
                  }
                } else doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case LowercaseNoParenWithDot:
                if (_isMethodOrFunction && (!_isClojure)) // java method
                {
                  if (_isConstructor) {
                    value = "";
                  } else if (Character.isLetter(value.charAt(0))) {
                    {
                      doc.remove(_dotOffset, _carretOffset - _dotOffset);
                      value = "." + value;
                    }
                  }
                } else doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
              case LowercaseNoParen:
                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                break;
            }

            doc.insertString(_dotOffset, value, null);
          } else {
            if (!c.equals("/")) {
              int backSlashOffset = indexOfBackSlash(component);
              if (backSlashOffset == -1) backSlashOffset = caretOffset;

              if (_isStatic || _layout == backSlashAfterParen || _layout == backSlashNoParen) {
                if (_isClojure && _isMethodOrFunction) {
                  if (isInCurrentNamespace(_fullclassname, component)) {
                    doc.remove(_dotOffset, _carretOffset - _dotOffset);
                    doc.insertString(_dotOffset, setValue(value), null);
                  } else {
                    doc.remove(backSlashOffset + 1, caretOffset - backSlashOffset - 1);
                    doc.insertString(backSlashOffset + 1, value, null);
                  }
                } else {
                  doc.remove(backSlashOffset + 1, caretOffset - backSlashOffset - 1);
                  doc.insertString(backSlashOffset + 1, value, null);
                }
              } else {
                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                doc.insertString(_dotOffset, setValue(value), null);
              }

            } else if (_isStatic || _layout == backSlashAfterParen || _layout == backSlashNoParen)
              if (_isClojure && _isMethodOrFunction) {
                if (isInCurrentNamespace(_fullclassname, component)) {
                  doc.remove(_dotOffset, _carretOffset - _dotOffset);
                  doc.insertString(_dotOffset, setValue(value), null);
                } else doc.insertString(_carretOffset, value, null);
              } else doc.insertString(_carretOffset, value, null);
            else {
              doc.remove(_dotOffset, _carretOffset - _dotOffset);
              doc.insertString(_dotOffset, setValue(value), null);
            }
          }

          component.setCaretPosition(component.getCaretPosition() - backOffset);

        } catch (BadLocationException e) {
          LOG.log(Level.FINEST, e.getMessage());
        }
      }
    }

    AtomicChange change = new AtomicChange();
    try {
      NbDocument.runAtomicAsUser(doc, change);
    } catch (BadLocationException ex) {
      LOG.log(Level.FINEST, ex.getMessage());
    }
  }

  private String getJavaImportListStr(String fullclassstr) {
    Integer dotPos = fullclassstr.lastIndexOf(".");
    String clsstr = "";
    String pkgstr = "";

    if (dotPos > -1) {
      clsstr = fullclassstr.substring(dotPos + 1);
      pkgstr = fullclassstr.substring(0, dotPos);

      return "(" + pkgstr + " " + clsstr + ")\n";

    } else return fullclassstr;
  }

  private String setValueForClass(String value, JTextComponent component) {

    Iterator iter = getAllJavaClasses(component);
    ArrayList<String> li = new ArrayList<String>();
    Hashtable ht = new Hashtable();

    String entry = "";

    if (iter != null) {
      while (iter.hasNext()) {
        entry = (String) iter.next();

        if (entry != null) ht.put(entry, getPkgPart(entry));
      }
    }

    if (ht.containsKey(value)) value = getClassPart(value);

    if (ht.containsValue(getPkgPart(value))) hasPkg = true;

    return value;
  }

  private Boolean isInCurrentNamespace(String value, JTextComponent component) {

    // value will have format of namespace/function
    Integer slashPos = value.indexOf("/");

    if (slashPos > -1) value = value.substring(0, slashPos);

    Iterator iter = getAllClojureNamespacesWithinNSnode(component);
    ArrayList<String> li = new ArrayList<String>();

    String entry = "";

    if (iter != null) {
      while (iter.hasNext()) {
        entry = (String) iter.next();

        if (entry != null) li.add(entry);
      }
    }

    if (li.contains(value)) return true;
    else return false;
  }

  private String getClassPart(String fullclassstr) {

    Integer dotPos = fullclassstr.lastIndexOf(".");

    if (dotPos > -1) return fullclassstr.substring(dotPos + 1);
    else return fullclassstr;
  }

  private String getPkgPart(String fullclassstr) {

    Integer dotPos = fullclassstr.lastIndexOf(".");

    if (dotPos > -1) return fullclassstr.substring(0, dotPos);
    else return fullclassstr;
  }

  private String setValue(String value) {

    if (_isClojure) return value;
    else return "." + value;
  }

  private Iterator getAllJavaClasses(JTextComponent component) {
    try {
      return ((Iterable) getalljavaclassesfn.invoke(component)).iterator();

    } catch (Exception ex) {
      // Exceptions.printStackTrace(ex);
      return null;
    }
  }

  private Iterator getAllClojureNamespacesWithinNSnode(JTextComponent component) {
    try {
      return ((Iterable) getallclojurenamespacesfn.invoke(component)).iterator();

    } catch (Exception ex) {
      // Exceptions.printStackTrace(ex);
      return null;
    }
  }

  private PersistentArrayMap addImportList(JTextComponent component, String javaList) {
    try {
      return (PersistentArrayMap) addimportlistfn.invoke(component, javaList);

    } catch (Exception ex) {
      // Exceptions.printStackTrace(ex);
      return null;
    }
  }

  @Override
  public void defaultAction(JTextComponent jTextComponent) {
    Completion.get().hideAll();
    doSubstitute(jTextComponent, null, 0);
  }

  @Override
  public void processKeyEvent(KeyEvent arg0) {

    //        boolean blnShift =arg0.isShiftDown();
    //        char c=arg0.getKeyChar();
    //        int keyCode=arg0.getKeyCode();

  }

  @Override
  public int getPreferredWidth(Graphics graphics, Font font) {
    return CompletionUtilities.getPreferredWidth(encodeHTML(_text), null, graphics, font);
  }

  @Override
  public void render(
      Graphics g,
      Font defaultFont,
      Color defaultColor,
      Color backgroundColor,
      int width,
      int height,
      boolean selected) {
    CompletionUtilities.renderHtml(
        _icon,
        encodeHTML(_text),
        null,
        g,
        defaultFont,
        (selected ? Color.white : fieldColor),
        width,
        height,
        selected);
  }

  @Override
  public CompletionTask createDocumentationTask() {

    // return null;

    return new AsyncCompletionTask(
        new AsyncCompletionQuery() {

          @Override
          protected void query(CompletionResultSet completionResultSet, Document document, int i) {
            completionResultSet.setDocumentation(
                new ClojureCodeCompletionDocumentation(ClojureCodeCompletionItem.this));
            completionResultSet.finish();
          }
        });
  }

  @Override
  public CompletionTask createToolTipTask() {
    return null;
  }

  @Override
  public boolean instantSubstitution(JTextComponent arg0) {
    return false;
  }

  @Override
  public int getSortPriority() {
    return _priority;
  }

  @Override
  public CharSequence getSortText() {
    return getText();
  }

  @Override
  public CharSequence getInsertPrefix() {
    return getText();
  }

  public static String encodeHTML(String s) {
    StringBuilder out = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      if (c > 127 || c == '"' || c == '<' || c == '>') {
        out.append("&#" + (int) c + ";");
      } else {
        out.append(c);
      }
    }
    return out.toString();
  }

  static int indexOfBackSlash(final JTextComponent component) {

    int caretOffset = component.getCaretPosition();

    String c;

    int i = caretOffset - 1;

    try {
      while (--i > -1) {
        c = component.getText(i, 1);
        if (c.equals("/")) {
          return i;
        }
      }
      return -1;
    } catch (BadLocationException ex) {
      return -1;
    }
  }
}