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
This commit is contained in:
tonihei 2019-07-31 11:16:48 +01:00 committed by Oliver Woodman
parent 78350cd17d
commit 6f2e24915d
5 changed files with 78 additions and 0 deletions

View File

@ -24,6 +24,7 @@ project.ext {
autoValueVersion = '1.6' autoValueVersion = '1.6'
autoServiceVersion = '1.0-rc4' autoServiceVersion = '1.0-rc4'
checkerframeworkVersion = '2.5.0' checkerframeworkVersion = '2.5.0'
jsr305Version = '3.0.2'
androidXTestVersion = '1.1.0' androidXTestVersion = '1.1.0'
truthVersion = '0.44' truthVersion = '0.44'
modulePrefix = ':' modulePrefix = ':'

View File

@ -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;

View File

@ -59,8 +59,11 @@ android {
dependencies { dependencies {
implementation 'androidx.annotation:annotation:1.0.2' implementation 'androidx.annotation:annotation:1.0.2'
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
compileOnly 'org.checkerframework:checker-compat-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:runner:' + androidXTestVersion
androidTestImplementation 'androidx.test.ext:junit:' + androidXTestVersion androidTestImplementation 'androidx.test.ext:junit:' + androidXTestVersion
androidTestImplementation 'com.google.truth:truth:' + truthVersion androidTestImplementation 'com.google.truth:truth:' + truthVersion

View File

@ -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;

View File

@ -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 {}