Пример #1
0
 public synchronized void startREPLServer() {
   if (ackREPLServer == null) {
     try {
       // TODO use ClojureOSGi.withBundle instead
       Var startServer =
           BundleUtils.requireAndGetVar(
               getBundle().getSymbolicName(), "clojure.tools.nrepl.server/start-server");
       Object defaultHandler =
           BundleUtils.requireAndGetVar(
                   getBundle().getSymbolicName(), "clojure.tools.nrepl.server/default-handler")
               .invoke();
       Object handler =
           BundleUtils.requireAndGetVar(
                   getBundle().getSymbolicName(), "clojure.tools.nrepl.ack/handle-ack")
               .invoke(defaultHandler);
       ackREPLServer =
           (ServerSocket)
               ((Map) startServer.invoke(Keyword.intern("handler"), handler))
                   .get(Keyword.intern("server-socket"));
       CCWPlugin.log(
           "Started ccw nREPL server: nrepl://127.0.0.1:" + ackREPLServer.getLocalPort());
     } catch (Exception e) {
       CCWPlugin.logError("Could not start plugin-hosted REPL server", e);
       throw new RuntimeException("Could not start plugin-hosted REPL server", e);
     }
   }
 }
Пример #2
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;
 }
Пример #3
0
 public static String getTokenPreferenceKey(Keyword token) {
   return CCW_PREFERENCE_PREFIX
       + "."
       + EDITOR_COLORING_PREFIX
       + "."
       + token.getName(); // $NON-NLS-1$
 }
Пример #4
0
 public static IPersistentMap snuser_define_caseframe(
     Keyword type, IPersistentList slots, IPersistentList fsymbols) {
   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, Keyword.intern("fsymbols"), fsymbols);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Пример #5
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;
 }
      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());
        }
      }
Пример #7
0
/**
 * Static class containing Clojure keywords used in scene descriptions
 *
 * @author Mike
 */
public class Key {
  // scene keys
  public static final Keyword SCENE = Keyword.intern(null, "scene");
  public static final Keyword ROOT = Keyword.intern(null, "root");
  public static final Keyword CAMERA = Keyword.intern(null, "camera");
  public static final Keyword LIGHT_SOURCES = Keyword.intern(null, "light-sources");

  // general keys
  public static final Keyword TYPE = Keyword.intern(null, "type");
  public static final Keyword COLOUR = Keyword.intern(null, "colour");
  public static final Keyword POSITION = Keyword.intern(null, "position");
  public static final Keyword NORMAL = Keyword.intern(null, "normal");
  public static final Keyword DIRECTION = Keyword.intern(null, "direction");
  public static final Keyword DISTANCE = Keyword.intern(null, "distance");

  // sky sphere
  public static final Keyword SKY_SPHERE = Keyword.intern(null, "sky-sphere");

  // plane
  public static final Keyword PLANE = Keyword.intern(null, "plane");

  // union
  public static final Keyword UNION = Keyword.intern(null, "union");
  public static final Keyword OBJECTS = Keyword.intern(null, "objects");

  // sphere
  public static final Keyword SPHERE = Keyword.intern(null, "sphere");
  public static final Keyword CENTRE = Keyword.intern(null, "centre");
  public static final Keyword RADIUS = Keyword.intern(null, "radius");

  // light source keys
  public static final Keyword LIGHT_SOURCE = Keyword.intern(null, "light-source");
  public static final Keyword SHADOWLESS = Keyword.intern(null, "shadowless");
  public static final Keyword INTENSITY = Keyword.intern(null, "intensity");
}
Пример #8
0
/** Constant definitions for plug-in preferences */
public class PreferenceConstants {

  public static final Keyword stringToken = Keyword.intern("string");
  public static final Keyword otherLiteralsToken = Keyword.intern("other-literals");
  public static final Keyword regexToken = Keyword.intern("regex");
  public static final Keyword intToken = Keyword.intern("int");
  public static final Keyword floatToken = Keyword.intern("float");
  public static final Keyword charToken = Keyword.intern("char");
  //	public static final Keyword literalSymbolToken = Keyword.intern("literalSymbol");

  //	public static final Keyword symbolToken = Keyword.intern("symbol");

