是否可以找出在 Eclipse 编辑器中编写的代码是否有效以及相应的 disable/enable 上下文菜单按钮?

Is it possible to find out whether the code written in Eclipse editor is valid and disable/enable context menu button accordingly?

我正在为我的 DSL 创建 Eclipse 插件,使用 Xtext 并需要为我的编辑器添加上下文菜单项(我已经做了),但需要查明编辑器中的代码是否有效,如果是 - > 这个菜单项应该启用,否则禁用。是否可以通过某种方式检查整个代码是否有效并相应地更新此上下文菜单项的状态? 我通过将此片段添加到 Xtext 中 .ui 项目中的 plugin.xml 文件来添加此上下文菜单项。

<extension point="org.eclipse.ui.menus">
        <menuContribution locationURI="popup:#TextEditorContext?after=additions">
            <command commandId="org.first.langu.ui.handler.InterpreterCommand" style="push">
                <enabledWhen checkEnabled="true">
                    <reference definitionId="org.first.langu.Program.XtextEditor.opened"/>
                </enabledWhen>
            </command>
        </menuContribution>
    </extension>
    <extension point="org.eclipse.ui.commands">
        <command id="org.first.langu.ui.handler.InterpreterCommand" name="Interpret Code"/>
    </extension>
    <extension point="org.eclipse.ui.handlers">
        <handler
                class="org.first.langu.ui.ProgramExecutableExtensionFactory:org.first.langu.ui.handler.InterpretCodeHandler"
                commandId="org.first.langu.ui.handler.InterpreterCommand"/>
    </extension>

基本上我需要检查编辑器中的代码是否有效,而不是是否刚打开编辑器。

您可以使用编辑器注释模型来查找是否有任何错误。 见 org.eclipse.xtext.ui.editor.XtextEditorErrorTickUpdater.getSeverity(XtextEditor) 有关如何检索和过滤注释的示例。如果有错误

,class用于在编辑器图标中显示红色x