Eclipse 插件:TextSelection 无法解决
我正在尝试开发我的第一个插件。
插件应操作活动文本编辑器中所选文本的内容。
我从“备忘单”中的“hello world”示例开始,效果非常好。
当尝试修改时,我发现该项目无法识别许多类型。
我将以下 jar 添加到项目构建路径库中:
- org.eclipse.jface.text_3.5.1.r351_v20090708-0800.jar
- org.eclipse.text_3.5.0.v20090513-2000.jar
- org.eclipse.ui.editors_3.5.0.v20090527-2000.jar
现在代码编译完美。
ISelection iSelection = null;
IEditorSite iEditorSite = window.getActivePage().getActiveEditor().getEditorSite();
if (iEditorSite != null) {
- <代码> ISelectionProvider iSelectionProvider = iEditorSite.getSelectionProvider(); <代码>
- if (iSelectionProvider != null) <代码>
- {
iSelection = iSelectionProvider.getSelection();
selectedText = ((ITextSelection)iSelection).getText();
}
}
问题在第 08 行。虽然 Eclipse 识别 ITextSelection 接口,但在运行时我得到无法解析类型异常。
尝试部署代码时,我在部署日志中收到以下行:
无法解析导入 org.eclipse.jface.text
I am trying to develop my first plug-in.
The plug-in should manipulate the content of the selected text in the active text editor.
I started with the “hello world” example from the “Cheat sheet” which worked perfect.
When tried to modify I found that project not recognizing many types.
I added the following jars to the project build path libraries:
- org.eclipse.jface.text_3.5.1.r351_v20090708-0800.jar
- org.eclipse.text_3.5.0.v20090513-2000.jar
- org.eclipse.ui.editors_3.5.0.v20090527-2000.jar
Now code compiles perfect.
ISelection iSelection = null;
IEditorSite iEditorSite = window.getActivePage().getActiveEditor().getEditorSite();
if (iEditorSite != null) {
ISelectionProvider iSelectionProvider = iEditorSite.getSelectionProvider();
if (iSelectionProvider != null)
{
iSelection = iSelectionProvider.getSelection();
selectedText = ((ITextSelection)iSelection).getText();
}
}
The problem is in line 08. although eclipse recognize the ITextSelection interface, at runtime I get cannot resolve type exception.
When trying to deploy the code I get the following line in the deploy log:
The import org.eclipse.jface.text cannot be resolved
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试在“运行配置”对话框中打开“插件”选项卡并单击“添加所需插件”按钮?
它可能会为您添加正确的运行时依赖项。
另请参阅插件的依赖项选项卡中的相同按钮项目:
替代文本 http://www.vogella.de/articles/RichClientPlatform/ images/product50.gif
(更多信息请参见文章“产品和品牌”)
另请参阅此SO答案以进行更多检查。
Did you try, in the Run configuration dialog, to open the "Plugins" tab and click the button "add required plug-ins" ?
It might add the right runtime dependencies for you.
See also that same button in the dependencies tab of your plugin project:
alt text http://www.vogella.de/articles/RichClientPlatform/images/product50.gif
(more in the article "Products and Branding")
See also this SO answer for more checks.