如何使用插件扩展 Eclipse Java 编辑器功能?

发布于 2024-10-18 05:26:23 字数 386 浏览 1 评论 0原文

希望有人能帮助我,给出提示和出路。 现在我正在参与一个雄心勃勃的项目,试图创建混合​​数学和编程 IDE。 经过大量的预研究,我们决定使用 eclipse 作为基础,并以某种方式添加 Mathematica、maple 功能。 一般来说,我们希望能够将数学表达式 (a = sin(Pi)+10^2) 输入到 java 代码中。此外,这些表达式应该在 LaTex 视图中显示在代码中,以便工程师更容易阅读,以说明我们想要在注释中实现插入图像的代码。 由于我们需要所有 java 编辑器功能,因此我认为使用标准 eclipse java 编辑器并学习它与其他对象(例如图像)的行为是正确的。

所以我的问题是: - 有人可以分享开发类似产品的经验吗? - 也许我们会开发一些类似的东西?

也许我会写更多的问题,尤其是更严格的问题。

Hope somebody could help me, giving a hint and way out.
Right now I'm involved in a ambitious project trying to create mixed math and programming IDE.
After a huge prestudy we decided to use eclipse as a base, and somehow add Mathematica,maple functionality.
Generally speaking we want to make entering math expressions (a = sin(Pi)+10^2) into java code possible. Also those expressions should be showed in LaTex view, right in the code to make it more readable for engineers, to illustrate the code we want to implement insertion images in comments.
As we need all th java editor functionality, in my opinion it's correct to use standart eclipse java editor, and learn it to behave with other objects, e. g. images.

So my questions are:
- Could somebody share experience developing similar products?
- May be there are something like we are going to develop?

Probably I'll write more questions, especially tighter ones.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

‖放下 2024-10-25 05:26:23

这确实是一个听起来很有趣的项目。正如 Gilbert Le Blanc 提到的,Java 编辑器针对编辑 Java 代码进行了高度优化,但并不意味着可扩展。

话虽这么说,我可以推荐两种选择(一种是按规则行事,一种是违反规则)。

  1. 您可以通过 org.eclipse.jdt.ui.JavaEditorTextHovers 扩展点(因此它的工作方式类似于 JavaDoc 悬停)或在位于编辑器(因此它的工作方式类似于 JavaDoc 视图)。 (这是按规则进行的。)
  2. 不久前,我实现了一个原型编辑器,它允许您编辑嵌入其中的 CAL(一种函数式 JVM 语言)片段的 Java 代码。这些片段存储在编辑器内自己的小窗口中。这是一个原型,并非一切都运行顺利,而且它也使用 Eclipse 3.2,但这正是您想要做的事情。编译和运行代码并不容易,但你可以看一下......好吧,也许吧。我必须找到源代码的 EPL 变体。在那之前,请意识到像这样破解 Java 编辑器需要一些有关 JDT 的专业知识,并且您需要小心操作方式,以免无意中破坏其他东西。

编辑

这是我所描述的项目的 zip 文件。它不会按原样编译,但您可以查看源代码:

尝试此链接< /a>.应该让全世界都能看到。

需要认识到的重要一点是 swt StyledText 小部件本身可以包含其他小部件。该项目在 Java 编辑器中利用了这一点。

特别是,请查看类 org.openquark.cal.eclipse.embedded.containing.ContainingEditor,它是 CompilaitonUnitEditor 的子类。这个特定的类将第二个文本编辑器(包含的编辑器)嵌入到另一个编辑器(包含的编辑器)中。

另外,请查看 org.openquark.cal.eclipse.embedded.containing.ControlManager。此类管理包含 CompilationUnitEditor 的样式文本内的不同控件。

该项目的作用是创建一个类似 Java 的编辑器,并允许用户在 Java 编辑器中嵌入另一种语言的编辑器。这些编辑器实际上由包含 Java 编辑器中的文本支持,但文本被包含的编辑器覆盖。

当文本输入包含编辑器时,包含的编辑器上下移动。此外,您还可以使用键盘在包含的编辑器中获得/失去焦点。

我已经有好几年没有查看这段代码了,但是如果您有任何疑问,请给我留言或添加到这个问题中。

