茉莉花茶适合什么人喝| 打牙祭是什么意思| 海选是什么意思| 宜入宅是什么意思| 粉刺是什么样的图片| 筋头巴脑是什么东西| 嗜酸性肉芽肿是什么病| 正师级是什么军衔| 香蕉有什么功效和作用| 只要睡觉就做梦是什么原因| 什么时候恢复的高考| 吃稀饭配什么菜好吃| 虾皮有什么营养价值| s代表什么意思| 滴虫性阴道炎吃什么药| 香薰是什么| 啮齿是什么意思| 狗生小狗前有什么征兆| 敏是什么意思| 37岁属什么| 吝啬鬼是什么生肖| 左肾积水是什么意思| 月经不调吃什么药调理最好| 孕妇耻骨疼是什么原因| 用神是什么意思| 做梦梦见捡钱是什么意思| 什么是量子力学| 什么门永远关不上| 狗癣用什么药最有效| sp是什么面料| 碳酸氢钠是什么东西| 金融办是什么单位| 什么是承兑| 艾灸有什么作用| 什么是精神出轨| 日本为什么要偷袭珍珠港| 麦粒肿不能吃什么食物| 臀推是什么意思| 子宫肌瘤吃什么食物好| 男人要吃什么才能壮阳| 恩赐是什么意思| 蜜蜂为什么要采蜜| 小孩爱吃手指头是什么原因| 秫米是什么米| cap是什么| 睡觉流口水是什么毛病| 三尖瓣少量反流是什么意思| 手掌中间那条线是什么线| 鼻子干燥吃什么中成药| 厚颜无耻是什么意思| 捋一捋是什么意思| 新疆人是什么民族| 看乳房挂什么科| 龋齿和蛀牙有什么区别| 白细胞低是什么意思| 人活着到底是为了什么| 猫不喜欢什么味道| 萎靡是什么意思| 人总放屁是什么原因| 行为艺术是什么意思| 老母鸡炖什么好吃又有营养价值| lap是什么意思| 李小龙属什么生肖| 十二月二号是什么星座| 吃什么壮阳| 香水前调中调后调是什么意思| 八项药是什么药| 白细胞低吃什么补得快| 什么花最香| 左手中指麻木是什么原因| 焦糖色上衣配什么颜色裤子| 脱髓鞘病变是什么意思| 白衣天使是什么意思| 旦辞爷娘去的旦是什么意思| 小月子能吃什么菜| 沉鱼落雁闭月羞花是什么意思| 白术是什么样子的图片| 人体最大的细胞是什么| 肠瘘是什么意思| 总口渴是什么原因| 什么克土| 三点水卖读什么| 担当是什么| 慢性鼻炎吃什么药| 樱花是什么样子的| 穴与什么有关| 阴虚吃什么中药| 中国一词最早出现在什么时候| blanc什么意思| 失恋什么意思| 胃酸反流吃什么药| 84属什么生肖| 腰椎mri是什么检查| 5月14日什么星座| 咬到舌头是什么预兆| 何首乌长什么样| c3是什么驾驶证| 野字五行属什么| 牙疼是什么火引起的| 脑出血是什么原因造成的| 扩容是什么意思| 尿酸高多吃什么食物好| prog是什么意思| 尿血是什么问题| 肿瘤是什么意思| 两肋插刀是什么意思| 确立是什么意思| 一致是什么意思| 什么瓜不能吃脑筋急转弯| 爱出汗吃什么药| 镇关西是什么意思| 男羊配什么属相最好| 红楼梦什么朝代| 产后吃什么水果| 五行缺什么查询| 养生是什么意思| 什么牌子的蛋白质粉比较好| 慢性肠炎吃什么药调理| 血肌酐高是什么原因| 1点到3点是什么时辰| 梦见养猪是什么意思| 3月29日是什么星座| 屁多且臭是什么原因| 孕前检查什么时候去最合适| 上证指数是什么意思| 中焦湿热吃什么中成药| 慢性炎伴鳞化是什么意思| 晚上睡觉脚抽搐是什么原因| 现役是什么意思| 澳门为什么叫澳门| 什么鸣什么吠| 168红包代表什么意思| 灵芝泡水喝有什么功效| 肛塞什么感觉| 丁亥年五行属什么| 纯钛是什么材质| 全身抽筋吃什么药| 狼牙套是什么| 梦见房子漏水是什么意思| 玟字五行属什么| 肿物是什么意思| 流产吃什么药| 口腔医学是干什么的| 丁是什么意思| 分家是什么意思| 河虾吃什么| 喜欢放屁是什么原因| 肠胃消化不好吃什么药| 经常头晕头疼是什么原因| 白鱼是什么鱼| 香五行属什么| 白细胞高一点点是什么原因| ntr什么意思| 腊猪蹄炖什么好吃| 一什么教室| 95年属什么多大| 互联网是干什么的| 长疱疹是什么原因| 甘油三酯高是什么| 左肾积水是什么意思| 嗣子是什么意思| 大腿粗是什么原因导致的| 双响炮是什么| 1965属什么生肖| 中央办公厅主任什么级别| 什么叫眼睛散光| 梦见自己疯了什么意思| 为什么不要看电焊火花| 间歇性是什么意思| 黄色鞋子配什么颜色裤子| 粉瘤是什么| 甲亢食疗吃什么| 羊蛋是什么| 低烧头疼吃什么药| 鱼肝油什么时候吃最好| 疮疖是什么意思| 哼唧是什么意思| 8.12什么星座| 猛虎下山是什么生肖| 一个山一个鬼念什么| 西安什么山| 油麦菜不能和什么一起吃| 侏儒症是什么原因引起的| 风什么浪什么| 肾不好会出现什么症状| roa是什么| 黎山老母什么级别神仙| 杏和什么不能一起吃| 拔萝卜是什么意思| 粘胶纤维是什么| 三聚净戒是指什么戒| 大四什么时候毕业| 复杂囊肿是什么意思| hpv病毒是什么原因引起的| 鸡蛋黄发红是什么原因| 有什么好| 六月十一号是什么星座| aut0是什么意思| 一直想大便是什么原因| 造瘘手术是什么意思| 皮肤起小水泡很痒是什么原因| 大禹的爸爸叫什么| 脑梗的人适合吃什么食物| 胃痛是什么原因| 扶她是什么意思| 干咳无痰是什么原因| 6.25是什么星座| 受凉拉肚子吃什么药| 1947年属什么生肖| 龙男和什么生肖最配| 田野里有什么| 缝纫机油是什么油| 失眠多梦吃什么药| 孕妇吃核桃对胎儿有什么好处| 帝王术是什么意思| 铁瓷是什么意思| 物以类聚人以群分什么意思| 主动脉增宽是什么意思| 女儿是小棉袄儿子是什么| 西游记什么朝代写的| 风湿病是什么原因造成的| 支气管扩张是什么意思| 乙肝看什么科| 脑筋急转弯什么东西越洗越脏| 7月6号是什么星座| 风波是什么意思| 肩周炎挂什么科室| 孕妇感冒了对胎儿有什么影响| 减肥晚上适合吃什么水果| 另起炉灶是什么意思| 黄金桂是什么茶| 这个季节种什么菜合适| 肾精亏虚吃什么中成药| 西咪替丁是治什么病| 如梦初醒是什么意思| 耳朵里发炎用什么药好| 阴道口疼是什么原因| 左后背发麻是什么原因| 醋栗是什么东西| 昭觉寺求什么最灵验| gh是什么激素| 画眉是什么| 砚是什么意思| 结婚30年是什么婚姻| 百事可乐和可口可乐有什么区别| 壮丁是什么意思| 银消病用什么药效果最好| 身份证数字分别代表什么| 小寒是什么意思| 吊孝是什么意思| 口腔溃疡用什么药最好| 吃刺猬有什么好处| 经期吃什么水果好| hds是什么意思| 属虎适合佩戴什么饰品| 443是什么意思| 辟谷什么意思| 印度信仰什么教| 生气什么| 属马的人佩戴什么招财| 面试要带什么| 老虎下山下一句是什么| 识大体是什么意思| 午夜是什么时候| 百度

