OLD | NEW |
(Empty) | |
| 1 # Chromium Java style guide |
| 2 |
| 3 _For other languages, please see the [Chromium style |
| 4 guides](https://chromium.googlesource.com/chromium/src/+/master/styleguide/style
guide.md)._ |
| 5 |
| 6 Chromium follows the [Android Open Source style |
| 7 guide](http://source.android.com/source/code-style.html) unless an exception |
| 8 is listed below. |
| 9 |
| 10 ## Style |
| 11 |
| 12 * Copyright header should use |
| 13 [Chromium](https://chromium.googlesource.com/chromium/src/+/master/styleguide/
styleguide.md) |
| 14 style. |
| 15 * TODO should follow chromium convention i.e. `TODO(username)`. |
| 16 * Use of ```assert``` statements are encouraged. |
| 17 * Fields should not be explicitly initialized to default values (see |
| 18 [here](https://groups.google.com/a/chromium.org/d/topic/chromium-dev/ylbLOvLs0
bs/discussion)). |
| 19 * For automated style checking install |
| 20 [checkstyle](https://sites.google.com/a/chromium.org/dev/developers/checkstyle
). |
| 21 |
| 22 ## Location |
| 23 |
| 24 "Top level directories" are defined as directories with a GN file, such as |
| 25 [//base](https://chromium.googlesource.com/chromium/src/+/master/base/) |
| 26 and |
| 27 [//content](https://chromium.googlesource.com/chromium/src/+/master/content/), |
| 28 Chromium Java should live in a directory named |
| 29 `<top level directory>/android/java`, with a package name |
| 30 `org.chromium.<top level directory>`. Each top level directory's Java should |
| 31 build into a distinct JAR that honors the abstraction specified in a native |
| 32 [checkdeps](https://chromium.googlesource.com/chromium/buildtools/+/master/check
deps/checkdeps.py) |
| 33 (e.g. `org.chromium.base` does not import `org.chromium.content`). The full |
| 34 path of any java file should contain the complete package name. |
| 35 |
| 36 For example, top level directory `//base` might contain a file named |
| 37 `base/android/java/org/chromium/base/Class.java`. This would get compiled into a |
| 38 `chromium_base.jar` (final JAR name TBD). |
| 39 |
| 40 `org.chromium.chrome.browser.foo.Class` would live in |
| 41 `chrome/android/java/org/chromium/chrome/browser/foo/Class.java`. |
| 42 |
| 43 New `<top level directory>/android` directories should have an `OWNERS` file |
| 44 much like |
| 45 [//base/android/OWNERS](https://chromium.googlesource.com/chromium/src/+/master/
base/android/OWNERS). |
| 46 |
| 47 ## Asserts |
| 48 |
| 49 The Chromium build system strips asserts in release builds (via ProGuard) and |
| 50 enables them in debug builds (or when `dcheck_always_on=true`) (via a [build |
| 51 step](https://codereview.chromium.org/2517203002)). You should use asserts in |
| 52 the [same |
| 53 scenarios](https://chromium.googlesource.com/chromium/src/+/master/styleguide/c+
+/c++.md#CHECK_DCHECK_and-NOTREACHED) |
| 54 where C++ DCHECK()s make sense. For multi-statement asserts, use |
| 55 `org.chromium.base.BuildConfig.DCHECK_IS_ON` to guard your code. |
| 56 |
| 57 Example assert: |
| 58 |
| 59 ```java |
| 60 assert someCallWithSideEffects() : "assert description"; |
| 61 ``` |
| 62 |
| 63 Example use of `DCHECK_IS_ON`: |
| 64 |
| 65 ```java |
| 66 if (org.chromium.base.BuildConfig.DCHECK_IS_ON) { |
| 67 if (!someCallWithSideEffects()) { |
| 68 throw new AssertionError("assert description"); |
| 69 } |
| 70 } |
| 71 ``` |
OLD | NEW |