IntelliJ IDEA code style settings for Square's Java and Android projects.
- Run the
install.sh
script. - Restart IntelliJ if it's running.
- Open IntelliJ/AS Project Settings -> Code Styles, change the code style for the project to the one you want.
Code styles changes from the AS default ones ------------------------------------------------ ### CesardsAndroid
#### Code Styles
Indents Detection
-
✓ Detect and use existing file indents for editing
<option name="AUTODETECT_INDENTS" value="true" />
-
Tab size: 2 / Indent: 2 / Continuation indent: 4
<indentOptions> <option name="INDENT_SIZE" value="2" /> <option name="CONTINUATION_INDENT_SIZE" value="4" /> <option name="TAB_SIZE" value="2" /> </indentOptions>
▼__Before Left Brace__
-
✓ Array initializer left brace
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
int[] empty = new int[] {};
▼ Within
-
✓ Code braces
<option name="SPACE_WITHIN_BRACES" value="true" />
interface Abba { }
-
✓ Array initializer braces
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
@SuppressWarnings({ "ALL" })
▼ Keep when reformatting
-
✗ Comment at first column
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
// todo something
-
✓ Simple methods in one line
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
public void foo1(int i1, int i2, int i3, int i4, int i5, int i6, int i7) {}
-
✓ Simple classes in one line
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
new Object() {};
▼ Extends / implements list ⇨ Wrap if long
<option name="EXTENDS_LIST_WRAP" value="1" />
public class ThisIsASampleClass extends
C1 implements I1, I2, I3, I4,
I5 {
-
Extends / implements keyword ⇨ Wrap if long
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
public class ThisIsASampleClass extends C1 implements I1, I2, I3, I4, I5 {
▼ Throws list ⇨ Wrap if long
<option name="THROWS_LIST_WRAP" value="1" />
public static void longerMethod() throws
Exception1, Exception2,
Exception3 {
-
Throws keyword ⇨ Wrap if long
<option name="THROWS_KEYWORD_WRAP" value="1" />
public static void longerMethod() throws Exception1, Exception2, Exception3 {
▼ Method declaration parameters ⇨ Chop down if long
<option name="METHOD_PARAMETERS_WRAP" value="5" />
public void foo1(int i1,
int i2,
int i3,
int i4,
int i5,
int i6,
int i7) {
-
✓ New line after '('
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
public void foo1( int i1, int i2, int i3, int i4, int i5, int i6, int i7) {}
-
✓ Place ')' on new line
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
public void foo1( int i1, int i2, int i3, int i4, int i5, int i6, int i7 ) {}
▼ Method call arguments ⇨ Chop down if long
<option name="CALL_PARAMETERS_WRAP" value="5" />
foo1(0x0051,
0x0052,
0x0053,
0x0054,
0x0055,
0x0056,
0x0057);
-
✓ New line after '('
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
foo1( 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057);
-
✓ Place ')' on new line
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
foo1( 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057 );
▼ Chained method calls ⇨ Chop down if long
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
super.getFoo()
.foo()
.getBar()
.bar();
▼ if()
statement
-
Force braces ⇨ Always
<option name="IF_BRACE_FORCE" value="3" />
if (2 < 3) { return; } else if (2 > 3) { return; } else { return; }
▼ for()
statement ⇨ Wrap if long
<option name="FOR_STATEMENT_WRAP" value="1" />
for (int i = 0; i < 0xFFFFFF;
i += 2)
-
✗ Align when multiline
<option name="ALIGN_MULTILINE_FOR" value="false" />
for (int i = 0; i < 0xFFFFFF; i += 2)
-
Force braces ⇨ Always
<option name="FOR_BRACE_FORCE" value="3" />
for (int i = 0; i < 0xFFFFFF; i += 2) { System.out.println(i); }
-
✓ New line after '('
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
for ( int i = 0; i < 0xFFFFFF; i += 2) {
-
✓ Place ')' on new line
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
for ( int i = 0; i < 0xFFFFFF; i += 2 ) {
▼ while()
statement
-
Force braces ⇨ Always
<option name="WHILE_BRACE_FORCE" value="3" />
while (x < 50000) { x++; }
▼ do { } while()
statement
-
Force braces ⇨ Always
<option name="DOWHILE_BRACE_FORCE" value="3" />
do { x++; } while (x < 10000);
▼ try-with-resources ⇨ Wrap if long
<option name="RESOURCE_LIST_WRAP" value="1" />
try (MyResource r1 = getResource();
MyResource r2 = null) {
doSomething();
}
-
✓ New line after '('
<option name="RESOURCE_LIST_LPAREN_ON_NEXT_LINE" value="true" />
-
✓ Place ')' on new line
<option name="RESOURCE_LIST_RPAREN_ON_NEXT_LINE" value="true" />
try ( MyResource r1 = getResource(); MyResource r2 = null ) {
▼ Binary expressions ⇨ Wrap if long
<option name="BINARY_OPERATION_WRAP" value="1" />
int x = (3 + 4 + 5 + 6) *
(7 + 8 + 9 + 10) *
(11 + 12 + 13 + 14 +
0xFFFFFFFF);
assert i + j + k + l + n +
m <=
2 : "assert description";
int y = 2 > 3 ?
7 + 8 + 9 :
11 + 12 + 13;
-
✓ Operation sign on next line
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
int x = (3 + 4 + 5 + 6) * (7 + 8 + 9 + 10) * (11 + 12 + 13 + 14 + 0xFFFFFFFF); assert i + j + k + l + n + m <= 2 : "assert description";
-
✓ New line after
{
<option name="PARENTHESES_EXPRESSION_LPAREN_WRAP" value="true" />
int x = (3 + 4 + 5 + 6) * ( 7 + 8 + 9 + 10) * ( 11 + 12 + 13 + 14 + 0xFFFFFFFF);
-
✓ Place
}
on new line<option name="PARENTHESES_EXPRESSION_RPAREN_WRAP" value="true" />
int x = (3 + 4 + 5 + 6) * ( 7 + 8 + 9 + 10 ) * ( 11 + 12 + 13 + 14 + 0xFFFFFFFF );
▼ Assignment statement ⇨ Wrap if long
<option name="ASSIGNMENT_WRAP" value="1" />
int[] a =
new int[]{1, 2, 0x0052, 0x0053, 0x0054};
-
✓ Assignment sign on next line
<option name="PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE" value="true" />
int[] a = new int[]{1, 2, 0x0052, 0x0053, 0x0054};
▼ Ternary operation ⇨ Wrap if long
<option name="TERNARY_OPERATION_WRAP" value="1" />
int y = 2 > 3 ? 7 + 8 + 9 :
11 + 12 + 13;
-
✓
?
and:
signs on next line<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
int y = 2 > 3 ? 7 + 8 + 9 : 11 + 12 + 13;
▼ Array initializer ⇨ Wrap always
<option name="ARRAY_INITIALIZER_WRAP" value="2" />
int[] a = new int[]{1,
2,
0x0052,
0x0053,
0x0054};
-
✓ New line after
{
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
int[] a = new int[]{ 1, 2, 0x0052, 0x0053, 0x0054 };
-
✓ Place
}
on new line<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
int[] a = new int[]{1, 2, 0x0052, 0x0053, 0x0054 };
▼ Assert statement ⇨ Wrap if long
<option name="ASSERT_STATEMENT_WRAP" value="1" />
assert i + j + k + l + n + m <= 2 :
"assert description";
-
✓
:
signs on next line<option name="ASSERT_STATEMENT_COLON_ON_NEXT_LINE" value="true" />
assert i + j + k + l + n + m <= 2 : "assert description";
Enums constants ⇨ Wrap always
<option name="ENUM_CONSTANTS_WRAP" value="2" />
enum Breed {
Dalmatian(),
Labrador(),
Dachshund()
}
Parameter annotations ⇨ Wrap if long
<option name="PARAMETER_ANNOTATION_WRAP" value="1" />
public void method(@Annotation1
@Annotation3(param1 = "value1", param2 = "value2")
final int param) {
Local variable annotations ⇨ Wrap always
<option name="VARIABLE_ANNOTATION_WRAP" value="2" />
@Annotation1
@Annotation3(param1 = "value1", param2 = "value2")
final int localVariable;
▼ Annotation parameters ⇨ Chow down if long
<option name="ANNOTATION_PARAMETER_WRAP" value="5" />
@Annotation3(param1 = "value1",
param2 = "value2")
In declarations ⇨ 1
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
public class Foo {
private int field1;
private int field2;
}
In code ⇨ 1
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
if (places != null && !places.isEmpty()) {
placeModelCollection = new ArrayList<>();
for (Place place : places) {
placeModelCollection.add(transform(place));
}
}
Before }
⇨ 0
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value
F438
span>="0" />
public void foo1() {
new Runnable() {
public void run() {
}
};
}
Around method interface ⇨ 0
<option name="BLANK_LINES_AROUND_METHOD_IN_INTERFACE" value="0" />
interface TestInterface {
int MAX = 10;
int MIN = 1;
void method1();
void method2();
}
▼ Alignment
-
✗ Align parameter descriptions
<option name="JD_ALIGN_PARAM_COMMENTS" value="false" />
/** * @param i short named parameter description * @param longParameterName long named parameter description * @param missingDescription */
-
✗ Align thrown exception descriptions
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" />
/** * @throws XXXException description. * @throws YException description. * @throws ZException */
▼ Blank lines
-
✓ After parameter descriptions
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
/** * @param missingDescription * * @return return description. */
-
✓ After return tag
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
/** * @param missingDescription * * @return return description. * * @throws XXXException description. */
▼ Invalid tags
-
✗ Keep empty
@param
tags<option name="JD_KEEP_EMPTY_PARAMETER" value="false" />
-
✗ Keep empty
@return
tags<option name="JD_KEEP_EMPTY_RETURN" value="false" />
-
✗ Keep empty
@throws
tags<option name="JD_KEEP_EMPTY_EXCEPTION" value="false" />
▼ Other
-
✓ Wrap at right margin
<option name="WRAP_COMMENTS" value="true" />
/** * This is a method description that is * long enough to exceed right margin. * <p> * Another paragraph of the description * placed after blank line. * <p> * Line with manual line feed. */
-
✗ Generate
<p/>
on empty lines<option name="JD_P_AT_EMPTY_LINES" value="false" />
/** * This is a method description that is * long enough to exceed right margin. * * Another paragraph of the description * placed after blank line. * * Line with manual line feed. */
-
✗ Do not wrap one line comments
<option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true" />
/** One-line comment */ public abstract String sampleMethod2();
-
✓ Preserve line feeds
<option name="JD_PRESERVE_LINE_FEEDS" value="true" />
/** * Another paragraph of the description * placed after blank line. * <p/> * Line with manual * line feed. */
Class count to use import with *
⇨ 999
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
Names count to use static import with *
⇨ 999
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
Import Layout
<package name="android" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
<package name="junit" withSubpackages="true" static="false" />
<package name="net" withSubpackages="true" static="false" />
<package name="org" withSubpackages="true" static="false" />
<package name="java" withSubpackages="true" static="false" />
<package name="javax" withSubpackages="true" static="false" />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
import android.*
import com.*
import junit.*
import net.*
import org.*
import java.*
import javax.*
import all other imports
<blank line>
import static all other imports
Grouping rules
-
✓ Keep getters and setters together
<group> <type>GETTERS_AND_SETTERS</type> <order>KEEP</order> </group>
-
✓ Keep overriden methods together (keep order)
<group> <type>OVERRIDDEN_METHODS</type> <order>KEEP</order> </group>
Final Modifier
-
✓ Make generated local variables final
<option name="GENERATE_FINAL_LOCALS" value="true" />
Comment Code
-
✗ Line comment at first column
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
-
✗ Block comment at first column
<option name="BLOCK_COMMENT_AT_FIRST_COLUMN" value="false" />
Default Visibility
-
✓ Package local
<option name="VISIBILITY" value="packageLocal" />
-
Tab size: 2 / Indent: 2 / Continuation indent: 4
<indentOptions> <option name="INDENT_SIZE" value="2" /> <option name="TAB_SIZE" value="2" /> </indentOptions>
✓ Keep line breaks
<option name="XML_KEEP_LINE_BREAKS" value="true" />
Keep blank lines ⇨ 1
<option name="XML_KEEP_BLANK_LINES" value="1" />
<application-components>
<description>Our product makes development a real
pleasure. It decreases the time you spend on routine,
repetitive.
</description>
</application-components>
Wrap attributes ⇨ Wrap always
<option name="XML_ATTRIBUTE_WRAP" value="2" />
<option name="workspace"
value="true"/>
✗ Align attrivutes
<option name="XML_ALIGN_ATTRIBUTES" value="false" />
<option name="workspace"
value="true"/>
Spaces
-
✗ In empty tag
<option name="XML_SPACE_INSIDE_EMPTY_TAG" value="false" />
<option name="workspace"/>
Layout Files
-
✗ Insert blank line before tag
<option name="LAYOUT_SETTINGS"> <value> <option name="INSERT_BLANK_LINE_BEFORE_TAG" value="false" /> </value> </option>
Other XML resource files
-
✗ Insert line break before first attribute
<option name="OTHER_SETTINGS"> <value> <option name="INSERT_LINE_BREAK_BEFORE_FIRST_ATTRIBUTE" value="false" /> </value> </option>
-
Tab size: 2 / Indent: 2 / Continuation indent: 4
<indentOptions> <option name="INDENT_SIZE" value="2" /> <option name="CONTINUATION_INDENT_SIZE" value="4" /> <option name="TAB_SIZE" value="2" /> </indentOptions>
▼ Keep when reformatting
-
✗ Comment at first column
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
// todo something
▼ Extends / implements list ⇨ Wrap if long
<option name="EXTENDS_LIST_WRAP" value="1" />
public class ThisIsASampleClass extends
C1 implements I1, I2, I3, I4,
I5 {
-
Extends / implements keyword ⇨ Wrap if long
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
public class ThisIsASampleClass extends C1 implements I1, I2, I3, I4, I5 {
▼ Throws list ⇨ Wrap if long
<option name="THROWS_LIST_WRAP" value="1" />
public static void longerMethod() throws
Exception1, Exception2,
Exception3 {
-
Throws keyword ⇨ Wrap if long
<option name="THROWS_KEYWORD_WRAP" value="1" />
public static void longerMethod() throws Exception1, Exception2, Exception3 {
▼ Method declaration parameters ⇨ Chop down if long
<option name="METHOD_PARAMETERS_WRAP" value="5" />
public void foo1(int i1,
int i2,
int i3,
int i4,
int i5,
int i6,
int i7) {
-
✓ New line after '('
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
public void foo1( int i1, int i2, int i3, int i4, int i5, int i6, int i7) {}
-
✓ Place ')' on new line
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
public void foo1( int i1, int i2, int i3, int i4, int i5, int i6, int i7 ) {}
▼ Method call arguments ⇨ Chop down if long
<option name="CALL_PARAMETERS_WRAP" value="5" />
foo1(0x0051,
0x0052,
0x0053,
0x0054,
0x0055,
0x0056,
0x0057);
-
✓ New line after '('
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
foo1( 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057);
-
✓ Place ')' on new line
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
foo1( 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057 );
▼ Chained method calls ⇨ Wrap if long
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
super.getFoo()
.foo()
.getBar()
.bar();
-
✓ Wrap first call
<option name="WRAP_FIRST_METHOD_IN_CALL_CHAIN" value="true" />
super .getFoo() .foo() .getBar() .bar();
▼ if()
statement
-
Force braces ⇨ Always
<option name="IF_BRACE_FORCE" value="3" />
if (2 < 3) { return; } else if (2 > 3) { return; } else { return; }
▼ for()
statement ⇨ Wrap if long
<option name="FOR_STATEMENT_WRAP" value="1" />
for (int i = 0; i < 0xFFFFFF;
i += 2)
-
✗ Align when multiline
<option name="ALIGN_MULTILINE_FOR" value="false" />
for (int i = 0; i < 0xFFFFFF; i += 2)
-
Force braces ⇨ Always
<option name="FOR_BRACE_FORCE" value="3" />
for (int i = 0; i < 0xFFFFFF; i += 2) { System.out.println(i); }
-
✓ New line after '('
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
for ( int i = 0; i < 0xFFFFFF; i += 2) {
-
✓ Place ')' on new line
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
for ( int i = 0; i < 0xFFFFFF; i += 2 ) {
▼ while()
statement
-
Force braces ⇨ Always
<option name="WHILE_BRACE_FORCE" value="3" />
while (x < 50000) { x++; }
▼ Binary expressions ⇨ Wrap if long
<option name="BINARY_OPERATION_WRAP" value="1" />
int x = (3 + 4 + 5 + 6) *
(7 + 8 + 9 + 10) *
(11 + 12 + 13 + 14 +
0xFFFFFFFF);
assert i + j + k + l + n +
m <=
2 : "assert description";
int y = 2 > 3 ?
7 + 8 + 9 :
11 + 12 + 13;
-
✓ New line after
{
<option name="PARENTHESES_EXPRESSION_LPAREN_WRAP" value="true" />
int x = (3 + 4 + 5 + 6) * ( 7 + 8 + 9 + 10) * ( 11 + 12 + 13 + 14 + A1CF 0xFFFFFFFF);
-
✓ Place
}
on new line<option name="PARENTHESES_EXPRESSION_RPAREN_WRAP" value="true" />
int x = (3 + 4 + 5 + 6) * ( 7 + 8 + 9 + 10 ) * ( 11 + 12 + 13 + 14 + 0xFFFFFFFF );
▼ Assignment statement ⇨ Wrap if long
<option name="ASSIGNMENT_WRAP" value="1" />
s1 = s2 =
s3 = "012345678901456"
▼ Ternary operation ⇨ Wrap if long
<option name="TERNARY_OPERATION_WRAP" value="1" />
int y = 2 > 3 ? 7 + 8 + 9 :
11 + 12 + 13;
▼ Assert statement ⇨ Wrap if long
<option name="ASSERT_STATEMENT_WRAP" value="1" />
assert i + j + k + l + n + m <= 2 :
"assert description";
Enums constants ⇨ Wrap always
<option name="ENUM_CONSTANTS_WRAP" value="2" />
enum Breed {
Dalmatian(),
Labrador(),
Dachshund()
}
Parameter annotations ⇨ Wrap if long
<option name="PARAMETER_ANNOTATION_WRAP" value="1" />
public void method(@Annotation1
@Annotation3(param1 = "value1", param2 = "value2")
final int param) {
Local variable annotations ⇨ Wrap always
<option name="VARIABLE_ANNOTATION_WRAP" value="2" />
@Annotation1
@Annotation3(param1 = "value1", param2 = "value2")
final int localVariable;
In declarations ⇨ 1
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
public class Foo {
private int field1;
private int field2;
}
In code ⇨ 1
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
if (places != null && !places.isEmpty()) {
placeModelCollection = new ArrayList<>();
for (Place place : places) {
placeModelCollection.add(transform(place));
}
}
Before }
⇨ 0
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
public void foo1() {
new Runnable() {
public void run() {
}
};
}
Around method interface ⇨ 0
<option name="BLANK_LINES_AROUND_METHOD_IN_INTERFACE" value="0" />
interface TestInterface {
int MAX = 10
int MIN = 1
def method1()
void method2()
}
Class count to use import with *
⇨ 999
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
Names count to use static import with *
⇨ 999
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
Import Layout
<package name="android" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
<package name="junit" withSubpackages="true" static="false" />
<package name="net" withSubpackages="true" static="false" />
<package name="org" withSubpackages="true" static="false" />
<package name="java" withSubpackages="true" static="false" />
<package name="javax" withSubpackages="true" static="false" />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
import android.*
import com.*
import junit.*
import net.*
import org.*
import java.*
import javax.*
import all other imports
<blank line>
import static all other imports
#### Related sources