Eclipse plugin 使用K_未知的CodeFormatter返回null

Eclipse plugin 使用K_未知的CodeFormatter返回null,eclipse-plugin,eclipse-jdt,Eclipse Plugin,Eclipse Jdt,在Eclipse Mars 4.5.1中尝试此代码: 相关部分: Map options=DefaultCodeFormatterConstants.getEclipseDefaultSettings(); options.put(JavaCore.COMPILER_COMPLIANCE,JavaCore.VERSION_1_5); options.put(JavaCore.COMPILER\u CODEGEN\u TARGET\u平台,JavaCore.VERSION\u 1\u 5); o

在Eclipse Mars 4.5.1中尝试此代码:

相关部分:

Map options=DefaultCodeFormatterConstants.getEclipseDefaultSettings();
options.put(JavaCore.COMPILER_COMPLIANCE,JavaCore.VERSION_1_5);
options.put(JavaCore.COMPILER\u CODEGEN\u TARGET\u平台,JavaCore.VERSION\u 1\u 5);
options.put(JavaCore.COMPILER\u源代码,JavaCore.VERSION\u 1\u 5);
CodeFormatter CodeFormatter=ToolFactory.createCodeFormatter(选项);
字符串源=。。。;
text编辑=codeFormatter.format(
CodeFormatter.K_编译单元,
来源:,
0,
source.length(),
0,
System.getProperty(“line.separator”)
);
它可以像那样工作,但是当我改为
CodeFormatter.K_UNKNOWN
而不是
CodeFormatter.K_编译单元
时,它停止工作-
edit
null
。我认为这在Eclipse的早期版本中可以正常工作


由于我不知道在调用format方法时得到的字符串是什么类型,有没有任何方法可以使用
K_UNKNOWN

“我认为这很好用”-您是否尝试使用早期版本运行代码?您可以发布源代码吗?我用4.5.1和
source=“Integer foo=new Integer(12);”
K_UNKNOWN
做了一个快速测试,结果成功了(即返回文本编辑,删除括号前/后的空格)