你觉得-汪精卫死后待遇如皇帝,降旗、百官缠黑纱一月,民间停止

百度 事发后不久,在成都的其他亲人接到电话,紧急赶往茂县。

For other languages, please see the Chromium style guides.

Chromium follows the Android Open Source style guide unless an exception is listed below.

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 get to decide.

Java Language Features

Type Deduction using “var”

A variable declaration can use the var keyword in place of the type (similar to the auto keyword in C++). In line with the guidance for C++, the var keyword may be used when it aids readability and the type of the value is already clear (ex. var bundle = new Bundle() is OK, but var something = returnValueIsNotObvious() may be unclear to readers who are new to this part of the code).

The var keyword may also be used in try-with-resources when the resource is not directly accessed (or when it falls under the previous guidance), such as:

try (var ignored = StrictModeContext.allowDiskWrites()) {
    // 'var' is permitted so long as the 'ignored' variable is not used directly
    // in the code.
}

Exceptions

A quick primer:

  • Throwable: Base class for all exceptions
    • Error: Base class for exceptions which are meant to crash the app.
    • Exception: Base class for exceptions that make sense the catch.
      • RuntimeException: Base class for exceptions that do not need to be declared as throws (“unchecked exceptions”).

Broad Catch Handlers

Use catch statements that do not catch exceptions they are not meant to.

  • There is rarely a valid reason to catch (Throwable t), since that includes the (generally unrecoverable) Error types.

