Skip to content

Commit 12f61ab

Browse files
committed
Add proper nullability annotations to Firestore.
Additionally remove uses of the redundant @publicapi annotation.
1 parent b543101 commit 12f61ab

File tree

71 files changed

+77
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+77
-324
lines changed

firebase-firestore/firebase-firestore.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ plugins {
2020
firebaseLibrary {
2121
testLab.enabled = true
2222
publishSources = true
23-
staticAnalysis.disableKotlinInteropLint()
2423
}
2524

2625
protobuf {

firebase-firestore/src/main/java/com/google/firebase/Timestamp.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import android.os.Parcel;
2020
import android.os.Parcelable;
2121
import androidx.annotation.NonNull;
22-
import com.google.firebase.annotations.PublicApi;
2322
import java.util.Date;
2423

2524
/**
@@ -35,10 +34,9 @@
3534
* https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto">The
3635
* reference timestamp definition</a>
3736
*/
38-
@PublicApi
3937
public final class Timestamp implements Comparable<Timestamp>, Parcelable {
4038

41-
@PublicApi @NonNull
39+
@NonNull
4240
public static final Parcelable.Creator<Timestamp> CREATOR =
4341
new Parcelable.Creator<Timestamp>() {
4442
@Override
@@ -61,21 +59,19 @@ public Timestamp[] newArray(int size) {
6159
* Negative second values with fractions must still have non-negative nanoseconds values that
6260
* count forward in time. Must be from 0 to 999,999,999 inclusive.
6361
*/
64-
@PublicApi
6562
public Timestamp(long seconds, int nanoseconds) {
6663
validateRange(seconds, nanoseconds);
6764
this.seconds = seconds;
6865
this.nanoseconds = nanoseconds;
6966
}
7067

71-
protected Timestamp(Parcel in) {
68+
protected Timestamp(@NonNull Parcel in) {
7269
this.seconds = in.readLong();
7370
this.nanoseconds = in.readInt();
7471
}
7572

7673
/** Creates a new timestamp from the given date. */
77-
@PublicApi
78-
public Timestamp(Date date) {
74+
public Timestamp(@NonNull Date date) {
7975
long millis = date.getTime();
8076
long seconds = millis / 1000;
8177
int nanoseconds = (int) (millis % 1000) * 1000000;
@@ -89,26 +85,22 @@ public Timestamp(Date date) {
8985
}
9086

9187
/** Creates a new timestamp with the current date, with millisecond precision. */
92-
@PublicApi
9388
@NonNull
9489
public static Timestamp now() {
9590
return new Timestamp(new Date());
9691
}
9792

9893
/** Returns the seconds part of the timestamp. */
99-
@PublicApi
10094
public long getSeconds() {
10195
return seconds;
10296
}
10397

10498
/** Returns the sub-second part of the timestamp, in nanoseconds. */
105-
@PublicApi
10699
public int getNanoseconds() {
107100
return nanoseconds;
108101
}
109102

110103
/** Returns a new Date corresponding to this timestamp. This may lose precision. */
111-
@PublicApi
112104
@NonNull
113105
public Date toDate() {
114106
return new Date(seconds * 1000 + (nanoseconds / 1000000));
@@ -120,14 +112,13 @@ public int describeContents() {
120112
}
121113

122114
@Override
123-
public void writeToParcel(Parcel dest, int flags) {
115+
public void writeToParcel(@NonNull Parcel dest, int flags) {
124116
dest.writeLong(this.seconds);
125117
dest.writeInt(this.nanoseconds);
126118
}
127119

128120
@Override
129-
@PublicApi
130-
public int compareTo(Timestamp other) {
121+
public int compareTo(@NonNull Timestamp other) {
131122
if (seconds == other.seconds) {
132123
return Integer.signum(nanoseconds - other.nanoseconds);
133124
}

firebase-firestore/src/main/java/com/google/firebase/firestore/Blob.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
import androidx.annotation.NonNull;
2020
import androidx.annotation.Nullable;
2121
import androidx.annotation.RestrictTo;
22-
import com.google.firebase.annotations.PublicApi;
2322
import com.google.firebase.firestore.util.Util;
2423
import com.google.protobuf.ByteString;
2524

2625
/** Immutable class representing an array of bytes in Firestore. */
27-
@PublicApi
2826
public class Blob implements Comparable<Blob> {
2927
private final ByteString bytes;
3028

@@ -39,7 +37,6 @@ private Blob(ByteString bytes) {
3937
* @return The new Blob instance
4038
*/
4139
@NonNull
42-
@PublicApi
4340
public static Blob fromBytes(@NonNull byte[] bytes) {
4441
checkNotNull(bytes, "Provided bytes array must not be null.");
4542
return new Blob(ByteString.copyFrom(bytes));
@@ -55,7 +52,6 @@ public static Blob fromByteString(@NonNull ByteString bytes) {
5552

5653
/** @return The bytes of this blob as a new byte[] array. */
5754
@NonNull
58-
@PublicApi
5955
public byte[] toBytes() {
6056
return bytes.toByteArray();
6157
}
@@ -84,7 +80,6 @@ public int hashCode() {
8480
}
8581

8682
@Override
87-
@PublicApi
8883
public int compareTo(@NonNull Blob other) {
8984
int size = Math.min(bytes.size(), other.bytes.size());
9085
for (int i = 0; i < size; i++) {

firebase-firestore/src/main/java/com/google/firebase/firestore/CollectionReference.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
import static com.google.common.base.Preconditions.checkNotNull;
1818

1919
import androidx.annotation.NonNull;
20+
import androidx.annotation.Nullable;
2021
import com.google.android.gms.tasks.Task;
21-
import com.google.firebase.annotations.PublicApi;
2222
import com.google.firebase.firestore.model.DocumentKey;
2323
import com.google.firebase.firestore.model.ResourcePath;
2424
import com.google.firebase.firestore.util.Executors;
2525
import com.google.firebase.firestore.util.Util;
26-
import javax.annotation.Nullable;
2726

2827
/**
2928
* A CollectionReference can be used for adding documents, getting document references, and querying
@@ -33,7 +32,6 @@
3332
* test mocks. Subclassing is not supported in production code and new SDK releases may break code
3433
* that does so.
3534
*/
36-
@PublicApi
3735
public class CollectionReference extends Query {
3836

3937
CollectionReference(ResourcePath path, FirebaseFirestore firestore) {
@@ -50,7 +48,6 @@ public class CollectionReference extends Query {
5048

5149
/** @return The ID of the collection. */
5250
@NonNull
53-
@PublicApi
5451
public String getId() {
5552
return query.getPath().getLastSegment();
5653
}
@@ -63,7 +60,6 @@ public String getId() {
6360
* collection.
6461
*/
6562
@Nullable
66-
@PublicApi
6763
public DocumentReference getParent() {
6864
ResourcePath parentPath = query.getPath().popLast();
6965
if (parentPath.isEmpty()) {
@@ -80,7 +76,6 @@ public DocumentReference getParent() {
8076
* @return The path of this collection.
8177
*/
8278
@NonNull
83-
@PublicApi
8479
public String getPath() {
8580
return query.getPath().canonicalString();
8681
}
@@ -92,7 +87,6 @@ public String getPath() {
9287
* @return A DocumentReference pointing to a new document with an auto-generated ID.
9388
*/
9489
@NonNull
95-
@PublicApi
9690
public DocumentReference document() {
9791
return document(Util.autoId());
9892
}
@@ -105,7 +99,6 @@ public DocumentReference document() {
10599
* @return The DocumentReference instance.
106100
*/
107101
@NonNull
108-
@PublicApi
109102
public DocumentReference document(@NonNull String documentPath) {
110103
checkNotNull(documentPath, "Provided document path must not be null.");
111104
return DocumentReference.forPath(
@@ -121,7 +114,6 @@ public DocumentReference document(@NonNull String documentPath) {
121114
* @return A Task that will be resolved with the DocumentReference of the newly created document.
122115
*/
123116
@NonNull
124-
@PublicApi
125117
public Task<DocumentReference> add(@NonNull Object data) {
126118
checkNotNull(data, "Provided data must not be null.");
127119
final DocumentReference ref = document();

firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentChange.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
import static com.google.firebase.firestore.util.Assert.hardAssert;
1818

1919
import androidx.annotation.NonNull;
20+
import androidx.annotation.Nullable;
2021
import androidx.annotation.VisibleForTesting;
21-
import com.google.firebase.annotations.PublicApi;
2222
import com.google.firebase.firestore.core.DocumentViewChange;
2323
import com.google.firebase.firestore.core.ViewSnapshot;
2424
import com.google.firebase.firestore.model.Document;
2525
import com.google.firebase.firestore.model.DocumentSet;
2626
import java.util.ArrayList;
2727
import java.util.List;
28-
import javax.annotation.Nullable;
2928

3029
/**
3130
* A DocumentChange represents a change to the documents matching a query. It contains the document
@@ -35,10 +34,8 @@
3534
* test mocks. Subclassing is not supported in production code and new SDK releases may break code
3635
* that does so.
3736
*/
38-
@PublicApi
3937
public class DocumentChange {
4038
/** An enumeration of snapshot diff types. */
41-
@PublicApi
4239
public enum Type {
4340
/** Indicates a new document was added to the set of documents matching the query. */
4441
ADDED,
@@ -91,7 +88,6 @@ public int hashCode() {
9188
}
9289

9390
@NonNull
94-
@PublicApi
9591
public Type getType() {
9692
return type;
9793
}
@@ -104,7 +100,6 @@ public Type getType() {
104100
* Type.REMOVED).
105101
*/
106102
@NonNull
107-
@PublicApi
108103
public QueryDocumentSnapshot getDocument() {
109104
return document;
110105
}
@@ -114,7 +109,6 @@ public QueryDocumentSnapshot getDocument() {
114109
* (i.e. supposing that all prior DocumentChange objects have been applied). Returns -1 for
115110
* 'added' events.
116111
*/
117-
@PublicApi
118112
public int getOldIndex() {
119113
return oldIndex;
120114
}
@@ -124,7 +118,6 @@ public int getOldIndex() {
124118
* supposing that all prior DocumentChange objects and the current DocumentChange object have been
125119
* applied). Returns -1 for 'removed' events.
126120
*/
127-
@PublicApi
128121
public int getNewIndex() {
129122
return newIndex;
130123
}

firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package com.google.firebase.firestore;
1616

17-
import com.google.firebase.annotations.PublicApi;
1817
import java.lang.annotation.ElementType;
1918
import java.lang.annotation.Retention;
2019
import java.lang.annotation.RetentionPolicy;
@@ -43,7 +42,6 @@
4342
* WriteBatch#set}), the property annotated by @DocumentId is ignored, which allows writing the POJO
4443
* back to any document, even if it's not the origin of the POJO.
4544
*/
46-
@PublicApi
4745
@Retention(RetentionPolicy.RUNTIME)
4846
@Target({ElementType.FIELD, ElementType.METHOD})
4947
public @interface DocumentId {}

0 commit comments

Comments
 (0)