From 6f2e24915d98a869f9ea360a1aa967bf8fcfed4b Mon Sep 17 00:00:00 2001 From: tonihei Date: Wed, 31 Jul 2019 11:16:48 +0100 Subject: [PATCH] Add @NonNullApi and annotate two packages with it. This new annotation declares everything as non-null by default and can be used as a package annotation in package-info.java. In this change the core lib offline package and the mediasession extension is annotated that way as initial example usage. PiperOrigin-RevId: 260894548 --- constants.gradle | 1 + .../ext/mediasession/package-info.java | 19 ++++++++++ library/core/build.gradle | 3 ++ .../exoplayer2/offline/package-info.java | 19 ++++++++++ .../android/exoplayer2/util/NonNullApi.java | 36 +++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/package-info.java create mode 100644 library/core/src/main/java/com/google/android/exoplayer2/offline/package-info.java create mode 100644 library/core/src/main/java/com/google/android/exoplayer2/util/NonNullApi.java diff --git a/constants.gradle b/constants.gradle index aba52817bc..b1c2c636c7 100644 --- a/constants.gradle +++ b/constants.gradle @@ -24,6 +24,7 @@ project.ext { autoValueVersion = '1.6' autoServiceVersion = '1.0-rc4' checkerframeworkVersion = '2.5.0' + jsr305Version = '3.0.2' androidXTestVersion = '1.1.0' truthVersion = '0.44' modulePrefix = ':' diff --git a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/package-info.java b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/package-info.java new file mode 100644 index 0000000000..65c0ce080e --- /dev/null +++ b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@NonNullApi +package com.google.android.exoplayer2.ext.mediasession; + +import com.google.android.exoplayer2.util.NonNullApi; diff --git a/library/core/build.gradle b/library/core/build.gradle index f532ae0e6a..ecb81c4450 100644 --- a/library/core/build.gradle +++ b/library/core/build.gradle @@ -59,8 +59,11 @@ android { dependencies { implementation 'androidx.annotation:annotation:1.0.2' + compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion + // Uncomment to enable Kotlin non-null strict mode. See [internal: b/138703808]. + // compileOnly "org.jetbrains.kotlin:kotlin-annotations-jvm:1.1.60" androidTestImplementation 'androidx.test:runner:' + androidXTestVersion androidTestImplementation 'androidx.test.ext:junit:' + androidXTestVersion androidTestImplementation 'com.google.truth:truth:' + truthVersion diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/package-info.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/package-info.java new file mode 100644 index 0000000000..61450c9cfd --- /dev/null +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@NonNullApi +package com.google.android.exoplayer2.offline; + +import com.google.android.exoplayer2.util.NonNullApi; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/NonNullApi.java b/library/core/src/main/java/com/google/android/exoplayer2/util/NonNullApi.java new file mode 100644 index 0000000000..bd7a70eba0 --- /dev/null +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/NonNullApi.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; +// import kotlin.annotations.jvm.MigrationStatus; +// import kotlin.annotations.jvm.UnderMigration; + +/** + * Annotation to declare all type usages in the annotated instance as {@link Nonnull}, unless + * explicitly marked with a nullable annotation. + */ +@Nonnull +@TypeQualifierDefault(ElementType.TYPE_USE) +// TODO(internal: b/138703808): Uncomment to ensure Kotlin issues compiler errors when non-null +// types are used incorrectly. +// @UnderMigration(status = MigrationStatus.STRICT) +@Retention(RetentionPolicy.CLASS) +public @interface NonNullApi {}