Eclipse代码样式格式化程序可以对齐赋值语句吗

Eclipse代码样式格式化程序可以对齐赋值语句吗

本文介绍了Eclipse代码样式格式化程序可以对齐赋值语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Eclipse中有一个Indentation选项:在类声明中对齐字段,
对齐类成员的赋值:

  class Foo {
int x = 3;
String y =abc
long z = 2;




$ p
$ b

是否有一个设置可以完成方法级别的赋值:

  private void foo(){
int x = 3;
String y =abc
long z = 2;
}

我找不到这样的设置。在Eclipse中没有这样的选项,但是如前所述,它将所选代码片段中的赋值和声明对齐。




  • 安装:下载最新版本的OCDFormat_ * .jar从(点击→Raw→另存为),并将其添加到Eclipse插件或dropins目录。

  • 用法:选择一段代码并按下Ctrl + 4。


>

Eclipse has an option in Indentation: "Alignment of fields in class declarations" that willalign assignments of class members as in:

class Foo {
   int x    = 3;
   String y = "abc"
   long z   = 2;
}

Is there a setting that will do the same for method level assignments as in:

private void foo() {
   int x    = 3;
   String y = "abc"
   long z   = 2;
}

I can not find such a setting.

解决方案

For future visitors.

There is no such option in Eclipse, but, as mentioned here, you can use plugin named OCDFormat that aligns assignments and declarations in a selected piece of code.

  • Installation: download the latest version of OCDFormat_*.jar from project page on github (click → Raw → Save as) and add it to your Eclipse plugins or dropins directory.

  • Usage: select a piece of code and press Ctrl+4.

这篇关于Eclipse代码样式格式化程序可以对齐赋值语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 00:48