34

The Spark code style requires four character indentation for multi parameter methods. So: the following code -as presently formatted by IJ - is incorrect:

def generateCirclesRdd(sc: SparkContext,
                       nCircles: Int = 3,
                       nTotalPoints: Int = 30,
                       outerRadius: Double): RDD[(Long, Long, Double)] = {

It should apparently be:

def generateCirclesRdd(sc: SparkContext,
    nCircles: Int = 3,
    nTotalPoints: Int = 30,
    outerRadius: Double): RDD[(Long, Long, Double)] = {

Where is this setting in the IJ code style? Screenshot shows what I was able to find.

enter image description here

UPDATE There is a comment about "Tabs and Indents" here it is :

enter image description here

Another Update: @yole has provided a helpful answer. However, I am still left with 2 spaces instead of 4 on the continuation.

For reference, here is the correct/required indentation within Spark. Notice the continuation on method declarations is 4 spaces.

  def train(
      data: RDD[Vector],
      k: Int,
      maxIterations: Int,
      runs: Int,
      initializationMode: String,
      seed: Long): KMeansModel = {

However the continuation on method invocations is only two:

    new KMeans().setK(k)
      .setMaxIterations(maxIterations)
      .setRuns(runs)
      .setInitializationMode(initializationMode)
      .setSeed(seed)
      .run(data)
4
  • I would guess that the option you need is "Use normal indent for parameters".
    – yole
    Feb 10, 2015 at 7:42
  • Nice idea: unfortunately that change had no effect. Feb 10, 2015 at 7:44
  • Chek Tabs and Indents tab on the left top corner Feb 10, 2015 at 7:48
  • @deathangel908 Updated OP with it - not much here.. Feb 10, 2015 at 7:53

5 Answers 5

37

Uncheck "Method declaration parameters | Align when multiline" and enable "Use normal indent for parameters".

5
  • This is close: we need 4 spaces for the indentation and not two. I am updating the OP. Feb 10, 2015 at 15:14
  • I gave an upvote to indicate your answer is at least a step in the right direction. Feb 10, 2015 at 15:20
  • If you need 4 spaces, then disable "Use normal indent for parameters".
    – yole
    Feb 10, 2015 at 19:28
  • 6
    I don't see a "Use normal indent for parameters" setting in IJ 2017 Mar 10, 2017 at 14:00
  • 1
    Changed correct answer to the next one simply due to versioning changes . Jun 14, 2019 at 17:51
21

There is two option that you have to change

  1. Uncheck Method declaration parameters | Align when multiline

enter image description here

  1. Check other | Alternate indentation for constructor args and parameter declarations with 4 spaces

enter image description here

2
  • would you pls post a screenshot? i am on a different version of IJ Jan 30, 2018 at 14:15
  • This was the right answer for me, 2017.3.3. Thank you!!
    – A.Wan
    Apr 25, 2018 at 19:09
6

In 2017, Check all the Settings/Editor/CodeStyle/Java/Wrapping and Braces options, where the line name is Allign when multiline. For me, it was checked at Chained Method calls, and that made these long indents. Just uncheck them.

1
  • YES! IntelliJ was driving me insane, been looking to solve this one for quite a while. Thank you
    – Aurelio
    Jan 26, 2018 at 16:43
3

enable "other | Alternate indentation for constructor args and parameter declarations with 4 spaces" help me out finally

2
  • with "Tabs and Indents | 2 2 2"
    – huali
    Jun 5, 2017 at 12:11
  • by the way ,this is really wired indentaion format.
    – huali
    Jun 5, 2017 at 12:15
0

This is that worked for me:

  • Enable "Align when multiline"
  • Enable "Use normal indent for parameters"
  • All other options "Method declaration parameters" are disabled

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.