Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
684 views
in Technique[技术] by (71.8m points)

intellij idea - Code style formatting without google-java-format plugin

Please tell me how to use code style formatting in IDEA?

I used the google-java-format plugin and it works very well for me.

An example of my code using the google-java-format plugin:

public Single<MonetaryAmount> calculateInterest(Status status, Account account) {
    var accountId = account.getKey().getRootId();
    return signIn
        .resolve(param1, param2, param3, param4, param5)
        .flatMap(
            loginPeriod ->
                findBalances(
                        lowestPeriodStartDate(loginPeriod, accountId),
                        highestPeriodEndDate(loginPeriod, accountId),
                        status.getStatusDetails().getLoginConfiguration(),
                        accountId)
                    .map(balances -> getInterestAccountBalance(balances, status.getSource()))
                    .flatMap(
                        accountBalance ->
                            moneyCalculator.calculateBalanceMoney(accountBalance, loginPeriod)));
  }

I also decided to try intellij-java-google-style.xml, which I found on github.

I went to Preferences -> Editor -> Code Style -> Java and imported this scheme there.

In the end, I ended up like this (not very pretty):

public Single<MonetaryAmount> calculateInterest(
        Status status,
        Account account) {
        var accountId = account.getKey().getRootId();
        return signIn.resolve(param1, param2, param3,
            param4, param5)
            .flatMap(loginPeriod -> findBalances(lowestPeriodStartDate(loginPeriod, accountId),
                highestPeriodEndDate(loginPeriod, accountId),
                status.getStatusDetails().getLoginConfiguration(),
                accountId)
                .map(balances -> getInterestAccountBalance(balances,
                    status.getSource()))
                .flatMap(accountBalance -> moneyCalculator
                    .calculateBalanceMoney(
                        accountBalance,
                        loginPeriod))
            );
    }

I tried to set my own settings for tab size, indent, continuation indent - but it didn't help.

Tell me how, using your settings in IDEE, to achieve the same beautiful formatting as it happens using the google-java-format plugin?

I don't want to use a plugin.

Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...