Search code examples
javaintellij-ideaindentation

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. 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. I want both of them to be below configProvider. IntelliJ automatically adds the indentation when I add a new parameter to this().

    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());
    }

Solution

  • Indent versus Continuation Indent settings

    Yes, IntelliJ offers indentation settings for continuation of a statement as well as for nested statements.

    The default in IntelliJ is a convention used across much of the industry, twice width of indenting for continuation as for nesting.

    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.

    Screenshot of IntelliJ > Preferences > Editor > Code Style > Java > Tabs and Indents > Indent field, versus Continuation Indent field.