Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij code style setting for wrapping on multi line function arguments

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) 
like image 708
WestCoastProjects Avatar asked Feb 10 '15 07:02

WestCoastProjects


People also ask

How do I fix code style in IntelliJ?

In the editor, select a code fragment you want to reformat. Before reformatting, you can take a look at the code style settings that are applied to the selected code: press Alt+Enter and click Adjust code style settings. From the main menu, select Code | Reformat Code or press Ctrl+Alt+L .

How do I change the indentation level in IntelliJ?

Open indentation settings in code style scheme Click the widget and select Configure Indents for 'Language'. In the dialog that opens, you can change settings for tabs and indents and also configure other code style settings. Click OK. Reformat the necessary part of your project to apply new indentation settings.

What are smart tabs IntelliJ?

IDEA has a “smart tabs” option that you can turn on: If this check box is selected, IntelliJ IDEA inserts tabs for indentation and reformatting, but fine alignment to a necessary column is done only via spaces. This is done in order to preserve visual representation of the source code, when the Tab Size is changed.

How do I import code style into IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. and select Import Scheme. Then select the necessary format. In the dialog that opens, select the file with the settings and click Open.


2 Answers

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

like image 110
yole Avatar answered Nov 02 '22 20:11

yole


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

like image 39
Kaushal Avatar answered Nov 02 '22 19:11

Kaushal