That is certainly an interesting sounding project. As Gilbert Le Blanc mentions, the Java Editor is highly optimized to edit Java code and is not meant to be extensible.

That being said, I can recommend two options (one that plays by the rules, and one that goes against them).

  1. Instead of embedding your images directly in the Java editor, you could implement your own hover, through the org.eclipse.jdt.ui.JavaEditorTextHovers extension point (so it would work like JavaDoc hovers), or in a separate view that sits beside the editor (so it would work like the JavaDoc view). (This is playing by the rules.)
  2. A while ago, I implemented a prototype editor that allows you to edit Java code with snippets of CAL (a functional JVM language) embedded inside of it. The snippets were stored in there own little window inside the editor. This was a prototype and not everything worked smoothly and it was also using Eclipse 3.2, but this is exactly the kind of thing that you want to do. It won't be easy to compile and run the code, but you can have a look at it....well, maybe. I have to find an EPL variant of the source code. Until then, just realize that hacking the Java Editor like this requires some specialized knowledge about the JDT and you need to be careful about how you do it so that you do inadvertently break other things.

Edit

Here is a zip of the project I described. It will not compile as it is, but you can look at the source code:

Try this link. It should be viewable by the world.

The essential thing to realize is that swt StyledText widgets can themselves contain other widgets. This project leverages that in Java editors.

In particular, look at the class org.openquark.cal.eclipse.embedded.containing.ContainingEditor, which is a sub-class of CompilaitonUnitEditor. This particular class embeds a second text editor (the contained editor) inside of another editor (the containing editor).

Also, take a look at org.openquark.cal.eclipse.embedded.containing.ControlManager. This class manages the different controls inside of a styled text of the containing CompilationUnitEditor.

What this project does is creates a Java-like editor, and allows users to embed editors for another language inside of the Java editor. These editors are actually backed by text in the containing Java editor, but the text is covered by the contained editor.

The contained editors move up and down as text is entered into containing editor. Also, you can use the keyboard to gain/lose focus in a contained editor.

It's been several years since I looked at this code, but if you have any questions, drop me a line or add to this question.

唠甜嗑 2024-10-25 05:26:23

Eclipse Java 编辑器由数百个 Java 类组成。在这数百个 Java 类中存在一个隐含的假设:编辑器视图仅用于代码。

在我看来,您会发现为数学图像开发 Mathematica 类型的编辑器要容易得多,而无需使用 Java 编辑器。您的工程师可以在 Eclipse 中打开两个编辑器。

如果我的评论没有阻止您,这里是 Eclipse Helios 的 Eclipse 文档(也称为 Eclipse Helios)在 Eclipse 3.6 中,

您要开始的部分称为 JDT 插件开发人员指南。

当我输入此内容时,Eclipse 网站响应缓慢。您还可以从 Eclipse Helios 内部访问帮助。

Help -> Help Contents

The Eclipse Java Editor is made up of hundreds of Java classes. There's an implicit assumption in those hundreds of Java classes that the editor view is just for code.

In my opinion, you'll find it much easier to develop a Mathematica-type editor for your math images, and leave the Java editor alone. Your engineers can open two editors in Eclipse.

If my comments haven't dissuaded you, here's the Eclipse documentation for Eclipse Helios, otherwise known as Eclipse 3.6

The section you'd start with is called the JDT Plug-in Developer Guide.

The Eclipse web site is responding slowly as I'm typing this. You can also access the Help from inside of Eclipse Helios.

Help -> Help Contents
旧人哭 2024-10-25 05:26:23

我清楚地知道你能做什么。首先,您可以打开unicode字符集。这将允许您使用希腊语等变量,从而使代码更具可读性。 [常规->工作空间->文本编码 = UTF-8]。

// Apply spring soft constraint using Erin Catto's method with Semi-Implicit Euler :
// Figure out (ω,ζ) from node sizes, then k=mEff.ω², c=2.mEff.ω.ζ 
double ω = 2.0*π*f;         // ω (angular frequency) 
double k = meff * ω*ω;      // spring stiffness 
double ζ = (b1.ζ + b2.ζ)/2;         // Average out the damping coefficients
double d = 2.0 * meff * ω * ζ;  // damping coefficient
double γ=h*(d+h*k);             // CFM (Constraint Force Mixing)

