【问题标题】:Are there any tools in IDEs to automatically fix comment formatting?IDE 中是否有任何工具可以自动修复注释格式?
【发布时间】:2011-01-25 01:58:02
【问题描述】:
/* Suppose I have a multi-line comment with hard line-breaks
 * that are roughly uniform on the right side of the text,
 * and I want to add text to a line in order to make the
 * comment a bit more descriptive.
 */

现在,最不幸的是,我需要将文本添加到 top 行之一。

/* Suppose I have a multi-line comment with hard line-breaks (here is some added text for happy fun time)
 * that are roughly uniform on the right side of the text,
 * and I want to add text to a line in order to make the
 * comment a bit more descriptive.
 */

需要 O(n) 时间(n 是行数)来修复每一行,以便它们大致重新排列。计算机应该这样做,而不是我。

在我们的 IDE 中是否有工具来处理这个问题?他们叫什么?

【问题讨论】:

  • Polystyle 还没有这样做,但可能值得一看,它承诺用于未来的版本之一:polystyle.com/index.jsp

标签: visual-studio eclipse ide netbeans comments


【解决方案1】:

emacs 支持命令fill-paragraph,它通常映射到meta-q

fill-paragraph 在第二段文本中的输出:

/* Suppose I have a multi-line comment with hard line-breaks (here is
 * some added text for happy fun time) that are roughly uniform on the
 * right side of the text, and I want to add text to a line in order
 * to make the comment a bit more descriptive.
 */

【讨论】:

  • 可惜我没用emacs,不过貌似只有这个编辑器支持这种东西。
  • 对于我的大部分 java 开发,我使用 IntelliJ。不过,我还是会抽出 emacs 来做一些 emacs 真正擅长的任务。
【解决方案2】:

Eclipse 内置了这个(至少,我认为这是您想要的)。当您键入注释时,然后键入 Ctrl+Shift+F,它将格式化您的所有代码,或仅格式化您突出显示的代码部分。

我现在刚刚对其进行了测试,它为我对齐了我所有的 cmets。

【讨论】:

  • 我认为他正在寻找改变行长的解决方案,而不是仅仅将它们对齐,以便它们大部分在右侧对齐并且在左侧精确对齐。
  • @Jacob G - 啊,我不明白。好决定。 (似乎彼得也经历了与我相同的思考过程。)
猜你喜欢
  • 1970-01-01
  • 2010-09-17
  • 1970-01-01
  • 2012-06-05
  • 1970-01-01
  • 2022-01-16
  • 2013-06-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多