Use catch (Exception e) when working with OS APIs that might throw (assuming the program can recover from them).

  • There have been many cases of crashes caused by IllegalStateException / IllegalArgumentException / SecurityException being thrown where only RemoteException was being caught. Unless catch handlers will differ based on exception type, just catch Exception.

Do not use catch (RuntimeException e).

  • It is useful to extend RuntimeException to make unchecked exception types, but the type does not make much sense in catch clauses, as there are not times when you'd want to catch all unchecked exceptions, but not also want to catch all checked exceptions.

Exception Messages

Avoid adding messages to exceptions that do not aid in debugging. For example:

try {
    somethingThatThrowsIOException();
} catch (IOException e) {
    // Bad - message does not tell you more than the stack trace does:
    throw new RuntimeException("Failed to parse a file.", e);
    // Good - conveys that this block failed along with the "caused by" exception.
    throw new RuntimeException(e);
    // Good - adds useful information.
    throw new RuntimeException(String.format("Failed to parse %s", fileName), e);
}

Wrapping with RuntimeException

It is common to wrap a checked exception with a RuntimeException for cases where a checked exception is not recoverable, or not possible. In order to reduce the number of stack trace “caused by” clauses, and to save on binary size, use JavaUtils.throwUnchecked() instead.

try {
    somethingThatThrowsIOException();
} catch (IOException e) {
    // Bad - RuntimeException adds no context and creates longer stack traces.
    throw new RuntimeException(e);
    // Good - Original exception is preserved.
    throw JavaUtils.throwUnchecked(e);
}
Do not use throwUnchecked() when the exception may want to be caught.

Asserts

The build system:

  • strips asserts in release builds (via R8),
  • enables them in debug builds,
  • and enables them in report-only mode for Canary builds.
// Code for assert expressions & messages is removed when asserts are disabled.
assert someCallWithoutSideEffects(param) : "Call failed with: " + param;

Use your judgement for when to use asserts vs exceptions. Generally speaking, use asserts to check program invariants (e.g. parameter constraints) and exceptions for unrecoverable error conditions (e.g. OS errors). You should tend to use exceptions more in privacy / security-sensitive code.

Do not add checks when the code will crash anyways. E.g.:

// Don't do this.
assert(foo != null);
foo.method(); // This will throw anyways.

For multi-statement asserts, use BuildConfig.ENABLE_ASSERTS to guard your code (similar to #if DCHECK_IS_ON() in C++). E.g.:

import org.chromium.build.BuildConfig;

...

if (BuildConfig.ENABLE_ASSERTS) {
    // Any code here will be stripped in release builds by R8.
    ...
}

DCHECKS vs Java Asserts

DCHECK and assert are similar, but our guidance for them differs:

  • CHECKs are preferred in C++, whereas asserts are preferred in Java.

This is because as a memory-safe language, logic bugs in Java are much less likely to be exploitable.

toString()

Use explicit serialization methods (e.g. toDebugString() or getDescription()) instead of toString() when dynamic dispatch is not required.

  1. R8 cannot detect when toString() is unused, so overrides will not be stripped when unused.
  2. R8 cannot optimize / inline these calls as well as non-overriding methods.

Records & AutoValue

// Banned.
record Rectangle(float length, float width) {}

Rationale:

  • To avoid dead code:
    • Records and @AutoValue generate equals(), hashCode(), and toString(), which R8 is unable to remove when unused.
    • When these methods are required, implement them explicitly so that the intention is clear.
  • Also - supporting record requires build system work (crbug/1493366).

Example with equals() and hashCode():

public class ValueClass {
    private final SomeClass mObjMember;
    private final int mIntMember;

    @Override
    public boolean equals(Object o) {
        return o instanceof ValueClass vc
                && Objects.equals(mObjMember, vc.mObjMember)
                && mIntMember == vc.mIntMember;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mObjMember, mIntMember);
    }
}

