简体   繁体   English

如何在intellij中为Java纠正多行中单个语句的缩进

[英]How to correct indentation for single statement in multiple lines for java in intellij

I am trying to get my head around to get correct indentation settings in my intellij. 我正在努力使自己的intellij获得正确的缩进设置。 I have tried couple of things from here , but nothing seems to work. 我从这里尝试了几件事,但似乎没有任何效果。 As you can see, for the this() constructor, RecordWriter and AmazonS3ClientBuilder gets indented. 如您所见,对于this()构造函数, RecordWriterAmazonS3ClientBuilder会缩进。 I want both of them to be below configProvider. 我希望它们都在configProvider以下。 IntelliJ automatically adds the indentation when I add a new parameter to this(). 当我向this()添加新参数时,IntelliJ自动添加缩进。

    public MysteriousClient(final ConfigurationProvider configProvider) {
        this(configProvider,
                RecordWriter.builder().withTopicPrefix(new DefaultStackNameProvider().getStackName()).build(),
                AmazonS3ClientBuilder.defaultClient());
    }

This is how I would like it to see: 这就是我希望看到的:

    public MysteriousClient(final ConfigurationProvider configProvider) {
        this(configProvider,
             RecordWriter.builder().withTopicPrefix(new DefaultStackNameProvider().getStackName()).build(),
             AmazonS3ClientBuilder.defaultClient());
    }

Indent versus Continuation Indent settings IndentContinuation Indent设置

Yes, IntelliJ offers indentation settings for continuation of a statement as well as for nested statements. 是的,IntelliJ提供了缩进设置以用于语句的延续以及嵌套语句。

The default in IntelliJ is a convention used across much of the industry, twice width of indenting for continuation as for nesting. IntelliJ中的默认设置是在整个行业中广泛使用的约定,其缩进宽度是嵌套宽度的两倍。

As others suggested, I too suggest you keep a different setting for continuation versus indenting, as these are two very different situations. 正如其他人所建议的,我也建议您将延续和缩进设置为不同的设置,因为这是两种截然不同的情况。

But if you insist, search the indent settings for “continuation”m if I recall correctly. 但是,如果您坚持认为,如果我没记错的话,请在缩进设置中搜索“ continuation” m。

IntelliJ>首选项>编辑器>代码样式> Java>制表符和缩进>缩进字段和Continuation Indent字段的屏幕快照。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM