我正在通过在Eclipse CDT中编辑AST进行实用的编码,在使用Change#perform方法执行重构后,我发现要格式化的代码,例如,这里我只是将函数调用转换为空>
//Old code
Publish(Author_id, Content);
//New code
(void) Publish(
Author_id,
Content);
您看到该方法已格式化为3行,如何停止此操作?
我的代码示例可以重构
INodeFactory factory = ast.getASTNodeFactory();
IASTNode newNode = rewriter.createLiteralNode("( void )"+selectedNode.getRawSignature());
rewriter.replace(selectedNode, newNode, null);
Change change = rewriter.rewriteAST();
change = change.perform(new NullProgressMonitor());
答案 0 :(得分:0)
我相信您有两种选择:
配置CDT的内置格式化程序,以您喜欢的方式格式化代码。在这种情况下,根据“新代码”的外观,看起来行Wrapping -> Function calls -> Arguments -> Line wrapping policy
被设置为“包装所有元素”选项之一。您可以将其更改为更喜欢的名称。
实施org.eclipse.cdt.core.CodeFormatter
扩展点以提供一种替代的格式化程序,其行为与默认的代码格式化程序不同(例如,它什么也不做)。
更新:我不知道在哪里找到这样的示例,但是假设您熟悉一般实现here is the reference的Eclipse扩展点。步骤将是:
org.eclipse.cdt.core.formatter.CodeFormatter
并实现format()
方法的类<extension ...>
上引用指向您的课程的plugin.xml
标签