Eclipse格式化程序可以配置为在括号之间缩进多行吗? [英] Can the Eclipse formatter be configured to indent multiple lines between parenthesis properly?

查看:169
本文介绍了Eclipse格式化程序可以配置为在括号之间缩进多行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public static void main(String [] args){
String [] numbers = new String [] {
one,
two,
three,
four,
};

new MessageFormat({0} {1} {2} {3})。format(
this is string one,
this is string two ,
这是字符串三
);

System.out.println(
new MessageFormat({0} {1} {2} {3})。format(
new String [] {
this is string zero,
this is string one,
this is string two,
this is string three
}

);
}

我已经玩过所有可以找到的设置。 永远加入行选项不会完全屠杀代码,但即使这样,缩进也被删除,代码如下所示:

  String [] numbers = new String [] {
one,
two,
three,
four,
};

new MessageFormat({0} {1} {2} {3})。format(
this is string one,
this is string two ,
这是字符串三
);

System.out.println(
new MessageFormat({0} {1} {2} {3})。format(
new String [] {
this is string zero,
this is string one,
this is string two,
this is string three
}

);

我发现关闭这样的块的格式化的能力,如下所示:

  // @formatter:off 
String [] numbers = new String [] {
one,
两个,
三,
四,
};
// @formatter:on

哪些是一个体面的工作,除了我的代码最终与他们混在一起,代码清理的正确的缩进部分忽略了该指令,并且混淆了缩进。



编辑:我找到了Line包装 - >包装线的默认缩进和数组初始化的默认缩进,并将其设置为1而不是0。对于数组初始化器来说,这是更好的,但是仍然不会缩小匹配开头圆括号的方式,我想要它:

  public static void main(String [] args){
String [] numbers = new String [] {
one,
two,
three ,
four,
};

new MessageFormat({0} {1} {2} {3})。format(
this is string one,
this is string two ,
这是字符串三
);

System.out.println(
new MessageFormat({0} {1} {2} {3})。format(
new String [] {
this is string zero,
this is string one,
this is string two,
this is string three
}

);
}


解决方案

。如果您选择包装所有元素,新行上的每个元素,表达式/数组初始化程序和函数调用/ Qalified对象分配参数我想你会得到类似的东西$ /

Can eclipse formatter and code cleanup be configured (or extended) to add the indentation I expect in the following examples:

public static void main(String[] args) {
    String[] numbers = new String[] {
        "one",
        "two",
        "three",
        "four",
    };

    new MessageFormat("{0} {1} {2} {3}").format(
        "this is string one",
        "this is string two",
        "this is string three"
    );

    System.out.println(
        new MessageFormat("{0} {1} {2} {3}").format(
            new String[]{
                "this is string zero",
                "this is string one",
                "this is string two",
                "this is string three"
            }
        )
    );
}

I've played around with all the settings that I can find. The "never join lines" option keeps it from completely butchering the code, but even then the indentation is all stripped and the code comes out like this:

    String[] numbers = new String[] {
    "one",
    "two",
    "three",
    "four",
    };

    new MessageFormat("{0} {1} {2} {3}").format(
    "this is string one",
    "this is string two",
    "this is string three"
    );

    System.out.println(
    new MessageFormat("{0} {1} {2} {3}").format(
    new String[] {
    "this is string zero",
    "this is string one",
    "this is string two",
    "this is string three"
    }
    )
    );

I discovered the ability to turn off formatting around such blocks like this:

    // @formatter:off
    String[] numbers = new String[] {
        "one",
        "two",
        "three",
        "four",
    };
    // @formatter:on

Which is a decent work around, except that my code ends up littered with them, and the "correct indentation" part of code cleanup ignores the directive and messes up the indentation anyway.

Edit: I found the settings for "Line Wrapping" -> "Default indentation for wrapped lines" and "Default indentation for array initializes" and have set them to "1" instead of "0". That is better for the array initializers, but still doesn't indent closing parethesis to match the opening parenthesis the way that I want it to:

public static void main(String[] args) {
    String[] numbers = new String[] {
        "one",
        "two",
        "three",
        "four",
    };

    new MessageFormat("{0} {1} {2} {3}").format(
        "this is string one",
        "this is string two",
        "this is string three"
        );

    System.out.println(
        new MessageFormat("{0} {1} {2} {3}").format(
            new String[] {
                "this is string zero",
                "this is string one",
                "this is string two",
                "this is string three"
            }
            )
        );
}

解决方案

Did you check line wrapping tab. if you select "Wrap all elements, every element on a new line" for Expressions/Array Initializers and Function Calls/Qalified object allocation arguments I think you will get something similar

这篇关于Eclipse格式化程序可以配置为在括号之间缩进多行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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