Skip to content

Commit

Permalink
More nullability annotation work (#70)
Browse files Browse the repository at this point in the history
* More nullability annotation work

This is a followup to #69, and improves it in two main ways:
- This adds it to subpackages as well, which I missed in the first pass.
- Switches to a custom `PackageNonNull` annotation instead, which expands the checks to also include return types, fields, local vars, etc. It's pretty broad right now but we could reduce scope if need be. This is pulled into a separate artifact for re-use, but still only applied as compileOnly.

* Clean up qualifiers

* Tweak name

* Don't export artifact

Not necessary, we'll make this a separate project later

* CLASS retention instead of runtime
  • Loading branch information
ZacSweers authored May 16, 2017
1 parent a463e85 commit ce0d555
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 2 deletions.
1 change: 1 addition & 0 deletions autodispose-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
compile deps.rx.android
compile deps.support.annotations
provided deps.misc.errorProneAnnotations
provided project(':autodispose-provided')
errorprone deps.build.errorProne
androidTestCompile deps.support.annotations
androidTestCompile deps.test.junit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2017. Uber Technologies
*
* 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.
*/

/**
* Android components for AutoDispose.
*/
@com.uber.autodispose.internal.EverythingNonNullByDefault
package com.uber.autodispose.android;

6 changes: 6 additions & 0 deletions autodispose-provided/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
AutoDispose-provided
====================

This module solely exists to separate out `@PackageNonnull` to allow for it to be a `compileOnly`
dependency of the other projects. This allows it to be useful still for static analysis, while not
imposing the jsr305 artifact as a full compile dependency on the consumer.
41 changes: 41 additions & 0 deletions autodispose-provided/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2017. Uber Technologies
*
* 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.
*/
buildscript {
repositories {
jcenter()
maven { url deps.build.repositories.plugins }
}
dependencies {
classpath deps.build.gradlePlugins.errorProne
}
}

apply plugin: 'java-library'
apply plugin: 'net.ltgt.errorprone'

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

test {
testLogging.showStandardStreams = true
}

dependencies {
compileOnly deps.misc.errorProneAnnotations
compile deps.misc.jsr305

errorprone deps.build.errorProne
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.uber.autodispose.internal;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;

/**
* This annotation can be applied to a package, class or method to indicate that the class fields,
* method return types and parameters in that element are not null by default unless:
* - The method overrides a method in a superclass (in which case the annotation of the
* corresponding parameter in the superclass applies).
* - There is a default parameter annotation applied to a more tightly nested element.
*/
@Documented
@Nonnull
@TypeQualifierDefault({
ElementType.FIELD,
ElementType.METHOD,
ElementType.PARAMETER
})
@Retention(RetentionPolicy.CLASS)
public @interface EverythingNonNullByDefault { }
2 changes: 1 addition & 1 deletion autodispose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test {
dependencies {
api deps.rx.java
compileOnly deps.misc.errorProneAnnotations
compileOnly deps.misc.jsr305
compileOnly project(':autodispose-provided')

errorprone deps.build.errorProne

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2017. Uber Technologies
*
* 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.
*/

/**
* These are Observers AutoDispose uses when scoping an observable. They are exposed as a public API
* to allow for consumers to watch for them if they want, such as in RxJava plugins.
*/
@com.uber.autodispose.internal.EverythingNonNullByDefault
package com.uber.autodispose.observers;

Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
* AutoDispose is an RxJava 2 tool for automatically binding the execution of RxJava 2 streams to a
* provided scope via disposal/cancellation.
*/
@javax.annotation.ParametersAreNonnullByDefault
@com.uber.autodispose.internal.EverythingNonNullByDefault
package com.uber.autodispose;

1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ rootProject.name = 'autodispose-root'
include ':autodispose'
include ':autodispose-android'
include ':autodispose-kotlin'
include ':autodispose-provided'

0 comments on commit ce0d555

Please sign in to comment.