Eclipse:垂直排列函数参数 [英] Eclipse: Lining up function arguments vertically

查看:239
本文介绍了Eclipse:垂直排列函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我输入如下方法声明:

  private void processCode(String codename,
boolean doSomethingElse,
int num_of_repeats){
}

然后点击 Ctrl + I 选择整个文件,Eclipse会弄乱函数参数的对齐这样

  private void processCode(String codename,
boolean doSomethingElse,
int num_of_repeats){
}

如何让Eclipse停止这样做? >

解决方案

按照以下步骤来实现你想要的:


  1. 打开首选项对话框(位于Windows - > Windows上的首选项或Mac上的Eclipse菜单中)

  2. 转到Java>代码样式>格式化器在树中该left

  3. 您将看到活动的格式化程序配置文件。您可以使用编辑...按钮进行编辑。单击

  4. 转到换行选项卡,选择左下方的方法声明>参数。

  5. 左下角您看到参数设置组。将线包装策略设置为包装所有元素,除非第一个元素(如果不需要))。将缩进策略设置为缩进列。

  6. 通过单击确定关闭所有对话框。



<你现在应该有你想要的行为。如果它符合您的需要,您可能也希望为构造函数参数应用相同的设置。


I'm running Eclipse 3.7.2 on Windows 7 professional.

If I type a method declaration like this:

private void processCode(String codename,
                         boolean doSomethingElse,
                         int num_of_repeats){
}

Then hit Ctrl + I with the whole file selected, Eclipse will mess up the alignment of the function arguments like this

private void processCode(String codename,
     boolean doSomethingElse,
     int num_of_repeats){
}

How can I get Eclipse to stop doing that?

解决方案

Follow these steps to achieve what you want:

  1. Open the preferences dialog (located in Windows -> Preferences on Windows/Linux or in the Eclipse menu on Mac).
  2. Go to Java > Code Style > Formatter in the tree on the left
  3. You see the active formatter profile. You can edit it using the "Edit ..." button. Click that.
  4. Go to the tab "Line Wrapping", select "Method Declarations" > "Parameters" on the lower left.
  5. On the bottom left you see the "Settings for parameters" group. Set the Line wrapping policy to "Wrap all elements, except first element if not necessary". Set the Indentation policy to "Indent on column".
  6. Close all dialogs by clicking ok.

You should now have the behavior you intended. If it fits your needs, you might want to apply the same settings for constructor parameters as well.

这篇关于Eclipse:垂直排列函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