Enums

Banned. Use @IntDef instead.

Rationale:

Java enums generate a lot of bytecode. Use constants where possible. When a custom type hierarchy is required, use explicit classes with inheritance.

Finalizers

In line with Google's Java style guide and Android's Java style guide, never override Object.finalize().

Custom finalizers:

  • are called on a background thread, and at an unpredicatble point in time,
  • swallow all exceptions (asserts won't work),
  • causes additional garbage collector jank.

Classes that need destructor logic should provide an explicit destroy() method. Use LifetimeAssert to ensure in debug builds and tests that destroy() is called.

Nullability Annotations

A migration to add @NullMarked to all Java files is currently underway (crbug.com/389129271). See nullaway.md for how to use @Nullable and related annotations.

Java Library APIs

Android provides the ability to bundle copies of java.* APIs alongside application code, known as Java Library Desugaring. However, since this bundling comes with a performance cost, Chrome does not use it. Treat java.* APIs the same as you would android.* ones and guard them with Build.VERSION.SDK_INT checks when necessary. The one exception is if the method is directly backported by D8 (these are okay to use, since they are lightweight). Android Lint will fail if you try to use an API without a corresponding Build.VERSION.SDK_INT guard or @RequiresApi annotation.

Logging

  • Use org.chromium.base.Log instead of android.util.Log.
    • It provides %s support, and ensures log stripping works correctly.
  • Minimize the use of Log.w() and Log.e().
    • Debug and Info log levels are stripped by ProGuard in release builds, and so have no performance impact for shipping builds. However, Warning and Error log levels are not stripped.
  • Function calls in log parameters are not stripped by ProGuard.
Log.d(TAG, "There are %d cats", countCats());  // countCats() not stripped.

Streams

Using Java streams outside of tests is strongly discouraged. If you can write your code as an explicit loop, then do so. The primary reason for this guidance is because the lambdas and method references needed for streams almost always result in larger binary size than their loop equivalents (see crbug.com/344943957 for examples).

The parallel() and parallelStream() APIs are simpler than their loop equivalents, but are banned due to a lack of a compelling use case in Chrome. If you find one, please discuss on java@chromium.org.

Use of stream() without a lambda / method reference is allowed. E.g.:

@SuppressWarnings("NoStreams")
private static List<Integer> boxInts(int[] arr) {
    return Arrays.stream(arr).boxed().collect(Collectors.toList());
}

@SuppressWarnings("NoStreams")
private static List<String> readLines(BufferedReader bufferedReader) {
    return bufferedReader.lines().collect(Collectors.toList());
}

AndroidX Annotations

  • Use them liberally. They are documented here.
    • They generally improve readability.
    • Many make lint more useful.
  • What about androidx.annotation.Nullable?
    • We are migrating away from it (see nullaway.md).
    • Keep using it in files that have not yet been migrated.

IntDefs

Values can be declared outside or inside the @interface. Chromium style is to declare inside.

@IntDef({ContactsPickerAction.CANCEL, ContactsPickerAction.CONTACTS_SELECTED,
        ContactsPickerAction.SELECT_ALL, ContactsPickerAction.UNDO_SELECT_ALL})
@Retention(RetentionPolicy.SOURCE)
public @interface ContactsPickerAction {
    int CANCEL = 0;
    int CONTACTS_SELECTED = 1;
    int SELECT_ALL = 2;
    int UNDO_SELECT_ALL = 3;
    int NUM_ENTRIES = 4;
}
// ...
void onContactsPickerUserAction(@ContactsPickerAction int action, ...);

Values of Integer type are also supported, which allows using a sentinel null if needed.

Style / Formatting

File Headers

TODOs

  • TODO should follow chromium convention. Examples:
    • TODO(username): Some sentence here.
    • TODO(crbug.com/40192027): Even better to use a bug for context.

Parameter Comments

Use parameter comments when they aid in the readability of a function call.

E.g.:

someMethod(/* enabled= */ true, /* target= */ null, defaultValue);

Default Field Initializers

  • Fields should not be explicitly initialized to default values (see here).

Curly Braces

Conditional braces should be used, but are optional if the conditional and the statement can be on a single line.

Do:

if (someConditional) return false;
for (int i = 0; i < 10; ++i) callThing(i);

or

if (someConditional) {
    return false;
}

Do NOT do:

if (someConditional)
    return false;

Import Order

  • Static imports go before other imports.
  • Each import group must be separated by an empty line.

This is the order of the import groups:

  1. android
  2. androidx
  3. com (except com.google.android.apps.chrome)
  4. dalvik
  5. junit
  6. org
  7. com.google.android.apps.chrome
  8. org.chromium
  9. java
  10. javax

Testing

Googlers, see go/clank-test-strategy.

In summary:

  • Use real dependencies when feasible and fast. Use Mockito’s @Mock most of the time, but write fakes for frequently used dependencies.

  • Do not use Robolectric Shadows for Chromium code.

    • Shadows make code harder to refactor.
    • Prefer to refactor code to make it more testable.
    • When you really need to use a test double for a static method, add a setFooForTesting() [...] method to make the test contract explicit.
  • Use Robolectric when possible (when tests do not require native). Other times, use on-device tests with one of the following annotations:

Test-only Code

Functions and fields used only for testing should have ForTesting as a suffix so that:

  1. The android-binary-size trybot can ensure they are removed in non-test optimized builds (by R8).
  2. PRESUMBIT.py can ensure no calls are made to such methods outside of tests, and

ForTesting methods that are @CalledByNative should use @CalledByNativeForTesting instead.

Symbols that are made public (or package-private) for the sake of tests should be annotated with @VisibleForTesting. Android Lint will check that calls from non-test code respect the “otherwise” visibility.

Symbols with a ForTesting suffix should not be annotated with @VisibleForTesting. While otherwise=VisibleForTesting.NONE exists, it is redundant given the “ForTesting” suffix and the associated lint check is redundant given our trybot check. You should, however, use it for test-only constructors.

Location

“Top level directories” are defined as directories with a GN file, such as //base and //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 (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.

Tools

google-java-format is used to auto-format Java files. Formatting of its code should be accepted in code reviews.

You can run git cl format to apply the automatic formatting.

Chromium also makes use of several static analysis tools.

Miscellany

  • Use UTF-8 file encodings and LF line endings.
normal是什么意思 瓜怂是什么意思 喝温开水有什么好处 后壁是什么意思 反式脂肪酸是什么意思
吃了避孕药不能吃什么东西 中医行业五行属什么 你想干什么 办什么厂比较好 胆固醇高会引起什么病
热玛吉是什么 睾酮高有什么影响 ozark是什么牌子 什么姿势容易怀孕 红斑狼疮的症状是什么
看肛门挂什么科 嗓子疼吃什么药好得快 乌药别名叫什么 看腋窝挂什么科 鳖是什么动物
慢悠悠的近义词是什么hcv8jop3ns5r.cn 拉屎为什么是黑色的hcv8jop8ns8r.cn 一九六三年属什么生肖hcv9jop6ns8r.cn miu是什么意思fenrenren.com 天衣无缝什么意思hcv7jop6ns8r.cn
什么服务hcv8jop7ns5r.cn 脸上发痒是什么原因hcv8jop2ns8r.cn 怎么知道自己什么血型xjhesheng.com 做梦梦见火是什么意思hcv9jop4ns6r.cn 追求是什么意思hcv8jop9ns7r.cn
大张伟原名叫什么bjhyzcsm.com 芦荟有什么用hcv7jop9ns9r.cn 体内湿热吃什么中成药hcv8jop4ns2r.cn 心尖尖是什么意思beikeqingting.com 拉肚子吃什么药最有效果hcv7jop9ns8r.cn
咳嗽有黄痰是什么原因hcv9jop4ns8r.cn 尿量少是什么原因jingluanji.com 肚子疼什么原因cl108k.com 胃气上逆是什么原因hcv8jop0ns0r.cn 宝宝经常发烧是什么原因引起的beikeqingting.com
百度