gpt4 book ai didi

java - 以编程方式将 Eclipse 格式化程序配置文件 XML 导出到 .prefs

转载 作者:行者123 更新时间:2023-11-30 06:09:24 26 4
gpt4 key购买 nike

我的团队使用 Eclipse 配置文件 XML 文件中定义的代码格式约定,如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="This Team's Formatting Convention" version="12">
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
...

我使用 eclipse 作为命令行格式化程序,使用如下命令:

eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter \
-config ${JAVA_FORMATTER_CONFIG_FILE} ${*}

仅当 ${JAVA_FORMATTER_CONFIG_FILE} 是 Eclipse 首选项文件,其文件名类似于 org.eclipse.jdt.core.prefs 且内容为:

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

如何以编程方式获取 .prefs 文件,而无需从 eclipse UI 手动导入 XML 配置文件?

最佳答案

来自 Eclipse Oxygen 工作台,

  • 导出当前首选项:文件 -> 导出 -> 首选项
  • 选择“Java 代码样式首选项”
  • 选择名称和目的地并保存(似乎必须使用 .epf 扩展名)

该文件将包含(除其他外)自定义格式配置

/instance/org.eclipse.jdt.ui/formatter_profile=_my-java-formatter
/instance/org.eclipse.jdt.ui/formatter_settings_version=13
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.formatterprofiles=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\n<profiles version\="13">\n<profile kind\="CodeFormatterProfile" name\="my-java-formatter" version\="13">\n...
...

然后您可以运行格式化程序

eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -config eclipse-formatter.epf Test.java

输出:

org.eclipse.m2e.logback.configuration: The org.eclipse.m2e.logback.configuration bundle was activated before the state location was initialized.  Will retry after the state location is initialized.
org.eclipse.m2e.logback.configuration: Logback config file: /home/luis/eclipse-workspace/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.8.3.20180227-2137.xml
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [bundleresource://496.fwk1538849250:1/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [bundleresource://496.fwk1538849250:2/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
org.eclipse.m2e.logback.configuration: Initializing logback
Configuration Name: eclipse-formatter.epf
Starting format job ...
Done.

首选项导出完成一次,然后您就可以分享eclipse-formatter.epf文件。希望有帮助。

关于java - 以编程方式将 Eclipse 格式化程序配置文件 XML 导出到 .prefs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50592418/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com