OLD | NEW |
1 # Chromium Java style guide | 1 # Chromium Java style guide |
2 | 2 |
3 _For other languages, please see the [Chromium style | 3 _For other languages, please see the [Chromium style |
4 guides](https://chromium.googlesource.com/chromium/src/+/master/styleguide/style
guide.md)._ | 4 guides](https://chromium.googlesource.com/chromium/src/+/master/styleguide/style
guide.md)._ |
5 | 5 |
6 Chromium follows the [Android Open Source style | 6 Chromium follows the [Android Open Source style |
7 guide](http://source.android.com/source/code-style.html) unless an exception | 7 guide](http://source.android.com/source/code-style.html) unless an exception |
8 is listed below. | 8 is listed below. |
9 | 9 |
10 A checkout should give you clang-format to automatically format Java code. | 10 A checkout should give you clang-format to automatically format Java code. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 Example use of `DCHECK_IS_ON`: | 117 Example use of `DCHECK_IS_ON`: |
118 | 118 |
119 ```java | 119 ```java |
120 if (org.chromium.base.BuildConfig.DCHECK_IS_ON) { | 120 if (org.chromium.base.BuildConfig.DCHECK_IS_ON) { |
121 if (!someCallWithSideEffects()) { | 121 if (!someCallWithSideEffects()) { |
122 throw new AssertionError("assert description"); | 122 throw new AssertionError("assert description"); |
123 } | 123 } |
124 } | 124 } |
125 ``` | 125 ``` |
126 | 126 |
| 127 ### Import Order |
| 128 |
| 129 * Static imports go before other imports. |
| 130 * Each import group must be separated by an empty line. |
| 131 |
| 132 This is the order of the import groups: |
| 133 |
| 134 1. android |
| 135 1. com (except com.google.android.apps.chrome) |
| 136 1. dalvik |
| 137 1. junit |
| 138 1. org |
| 139 1. com.google.android.apps.chrome |
| 140 1. org.chromium |
| 141 1. java |
| 142 1. javax |
| 143 |
| 144 This is enforced by the |
| 145 [Chromium Checkstyle configuration](../../tools/android/checkstyle/chromium-styl
e-5.0.xml) |
| 146 under the ImportOrder module. |
| 147 |
127 ## Location | 148 ## Location |
128 | 149 |
129 "Top level directories" are defined as directories with a GN file, such as | 150 "Top level directories" are defined as directories with a GN file, such as |
130 [//base](https://chromium.googlesource.com/chromium/src/+/master/base/) | 151 [//base](https://chromium.googlesource.com/chromium/src/+/master/base/) |
131 and | 152 and |
132 [//content](https://chromium.googlesource.com/chromium/src/+/master/content/), | 153 [//content](https://chromium.googlesource.com/chromium/src/+/master/content/), |
133 Chromium Java should live in a directory named | 154 Chromium Java should live in a directory named |
134 `<top level directory>/android/java`, with a package name | 155 `<top level directory>/android/java`, with a package name |
135 `org.chromium.<top level directory>`. Each top level directory's Java should | 156 `org.chromium.<top level directory>`. Each top level directory's Java should |
136 build into a distinct JAR that honors the abstraction specified in a native | 157 build into a distinct JAR that honors the abstraction specified in a native |
137 [checkdeps](https://chromium.googlesource.com/chromium/buildtools/+/master/check
deps/checkdeps.py) | 158 [checkdeps](https://chromium.googlesource.com/chromium/buildtools/+/master/check
deps/checkdeps.py) |
138 (e.g. `org.chromium.base` does not import `org.chromium.content`). The full | 159 (e.g. `org.chromium.base` does not import `org.chromium.content`). The full |
139 path of any java file should contain the complete package name. | 160 path of any java file should contain the complete package name. |
140 | 161 |
141 For example, top level directory `//base` might contain a file named | 162 For example, top level directory `//base` might contain a file named |
142 `base/android/java/org/chromium/base/Class.java`. This would get compiled into a | 163 `base/android/java/org/chromium/base/Class.java`. This would get compiled into a |
143 `chromium_base.jar` (final JAR name TBD). | 164 `chromium_base.jar` (final JAR name TBD). |
144 | 165 |
145 `org.chromium.chrome.browser.foo.Class` would live in | 166 `org.chromium.chrome.browser.foo.Class` would live in |
146 `chrome/android/java/org/chromium/chrome/browser/foo/Class.java`. | 167 `chrome/android/java/org/chromium/chrome/browser/foo/Class.java`. |
147 | 168 |
148 New `<top level directory>/android` directories should have an `OWNERS` file | 169 New `<top level directory>/android` directories should have an `OWNERS` file |
149 much like | 170 much like |
150 [//base/android/OWNERS](https://chromium.googlesource.com/chromium/src/+/master/
base/android/OWNERS). | 171 [//base/android/OWNERS](https://chromium.googlesource.com/chromium/src/+/master/
base/android/OWNERS). |
151 | 172 |
152 ## Miscellany | 173 ## Miscellany |
153 | 174 |
154 * Use UTF-8 file encodings and LF line endings. | 175 * Use UTF-8 file encodings and LF line endings. |
OLD | NEW |