从新的文件向导以编程方式触发Eclipse的代码格式化程序 [英] Trigger Eclipse's code formatter programmatically from a new file wizard

查看:305
本文介绍了从新的文件向导以编程方式触发Eclipse的代码格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用向导( org.eclipse.jface.wizard.Wizard )编写一个Eclipse插件,该向导会创建一个带有基本代码模板的新文件。为了简化文件内容的拼接在一起,我打算将所有东西都填入一个长字符串,将其注入到文件中,然后调用我的自定义Formatter(继承 org.eclipse.xtext.formatting。 impl impl??orm orm orm????????。。。。。。。。。。>>>>>>>>>>>>>>>>>>>>>>>>>>>????????
在向导中,我调用 IDE.openEditor()并返回一个句柄到一个 IEditorPart 。我可以从这里做什么?

解决方案

嗯,我找到了我的答案:

  IEditorPart编辑器= IDE.openEditor(页面,文件,真实); 
XtextEditor xed =(XtextEditor)编辑器;
((SourceViewer)xed.getInternalSourceViewer())。doOperation(ISourceViewer.FORMAT);

也许这将帮助别人寻找类似的东西!


I'm writing an Eclipse plugin with a wizard (org.eclipse.jface.wizard.Wizard) which creates a new file with a basic code template. To simplify the "piecing together" of the file contents, I plan to stuff everything into one long string, inject it into the file, and then call my custom Formatter (inherits org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter) to clean up all the indentation and so on.

Question is, how do I go about calling the formatter programmatically? In the wizard I call IDE.openEditor() and get back a handle to an IEditorPart. What can I do from here?

解决方案

Well, I have found my answer:

IEditorPart editor = IDE.openEditor(page, file, true);
XtextEditor xed = (XtextEditor)editor;
((SourceViewer)xed.getInternalSourceViewer()).doOperation(ISourceViewer.FORMAT);

Maybe that will help someone else looking for something similar!

这篇关于从新的文件向导以编程方式触发Eclipse的代码格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