Search in sources :

Example 6 with PersistentArrayMap

use of clojure.lang.PersistentArrayMap in project storm by apache.

the class ClojureSpout method open.

@Override
public void open(final Map conf, final TopologyContext context, final SpoutOutputCollector collector) {
    IFn hof = Utils.loadClojureFn(_fnSpec.get(0), _fnSpec.get(1));
    try {
        IFn preparer = (IFn) hof.applyTo(RT.seq(_params));
        final Map<Keyword, Object> collectorMap = new PersistentArrayMap(new Object[] { Keyword.intern(Symbol.create("output-collector")), collector, Keyword.intern(Symbol.create("context")), context });
        List<Object> args = new ArrayList<Object>() {

            {
                add(conf);
                add(context);
                add(collectorMap);
            }
        };
        _spout = (ISpout) preparer.applyTo(RT.seq(args));
        //this is kind of unnecessary for clojure
        try {
            _spout.open(conf, context, collector);
        } catch (AbstractMethodError ame) {
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IFn(clojure.lang.IFn) PersistentArrayMap(clojure.lang.PersistentArrayMap) Keyword(clojure.lang.Keyword) ArrayList(java.util.ArrayList)

Example 7 with PersistentArrayMap

use of clojure.lang.PersistentArrayMap in project storm by nathanmarz.

the class ClojureSpout method open.

@Override
public void open(final Map conf, final TopologyContext context, final SpoutOutputCollector collector) {
    IFn hof = Utils.loadClojureFn(_fnSpec.get(0), _fnSpec.get(1));
    try {
        IFn preparer = (IFn) hof.applyTo(RT.seq(_params));
        final Map<Keyword, Object> collectorMap = new PersistentArrayMap(new Object[] { Keyword.intern(Symbol.create("output-collector")), collector, Keyword.intern(Symbol.create("context")), context });
        List<Object> args = new ArrayList<Object>() {

            {
                add(conf);
                add(context);
                add(collectorMap);
            }
        };
        _spout = (ISpout) preparer.applyTo(RT.seq(args));
        //this is kind of unnecessary for clojure
        try {
            _spout.open(conf, context, collector);
        } catch (AbstractMethodError ame) {
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IFn(clojure.lang.IFn) PersistentArrayMap(clojure.lang.PersistentArrayMap) Keyword(clojure.lang.Keyword) ArrayList(java.util.ArrayList)

Example 8 with PersistentArrayMap

use of clojure.lang.PersistentArrayMap in project enclojure by EricThorsen.

the class ClojureCodeCompletionItem method doSubstitute.

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 (// java package containing the Class at the end
                !_isClojure && _isNamespaceOrPkg) {
                    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 (// java method
                            _isMethodOrFunction && (!_isClojure)) {
                                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 (// java method
                            _isMethodOrFunction && (!_isClojure)) {
                                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 (// java method
                            _isMethodOrFunction && (!_isClojure)) {
                                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 (// java method
                            _isMethodOrFunction && (!_isClojure)) {
                                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());
    }
}
Also used : PersistentArrayMap(clojure.lang.PersistentArrayMap) StyledDocument(javax.swing.text.StyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

PersistentArrayMap (clojure.lang.PersistentArrayMap)8 ArrayList (java.util.ArrayList)7 IFn (clojure.lang.IFn)6 Keyword (clojure.lang.Keyword)6 BadLocationException (javax.swing.text.BadLocationException)2 StyledDocument (javax.swing.text.StyledDocument)2 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Document (javax.swing.text.Document)1 JTextComponent (javax.swing.text.JTextComponent)1 Project (org.netbeans.api.project.Project)1 CompletionResultSet (org.netbeans.spi.editor.completion.CompletionResultSet)1 AsyncCompletionQuery (org.netbeans.spi.editor.completion.support.AsyncCompletionQuery)1 AsyncCompletionTask (org.netbeans.spi.editor.completion.support.AsyncCompletionTask)1