其次,您建议在代码中显示 LaTeX 公式也是下一个最好的事情。我知道这是可能的,因为我三年前写了一篇,但我在任何地方都找不到代码。我曾将其发布在 Eclipse 插件论坛上,但现在已经消失了。
好消息是我正在再次写它,因为我需要它 - 这就是我找到你的帖子的方式。这次我使用的是 jlatexmath,它比我上次使用的要好。
这个想法是/是,您可以将公式作为 LaTeX 嵌入到注释中,并且当您将鼠标悬停在工具提示上时,插件会在工具提示中呈现 LaTeX。

完成后我会在这里发布链接或代码。大部分工作是弄清楚如何让 Eclipse 接受新的悬停控件。
京东

I know exactly what you can do. First, you can turn-on the unicode character set. This will allow you to have variables such as greeks, which makes the code much more readable. [General->WorkSpace->Text Encoding = UTF-8].

// Apply spring soft constraint using Erin Catto's method with Semi-Implicit Euler :
// Figure out (ω,ζ) from node sizes, then k=mEff.ω², c=2.mEff.ω.ζ 
double ω = 2.0*π*f;         // ω (angular frequency) 
double k = meff * ω*ω;      // spring stiffness 
double ζ = (b1.ζ + b2.ζ)/2;         // Average out the damping coefficients
double d = 2.0 * meff * ω * ζ;  // damping coefficient
double γ=h*(d+h*k);             // CFM (Constraint Force Mixing)

Second, your suggestion to have a LaTeX formula visible within the code is also the next best thing. I know it's possible because I wrote one 3 years ago, but I can't find the code anywhere. I had posted it on a forum for eclipse plug-ins but it's gone now.
The good news is that I'm writing it again, because I need it - that's how I found your post . This time I'm using jlatexmath which is better than what I used last time.
The idea was/is that you can embed a formula in a comment as LaTeX, and the plug-in renders the LaTeX in a tooltip when you hover on it.

I'll post a link or code here when I'm done. Most of the work is figuring out how to make eclipse accept the new hover control.
J.D.

紫罗兰の梦幻 2024-10-25 05:26:23

好的,作为我上面帖子的后续内容,这里是我为此开发的 Eclipse 插件开发环境 (PDE) 项目。该插件名为 LaTeXHover,每当您将鼠标悬停在包含 LaTeX 的注释行顶部时,都会弹出一个工具提示,例如:

// $latex i\hbar\frac{\partial}{\partial t}\left| \Psi(t)\right>=H\left|\Psi(t)\right>$
// $latex x=\frac{-b \pm \sqrt{b^2-4ac}}{2a}$

LaTeX 必须使用 $latex 和 $ 进行分隔,不得有多余的空格。
它使用 jlatexmath 进行渲染。

我将尝试更好地打包该插件并将其添加到 Git 存储库,并且可能将其贡献给 Eclipse 插件项目之一。和上次一样,我现在没有时间这样做,但至少现在它就在那里。欢迎任何希望从这里继续该项目的人这样做。
京东

git://github.com/jdbertron/latexhover.git

Ok, as a follow-up to my post above, here is the Eclipse Plug-In Development Environment (PDE) project I developed for this. The Plug-in is named LaTeXHover and will pop-up a tooltip whenever you hover on top of a comment line that contains LaTeX such as:

// $latex i\hbar\frac{\partial}{\partial t}\left|\Psi(t)\right>=H\left|\Psi(t)\right>$
// $latex x=\frac{-b \pm \sqrt{b^2-4ac}}{2a}$

The LaTeX must be delimited using $latex and $ with no extra spaces.
It uses jlatexmath for rendering.

I'll try to package the plug-in better and add that to the Git repo, and maybe contribute it to one of the Eclipse Plug-In projects. As last time, I don't have time now to do this, but at least it's out there now. Anyone wishing to continue the project from here is welcome to do so.
J.D.

git://github.com/jdbertron/latexhover.git
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文