  public static final Keyword FUNCTION_Token = Keyword.intern("FUNCTION");
  public static final Keyword callableFUNCTION_Token = Keyword.intern("callableFUNCTION");
  public static final Keyword MACRO_Token = Keyword.intern("MACRO");
  public static final Keyword callableMACRO_Token = Keyword.intern("callableMACRO");
  public static final Keyword SPECIAL_FORM_Token = Keyword.intern("SPECIAL_FORM");
  public static final Keyword callableSPECIAL_FORM_Token = Keyword.intern("callableSPECIAL_FORM");
  public static final Keyword GLOBAL_VAR_Token = Keyword.intern("GLOBAL_VAR");
  public static final Keyword callableGLOBAL_VAR_Token = Keyword.intern("callableGLOBAL_VAR");
  public static final Keyword JAVA_CLASS_Token = Keyword.intern("JAVA_CLASS");
  public static final Keyword callableJAVA_CLASS_Token = Keyword.intern("callableJAVA_CLASS");
  public static final Keyword JAVA_INSTANCE_METHOD_Token = Keyword.intern("JAVA_INSTANCE_METHOD");
  public static final Keyword callableJAVA_INSTANCE_METHOD_Token =
      Keyword.intern("callableJAVA_INSTANCE_METHOD");
  public static final Keyword JAVA_STATIC_METHOD_Token = Keyword.intern("JAVA_STATIC_METHOD");
  public static final Keyword callableJAVA_STATIC_METHOD_Token =
      Keyword.intern("callableJAVA_STATIC_METHOD");
  public static final Keyword RAW_SYMBOL_Token = Keyword.intern("RAW_SYMBOL");
  public static final Keyword callable_RAW_SYMBOL_Token = Keyword.intern("callableRAW_SYMBOL");

  public static final Keyword deactivatedRainbowParen = Keyword.intern("deactivated-rainbow-paren");
  public static final Keyword rainbowParenLevel1 = Keyword.intern("rainbow-paren-level-1");
  public static final Keyword rainbowParenLevel2 = Keyword.intern("rainbow-paren-level-2");
  public static final Keyword rainbowParenLevel3 = Keyword.intern("rainbow-paren-level-3");
  public static final Keyword rainbowParenLevel4 = Keyword.intern("rainbow-paren-level-4");
  public static final Keyword rainbowParenLevel5 = Keyword.intern("rainbow-paren-level-5");
  public static final Keyword rainbowParenLevel6 = Keyword.intern("rainbow-paren-level-6");
  public static final Keyword rainbowParenLevel7 = Keyword.intern("rainbow-paren-level-7");
  public static final Keyword rainbowParenLevel8 = Keyword.intern("rainbow-paren-level-8");

  public static final Keyword keywordToken = Keyword.intern("keyword");
  public static final Keyword commentToken = Keyword.intern("comment");
  public static final Keyword whitespaceToken = Keyword.intern("whitespace");
  public static final Keyword metaToken = Keyword.intern("meta");
  public static final Keyword readerLiteralTag = Keyword.intern("reader-literal");

  public static final Keyword replLogValue = Keyword.intern("repl-log-keyword-value");
  public static final Keyword replLogError = Keyword.intern("repl-log-error");

  /**
   * Set of tokens keywords for which syntax color information can be retrieved from preferences via
   * the <code>getColorizableToken()</code> method
   */
  public static final Set<Keyword> colorizableTokens;

  /** List of tokens, ordered to be displayed on the preferences page. */
  public static final List<Keyword> orderedColorizableTokens; // FIXME: use it, or remove it

  static {
    orderedColorizableTokens =
        Collections.unmodifiableList(
            new ArrayList<Keyword>() {
              {
                add(stringToken);
                add(otherLiteralsToken);
                add(regexToken);
                add(intToken);
                add(floatToken);
                add(charToken);
                add(FUNCTION_Token);
                add(callableFUNCTION_Token);
                add(MACRO_Token);
                add(callableMACRO_Token);
                add(SPECIAL_FORM_Token);
                add(callableSPECIAL_FORM_Token);
                add(GLOBAL_VAR_Token);
                add(callableGLOBAL_VAR_Token);
                add(JAVA_CLASS_Token);
                add(callableJAVA_CLASS_Token);
                add(JAVA_INSTANCE_METHOD_Token);
                add(callableJAVA_INSTANCE_METHOD_Token);
                add(JAVA_STATIC_METHOD_Token);
                add(callableJAVA_STATIC_METHOD_Token);
                add(RAW_SYMBOL_Token);
                add(callable_RAW_SYMBOL_Token);
                add(keywordToken);
                add(commentToken);
                add(metaToken);
                add(readerLiteralTag);
                add(deactivatedRainbowParen);
                add(rainbowParenLevel1);
                add(rainbowParenLevel2);
                add(rainbowParenLevel3);
                add(rainbowParenLevel4);
                add(rainbowParenLevel5);
                add(rainbowParenLevel6);
                add(rainbowParenLevel7);
                add(rainbowParenLevel8);
                add(replLogValue);
                add(replLogError);
              }
            });

    colorizableTokens = Collections.unmodifiableSet(new HashSet<Keyword>(orderedColorizableTokens));
  }

