You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: project_and_code_guidelines.md
+42-2Lines changed: 42 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,7 +199,7 @@ class MyClass {
199
199
200
200
Braces around the statements are required unless the condition and the body fit on one line.
201
201
202
-
If the condition and the body fit on one line and that line is shorter than the max line length, then do __not__ use braces e.g.
202
+
If the condition and the body fit on one line and that line is shorter than the max line length, then braces are not required, e.g.
203
203
204
204
```java
205
205
if (condition) body();
@@ -212,7 +212,9 @@ if (condition)
212
212
body(); // bad!
213
213
```
214
214
215
-
### 2.2.6 Use standard Java annotations
215
+
### 2.2.6 Annotations
216
+
217
+
#### 2.2.6.1 Annotations practices
216
218
217
219
According to the Android code style guide, the standard practices for some of the predefined annotations in Java are:
218
220
@@ -222,6 +224,26 @@ According to the Android code style guide, the standard practices for some of th
222
224
223
225
More information about annotations guidelines can be found [here](http://source.android.com/source/code-style.html#use-standard-java-annotations).
224
226
227
+
#### 2.2.6.2 Annotations style
228
+
229
+
__Classes, Methods and Constructors__
230
+
231
+
When annotations are applied to a class, method or constructor they are listed after the documentation block and should appear as __one annotation per line__ .
232
+
233
+
```java
234
+
/* This is the documentation block about the class */
235
+
@AnnotationA
236
+
@AnnotationB
237
+
publicclassMyAnnotatedClass { }
238
+
```
239
+
240
+
__Fields__
241
+
242
+
Annotations applying to fields should be listed __on the same line__, unless the line reaches the maximum line length.
243
+
244
+
```java
245
+
@Nullable@MockDataManager mDataManager;
246
+
```
225
247
226
248
### 2.2.7 Limit variable scope
227
249
@@ -431,6 +453,24 @@ There are two __exceptions__ where is possible to have lines longer than 100:
431
453
432
454
There isn't an exact formula that explains how to line-wrap and quite often different solutions are valid. However there are a few rules that can be applied to common cases.
433
455
456
+
__Break at operators__
457
+
458
+
When the line is broken at an operator, the break comes __before__ the operator. For example:
459
+
460
+
```java
461
+
int longName = anotherVeryLongVariable + anEvenLongerOne - thisRidiculousLongOne
462
+
+ theFinalOne;
463
+
```
464
+
465
+
__Assignment Operator Exception__
466
+
467
+
An exception to the break at operators rule is the assignment operator `=`, where the line break should happen __after__ the operator.
When multiple methods are chained in the same line - for example when using Builders - every call to a method should go in its own line, breaking the line before the `.`
0 commit comments