示例#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
 static {
   try {
     CCWPlugin.getClojureOSGi()
         .require(CCWPlugin.getDefault().getBundle(), PareditAutoEditStrategyImpl_NS);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
示例#3
0
 public static void lightenStyledTextColors(StyledText st, double pct) {
   StyleRange[] srs = st.getStyleRanges();
   Color defaultFGColor = CCWPlugin.getColor(RGBUtil.lighten(st.getForeground().getRGB(), pct));
   for (int i = 0; i < srs.length; i++) {
     StyleRange oldSR = srs[i];
     StyleRange newSR = newStyleRange(oldSR);
     Color lightForeground =
         (oldSR.foreground == null)
             ? defaultFGColor
             : CCWPlugin.getColor(RGBUtil.lighten(oldSR.foreground.getRGB(), pct));
     newSR.foreground = lightForeground;
     st.setStyleRange(newSR);
   }
   st.setForeground(defaultFGColor);
 }
示例#4
0
 /**
  * Create a preference store combined from the Clojure, the EditorsUI and the PlatformUI
  * preference stores to inherit all the default text editor settings from the Eclipse preferences.
  *
  * <p>Beware, the combined preference store can only be instanciated from the UI Thread.
  *
  * @return the combined preference store.
  */
 public IPreferenceStore getCombinedPreferenceStore() {
   if (prefs == null) {
     prefs =
         new ChainedPreferenceStore(
             new IPreferenceStore[] {
               CCWPlugin.getDefault().getPreferenceStore(),
               EditorsUI.getPreferenceStore(),
               PlatformUI.getPreferenceStore()
             });
   }
   return prefs;
 }
示例#5
0
 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);
 }
示例#6
0
  private static String fileArg(IProject project, IFile file) {
    String FILE_ARG_ERROR_PREFIX =
        "When trying to create clojure.main " + "file arg to launch, was " + "unable to ";

    IPath filePath = file.getLocation();

    IJavaProject javaProject = ClojureCore.getJavaProject(project);
    try {
      IPackageFragmentRoot filePFR = findPackageFragmentRoot(javaProject, filePath);
      if (filePFR != null) {
        IPath pfrPath = filePFR.getResource().getLocation();
        // TODO we can use .makeRelativeTo again when we decide not to support Eclipse 3.4 anymore
        //    			String classpathRelativeArg = filePath.makeRelativeTo(pfrPath).toString();
        String classpathRelativeArg = filePath.toString().substring(pfrPath.toString().length());
        if (classpathRelativeArg.startsWith("/")) {
          classpathRelativeArg = classpathRelativeArg.substring(1);
        }
        return " \"@/" + classpathRelativeArg + "\"";
      } else {
        CCWPlugin.logError(
            FILE_ARG_ERROR_PREFIX
                + " find package fragment root for file "
                + file
                + " in project "
                + project);
        return "";
      }
    } catch (JavaModelException jme) {
      CCWPlugin.logError(
          FILE_ARG_ERROR_PREFIX
              + " complete due to a JavaModelException finding package fragment root for file "
              + file
              + " in project "
              + project,
          jme);
      return "";
    }
  }
示例#7
0
 public static boolean isAutoReloadOnStartupSaveEnabled() {
   return CCWPlugin.getDefault()
       .getPreferenceStore()
       .getBoolean(PreferenceConstants.CCW_GENERAL_AUTO_RELOAD_ON_STARTUP_SAVE);
 }
示例#8
0
 public static void log(String msg) {
   getTracer().trace(TraceOptions.LOG_INFO, "INFO   - " + msg);
   plugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, msg));
 }
示例#9
0
 public static void logWarning(Throwable e) {
   getTracer().trace(TraceOptions.LOG_WARNING, e);
   plugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, e.getMessage(), e));
 }
示例#10
0
 public static void logWarning(String msg, Throwable e) {
   getTracer().trace(TraceOptions.LOG_WARNING, e, "WARNING - " + msg);
   plugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, msg, e));
 }
示例#11
0
 public static void logError(Throwable e) {
   getTracer().trace(TraceOptions.LOG_ERROR, e, "ERROR  - ");
   plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e));
 }
示例#12
0
 public static void logError(String msg, Throwable e) {
   getTracer().trace(TraceOptions.LOG_ERROR, e, "ERROR  - " + msg);
   plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, msg, e));
 }
