【发布时间】:2018-11-08 14:02:20
【问题描述】:
我的团队使用 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
如何在不从 eclipse UI 手动导入 XML 配置文件的情况下以编程方式获取 .prefs 文件?
【问题讨论】:
-
使用 XSLT、正则表达式或从 XML 读取 ID/值对并将其保存到属性文件中,可以轻松地将 XML 文件转换为属性文件:
<setting id="${id}" value="${value}"/>=>${id}=${value}。还是我误解了您的问题,这与将格式化程序配置文件 XML 转换为.settings/org.eclipse.jdt.core.prefs无关? -
我明白了。我不确定 XML 到 .pref 值是否有任何特殊处理或映射。
标签: java eclipse code-formatting