  public static final String CCW_PREFERENCE_PREFIX = "ccw.preferences"; // $NON-NLS-1$

  public static final String CCW_GENERAL_AUTOMATIC_NATURE_ADDITION =
      CCW_PREFERENCE_PREFIX + ".automatic_nature_addition";

  public static final String CCW_GENERAL_AUTO_RELOAD_ON_STARTUP_SAVE =
      CCW_PREFERENCE_PREFIX + ".auto_reload_on_startup_save";

  public static final String SWITCH_TO_NS_ON_REPL_STARTUP =
      CCW_PREFERENCE_PREFIX + ".switch_to_ns_on_repl_startup"; // $NON-NLS-1$

  public static final String USE_STRICT_STRUCTURAL_EDITING_MODE_BY_DEFAULT =
      CCW_PREFERENCE_PREFIX + ".use_strict_structural_editing_mode_by_default"; // $NON-NLS-1$
  public static final String SHOW_RAINBOW_PARENS_BY_DEFAULT =
      CCW_PREFERENCE_PREFIX + ".show_rainbow_parens_by_default"; // $NON-NLS-1$

  public static final String USE_TAB_FOR_REINDENTING_LINE =
      CCW_PREFERENCE_PREFIX + ".use_tab_for_reindenting_line"; // $NON-NLS-1$

  public static final String FORCE_TWO_SPACES_INDENT =
      CCW_PREFERENCE_PREFIX + ".force_two_spaces_indent"; // $NON-NLS-1$

  public static final String EDITOR_COLORING_PREFIX = "editor_color"; // $NON-NLS-1$

  public static final String EDITOR_ESCAPE_ON_PASTE =
      CCW_PREFERENCE_PREFIX + ".escape_on_paste"; // $NON-NLS-1$

  public static final String EDITOR_CODE_COMPLETION_AUTO_ACTIVATE =
      CCW_PREFERENCE_PREFIX + ".code_completion.auto_activate";

  public static final String EDITOR_DISPLAY_NAMESPACE_IN_TABS =
      CCW_PREFERENCE_PREFIX + ".editor.display_namespace_in_tabs";

  public static final String REPL_VIEW_AUTO_EVAL_ON_ENTER_ACTIVE =
      CCW_PREFERENCE_PREFIX + ".repl_view_autoeval_on_enter_active"; // $NON-NLS-1$
  public static final String REPL_VIEW_DISPLAY_HINTS =
      CCW_PREFERENCE_PREFIX + ".repl_view_display_hints"; // $NON-NLS-1$

  public static final String EDITOR_BOLD_SUFFIX = ".bold"; // $NON-NLS-1$
  public static final String EDITOR_ITALIC_SUFFIX = ".italic"; // $NON-NLS-1$
  /* TODO enable these once text attributes are used in the editor
  public static final String EDITOR_UNDERLINE_SUFFIX = ".underline"; //$NON-NLS-1$
  public static final String EDITOR_STRIKETHROUGH_SUFFIX = ".strikethrough"; //$NON-NLS-1$
  */

  public static final String EDITOR_COLORING_ENABLED_SUFFIX = ".enabled"; // $NON-NLS-1$

  public static class ColorizableToken {
    public final RGB rgb;
    public final Boolean isBold;
    public final Boolean isItalic;

    public ColorizableToken(RGB rgb, Boolean isBold, Boolean isItalic) {
      this.rgb = rgb;
      this.isBold = isBold;
      this.isItalic = isItalic;
    }
  }

  public static String getTokenPreferenceKey(Keyword token) {
    return CCW_PREFERENCE_PREFIX
        + "."
        + EDITOR_COLORING_PREFIX
        + "."
        + token.getName(); // $NON-NLS-1$
  }

  public static ColorizableToken getColorizableToken(
      IPreferenceStore store, Keyword token, RGB defaultColor) {
    String tokenKey = getTokenPreferenceKey(token);
    return new ColorizableToken(
        CCWPlugin.getPreferenceRGB(store, tokenKey, defaultColor),
        store.getBoolean(SyntaxColoringHelper.getEnabledPreferenceKey(tokenKey))
            ? store.getBoolean(SyntaxColoringHelper.getBoldPreferenceKey(tokenKey))
            : null,
        store.getBoolean(SyntaxColoringHelper.getEnabledPreferenceKey(tokenKey))
            ? store.getBoolean(SyntaxColoringHelper.getItalicPreferenceKey(tokenKey))
            : null);
  }
}
Пример #9
0
 private static Keyword keyword(String s) {
   return Keyword.intern(s);
 }