如何防止在XText中格式化

时间:2016-08-25 20:45:01

标签: grammar xtext

我创建了xtext项目。我没有任何Format类,但是当我按ctrl + f。

时会产生一些默认格式

我可以以什么方式阻止格式化?我建议我需要覆盖格式化程序类,但是以什么方式可以生成这个类?或者,也许我可以阻止项目设置中的默认格式化?

此致 弗拉基米尔

1 个答案:

答案 0 :(得分:0)

你可以简单地“创建”这个类

class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {

    def Class<? extends IFormatter2> bindIFormatter2() {
        Formatter2NullImpl
    }

    def void configureFormatterPreferences(Binder binder) {
        binder.bind(IPreferenceValuesProvider).annotatedWith(FormatterPreferences).to(FormatterPreferenceValuesProvider);
    }

}

class Formatter2NullImpl implements IFormatter2 {

    override format(FormatterRequest request) {
        return #[]
    }

}

@FinalFieldsConstructor
class MyDslUiModule extends AbstractMyDslUiModule {

    override Class<? extends IContentFormatterFactory> bindIContentFormatterFactory() {
        return org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory;
    }
}

或配置工作流程

language = StandardLanguage {
    ...
    formatter = {
        generateStub = true
    }
    ...
}

并编辑生成的类

相关问题