用于使Eclipse插件开发更容易的库?

时间:2012-03-22 06:00:40

标签: eclipse eclipse-plugin

我刚学习Eclipse插件开发,目前只是为了添加一些其他人无法实现的简单自定义命令。我注意到Eclipse插件API ......还有很多不足之处。是否有任何开源库试图改善插件开发体验? (我开始无所事事地推测自己编写......)。

我知道Eclipse 4.0应该会长期解决其中的一些问题,但我不太可能很快就能在工作中使用它。


修改

这是我的意思的一个例子。这是emacs的“饥饿删除”功能的实现:

(defmacro hungry-delete-backward (&optional limit)
  (if limit
      `(let ((limit (or ,limit (point-min))))
         (while (progn
                  ;; skip-syntax-* doesn't count \n as whitespace..
                  (skip-chars-backward " \t\n\r\f\v" limit)
                  (and (eolp)
                       (eq (char-before) ?\\)
                       (> (point) limit)))
           (backward-char)))
    '(while (progn
              (skip-chars-backward " \t\n\r\f\v")
              (and (eolp)
                   (eq (char-before) ?\\)))
       (backward-char))))

这里是Eclipse的等效实现的 part ,不包括清单文件,plugin.xml或插件的Activator:

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  IEditorPart editor = HandlerUtil.getActiveEditorChecked(event);
  if (!(editor instanceof ITextEditor)) return null;
  ITextEditor ite = (ITextEditor) editor;
  IDocumentProvider idp = ite.getDocumentProvider();
  IDocument doc = idp.getDocument(ite.getEditorInput());
  ISelection selection = ite.getSelectionProvider().getSelection();
  if (!(editor instanceof ITextSelection)) return null;
  ITextSelection its = (ITextSelection) selection;
  int currentCursorPosition = its.getOffset();
  int deletionStart, deletionEnd;
  if (its.getLength() == 0) {
    deletionStart = currentCursorPosition - 1;
    deletionEnd = currentCursorPosition;
    FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(doc);
    while (Character.isWhitespace(frda.charAt(deletionStart)) && deletionStart > 0) {
      deletionStart--;
   }
   if (deletionStart != 0 && deletionStart + 1 != deletionEnd) deletionStart++;
  } else {
    deletionStart = its.getOffset();
    deletionEnd = its.getOffset() + its.getLength();
  }

  int deletionLength = deletionEnd - deletionStart;
  try {
    doc.replace(deletionStart, deletionLength, "");
  } catch (BadLocationException ble) {
    // Bad location, just ignore it.
  }
  return null;
}

例如,Java版本顶部的样板块可以很容易地被库替换。

1 个答案:

答案 0 :(得分:0)

我认为您正在寻找类似Groovy-MonkeyEclipse-Monkey的内容,它们允许您编写插入Eclipse的脚本。我对这两个项目都不太了解,也不知道它们是否得到了积极维护(实际上我知道不再维护Eclipse-Monkey)。但是,这些允许您在Eclipse中执行类似emacs的脚本。