示例#13
0
    public void createControl(Composite parent) {
      Composite topLevel = new Composite(parent, SWT.NONE);
      GridLayout topLayout = new GridLayout();
      topLayout.verticalSpacing = 0;
      topLevel.setLayout(topLayout);

      topLevel.setFont(parent.getFont());

      // Show description on opening
      setErrorMessage(null);
      setMessage(null);
      setControl(topLevel);

      boolean fail = false;
      if (getSelection().size() == 1) {
        Object sel = getSelection().getFirstElement();
        if (sel instanceof IPackageFragmentRoot) {
          dest = (IContainer) ((IPackageFragmentRoot) sel).getResource();
        } else if (sel instanceof IPackageFragment) {
          dest = (IContainer) ((IPackageFragment) sel).getResource();
          packageName = ((IPackageFragment) sel).getElementName();
        } else {
          final String JAVA_SOURCE_ERROR =
              "Cannot create Clojure namespace outside a java source folder";
          CCWPlugin.logError("Wrong selection type: " + sel.getClass() + ". " + JAVA_SOURCE_ERROR);
          mainPage.setErrorMessage(JAVA_SOURCE_ERROR);
          fail = true;
        }

        if (dest != null) {
          setDescription(
              "Create new Clojure "
                  + kind(true)
                  + " in \""
                  + dest.getFullPath().toString()
                  + "\" of project \""
                  + dest.getProject().getName()
                  + "\"");
        }
      } else {
        IProject project = null;
        for (Iterator i = getSelection().iterator(); i.hasNext(); ) {
          IResource res;
          Object e = i.next();
          if (e instanceof IResource) res = (IResource) e;
          else if (e instanceof IAdaptable)
            res = (IResource) ((IAdaptable) e).getAdapter(IResource.class);
          else res = null;
          if (res == null) continue;
          if (res.getProject() == null) continue;
          if (project == null) project = res.getProject();
          else {
            project = null;
            break;
          }
        }
        if (project != null) {
          dest = project;
          setDescription("Create new top-level Clojure " + kind(true) + ".");
        } else if (project == null) {
          mainPage.setErrorMessage(
              "Cannot create top-level Clojure " + kind(true) + " without project selection.");
          fail = true;
        }
      }
      if (!fail) {
        Group group = label(topLevel, kind() + " name:");
        text = new Text(group, SWT.LEFT + SWT.BORDER);
        addToGroup(group, text);
      }
    }
示例#14
0
  /** @see org.eclipse.jface.wizard.IWizard#performFinish() */
  public boolean performFinish() {
    IContainer dest = dest();
    if (dest == null) {
      mainPage.setErrorMessage("Must select an existing destination folder.");
      return false;
    }
    String name = name();
    String suffix = suffix();
    if (name.length() == 0) {
      mainPage.setErrorMessage("Empty file name.");
      return false;
    }
    if (!Character.isJavaIdentifierStart(name.charAt(0))) {
      mainPage.setErrorMessage(
          "Invalid character \'"
              + name.charAt(0)
              + "\' at index "
              + 0
              + " for Clojure namespace file \'"
              + name
              + "'");
      return false;
    }
    for (int i = 1; i < name.length(); i++)
      if (!Character.isJavaIdentifierPart(name.charAt(i))) {
        mainPage.setErrorMessage(
            "Invalid character \'"
                + name.charAt(i)
                + "\' at index "
                + i
                + " for Clojure namespace file \'"
                + name
                + "'");
        return false;
      }

    // check if file already exists.
    IFile file;
    if (mainPage.dest instanceof IProject) {
      file = ((IProject) mainPage.dest).getFile(name + suffix);
    } else if (mainPage.dest instanceof IFolder) {
      file = ((IFolder) mainPage.dest).getFile(name + suffix);
    } else {
      return false;
    }

    if (file.exists()) {
      mainPage.setErrorMessage("File " + file.getName() + " already exists.");
      return false;
    }

    try {
      String namespace =
          ((StringUtils.isEmpty(mainPage.packageName) ? "" : mainPage.packageName + ".") + name)
              .replaceAll("_", "-");
      String contents = "(ns " + namespace + ")\n\n";
      file.create(new StringBufferInputStream(contents), true, null);
      IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
      if (dw != null) {
        IWorkbenchPage page = dw.getActivePage();
        if (page != null) {
          TextEditor editor = (TextEditor) IDE.openEditor(page, file, true);
          editor.selectAndReveal(contents.length(), 0);
        }
      }
    } catch (CoreException e) {
      CCWPlugin.logError(e);
      return false;
    }

    return true;
  }