summaryrefslogtreecommitdiff
path: root/chromium/styleguide/java/java.md
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-05 17:15:33 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-11 07:47:18 +0000
commit7324afb043a0b1e623d8e8eb906cdc53bdeb4685 (patch)
treea3fe2d74ea9c9e142c390dac4ca0e219382ace46 /chromium/styleguide/java/java.md
parent6a4cabb866f66d4128a97cdc6d9d08ce074f1247 (diff)
downloadqtwebengine-chromium-7324afb043a0b1e623d8e8eb906cdc53bdeb4685.tar.gz
BASELINE: Update Chromium to 58.0.3029.54
Change-Id: I67f57065a7afdc8e4614adb5c0230281428df4d1 Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'chromium/styleguide/java/java.md')
-rw-r--r--chromium/styleguide/java/java.md154
1 files changed, 154 insertions, 0 deletions
diff --git a/chromium/styleguide/java/java.md b/chromium/styleguide/java/java.md
new file mode 100644
index 00000000000..0567689a48e
--- /dev/null
+++ b/chromium/styleguide/java/java.md
@@ -0,0 +1,154 @@
+# Chromium Java style guide
+
+_For other languages, please see the [Chromium style
+guides](https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md)._
+
+Chromium follows the [Android Open Source style
+guide](http://source.android.com/source/code-style.html) unless an exception
+is listed below.
+
+A checkout should give you clang-format to automatically format Java code.
+It is suggested that Clang's formatting of code should be accepted in code
+reviews.
+
+You can propose changes to this style guide by sending an email to
+`java@chromium.org`. Ideally, the list will arrive at some consensus and you can
+request review for a change to this file. If there's no consensus,
+[`//styleguide/java/OWNERS`](https://chromium.googlesource.com/chromium/src/+/master/styleguide/java/OWNERS)
+get to decide.
+
+## Tools
+
+### Automatically formatting edited files
+
+You can run `git cl format` to apply the automatic formatting.
+
+### IDE setup
+
+For automatically using the correct style, follow the guide to set up your
+favorite IDE:
+
+* [Android Studio](https://chromium.googlesource.com/chromium/src/+/master/docs/android_studio.md)
+* [Eclipse](https://chromium.googlesource.com/chromium/src/+/master/docs/eclipse.md)
+
+### Checkstyle
+
+Checkstyle is automatically run by the build bots, and to ensure you do not have
+any surprises, you can also set up checkstyle locally using [this
+guide](https://sites.google.com/a/chromium.org/dev/developers/checkstyle).
+
+### Lint
+
+Lint is run as part of the build. For more information, see
+[here](https://chromium.googlesource.com/chromium/src/+/master/build/android/docs/lint.md).
+
+## File Headers
+
+Use the same format as in the [C++ style guide](https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md#File-headers).
+
+## TODOs
+
+TODO should follow chromium convention i.e. `TODO(username)`.
+
+## Code formatting
+
+* Fields should not be explicitly initialized to default values (see
+ [here](https://groups.google.com/a/chromium.org/d/topic/chromium-dev/ylbLOvLs0bs/discussion)).
+
+### Curly braces
+
+Conditional braces should be used, but are optional if the conditional and the
+statement can be on a single line.
+
+Do:
+
+```java
+if (someConditional) return false;
+for (int i = 0; i < 10; ++i) callThing(i);
+```
+
+or
+
+```java
+if (someConditional) {
+ return false;
+}
+```
+
+Do NOT do:
+
+```java
+if (someConditional)
+ return false;
+```
+
+### Exceptions
+
+Similarly to the Android style guide, we discourage the use of
+`catch Exception`. It is also allowed to catch multiple exceptions in one line.
+
+It is OK to do:
+
+```java
+try {
+ somethingThatThrowsIOException();
+ somethingThatThrowsParseException();
+} catch (IOException | ParseException e) {
+ Log.e(TAG, "Failed to do something with exception: ", e)
+}
+```
+
+### Asserts
+
+The Chromium build system strips asserts in release builds (via ProGuard) and
+enables them in debug builds (or when `dcheck_always_on=true`) (via a [build
+step](https://codereview.chromium.org/2517203002)). You should use asserts in
+the [same
+scenarios](https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md#CHECK_DCHECK_and-NOTREACHED)
+where C++ DCHECK()s make sense. For multi-statement asserts, use
+`org.chromium.base.BuildConfig.DCHECK_IS_ON` to guard your code.
+
+Example assert:
+
+```java
+assert someCallWithSideEffects() : "assert description";
+```
+
+Example use of `DCHECK_IS_ON`:
+
+```java
+if (org.chromium.base.BuildConfig.DCHECK_IS_ON) {
+ if (!someCallWithSideEffects()) {
+ throw new AssertionError("assert description");
+ }
+}
+```
+
+## Location
+
+"Top level directories" are defined as directories with a GN file, such as
+[//base](https://chromium.googlesource.com/chromium/src/+/master/base/)
+and
+[//content](https://chromium.googlesource.com/chromium/src/+/master/content/),
+Chromium Java should live in a directory named
+`<top level directory>/android/java`, with a package name
+`org.chromium.<top level directory>`. Each top level directory's Java should
+build into a distinct JAR that honors the abstraction specified in a native
+[checkdeps](https://chromium.googlesource.com/chromium/buildtools/+/master/checkdeps/checkdeps.py)
+(e.g. `org.chromium.base` does not import `org.chromium.content`). The full
+path of any java file should contain the complete package name.
+
+For example, top level directory `//base` might contain a file named
+`base/android/java/org/chromium/base/Class.java`. This would get compiled into a
+`chromium_base.jar` (final JAR name TBD).
+
+`org.chromium.chrome.browser.foo.Class` would live in
+`chrome/android/java/org/chromium/chrome/browser/foo/Class.java`.
+
+New `<top level directory>/android` directories should have an `OWNERS` file
+much like
+[//base/android/OWNERS](https://chromium.googlesource.com/chromium/src/+/master/base/android/OWNERS).
+
+## Miscellany
+
+* Use UTF-8 file encodings and LF line endings.