Java Coding style
We use theJava CodingStyle.Quick summary:
FirstLetterUpperCase for class names.
camelCase for method and variable names.
One declaration per line:
intx,y;// this is BAD!inta;// split it overintb;// two lines
Braces should be placed like so (generally, opening braces on sameline, closing braces on a new line):
publicvoidfunc(intarg){if(arg!=0){while(arg>0){arg--;}}else{arg++;}}
Places we differ from the Java coding style:
Start class variable names with ‘m’ prefix (e.g.mSomeClassVariable) and static variables with ‘s’ prefix (e.g.sSomeStaticVariable)
import
statements:Do not use wildcard imports like `import java.util.*;`
Organize imports by blocks separated by empty line:org.mozilla.*, android.*, com.*, net.*, org.*, then java.*This is basically what Android Studio does by default, exceptthat we place org.mozilla.* at the front - please adjustSettings -> Editor -> Code Style -> Java -> Importsaccordingly.
Within each import block, alphabetize import names withuppercase before lowercase. For example,
com.example.Foo
isbeforecom.example.bar
4-space indents.
Spaces, not tabs.
Don’t restrict yourself to 80-character lines. Google’s Androidstyle guide suggests 100-character lines, which is also thedefault setting in Android Studio. Java code tends to be longhorizontally, so use appropriate judgement when wrapping. Avoiddeep indents on wrapping. Note that aligning the wrapped part of aline, with some previous part of the line (rather than just usinga fixed indent), may require shifting the code every time the linechanges, resulting in spurious whitespace changes.
For additional specifics on Firefox for Android, see theCodingStyle guide for Firefox onAndroid.
TheAndroid CodingStyle has someuseful guidelines too.