diff --git a/firebase-firestore/firebase-firestore.gradle b/firebase-firestore/firebase-firestore.gradle index 6ab13a4ac87..8e3c6eca0ac 100644 --- a/firebase-firestore/firebase-firestore.gradle +++ b/firebase-firestore/firebase-firestore.gradle @@ -20,7 +20,6 @@ plugins { firebaseLibrary { testLab.enabled = true publishSources = true - staticAnalysis.disableKotlinInteropLint() } protobuf { diff --git a/firebase-firestore/src/main/java/com/google/firebase/Timestamp.java b/firebase-firestore/src/main/java/com/google/firebase/Timestamp.java index 36630741c9b..d7074a883d1 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/Timestamp.java +++ b/firebase-firestore/src/main/java/com/google/firebase/Timestamp.java @@ -19,7 +19,6 @@ import android.os.Parcel; import android.os.Parcelable; import androidx.annotation.NonNull; -import com.google.firebase.annotations.PublicApi; import java.util.Date; /** @@ -35,10 +34,9 @@ * https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto">The * reference timestamp definition */ -@PublicApi public final class Timestamp implements Comparable, Parcelable { - @PublicApi @NonNull + @NonNull public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override @@ -61,21 +59,19 @@ public Timestamp[] newArray(int size) { * Negative second values with fractions must still have non-negative nanoseconds values that * count forward in time. Must be from 0 to 999,999,999 inclusive. */ - @PublicApi public Timestamp(long seconds, int nanoseconds) { validateRange(seconds, nanoseconds); this.seconds = seconds; this.nanoseconds = nanoseconds; } - protected Timestamp(Parcel in) { + protected Timestamp(@NonNull Parcel in) { this.seconds = in.readLong(); this.nanoseconds = in.readInt(); } /** Creates a new timestamp from the given date. */ - @PublicApi - public Timestamp(Date date) { + public Timestamp(@NonNull Date date) { long millis = date.getTime(); long seconds = millis / 1000; int nanoseconds = (int) (millis % 1000) * 1000000; @@ -89,26 +85,22 @@ public Timestamp(Date date) { } /** Creates a new timestamp with the current date, with millisecond precision. */ - @PublicApi @NonNull public static Timestamp now() { return new Timestamp(new Date()); } /** Returns the seconds part of the timestamp. */ - @PublicApi public long getSeconds() { return seconds; } /** Returns the sub-second part of the timestamp, in nanoseconds. */ - @PublicApi public int getNanoseconds() { return nanoseconds; } /** Returns a new Date corresponding to this timestamp. This may lose precision. */ - @PublicApi @NonNull public Date toDate() { return new Date(seconds * 1000 + (nanoseconds / 1000000)); @@ -120,14 +112,13 @@ public int describeContents() { } @Override - public void writeToParcel(Parcel dest, int flags) { + public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeLong(this.seconds); dest.writeInt(this.nanoseconds); } @Override - @PublicApi - public int compareTo(Timestamp other) { + public int compareTo(@NonNull Timestamp other) { if (seconds == other.seconds) { return Integer.signum(nanoseconds - other.nanoseconds); } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/Blob.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/Blob.java index ce105f59e84..9bcf72597ca 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/Blob.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/Blob.java @@ -19,12 +19,10 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.util.Util; import com.google.protobuf.ByteString; /** Immutable class representing an array of bytes in Firestore. */ -@PublicApi public class Blob implements Comparable { private final ByteString bytes; @@ -39,7 +37,6 @@ private Blob(ByteString bytes) { * @return The new Blob instance */ @NonNull - @PublicApi public static Blob fromBytes(@NonNull byte[] bytes) { checkNotNull(bytes, "Provided bytes array must not be null."); return new Blob(ByteString.copyFrom(bytes)); @@ -55,7 +52,6 @@ public static Blob fromByteString(@NonNull ByteString bytes) { /** @return The bytes of this blob as a new byte[] array. */ @NonNull - @PublicApi public byte[] toBytes() { return bytes.toByteArray(); } @@ -84,7 +80,6 @@ public int hashCode() { } @Override - @PublicApi public int compareTo(@NonNull Blob other) { int size = Math.min(bytes.size(), other.bytes.size()); for (int i = 0; i < size; i++) { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/CollectionReference.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/CollectionReference.java index ccef135048f..dc8c7551b57 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/CollectionReference.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/CollectionReference.java @@ -17,13 +17,12 @@ import static com.google.common.base.Preconditions.checkNotNull; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.android.gms.tasks.Task; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.model.DocumentKey; import com.google.firebase.firestore.model.ResourcePath; import com.google.firebase.firestore.util.Executors; import com.google.firebase.firestore.util.Util; -import javax.annotation.Nullable; /** * A CollectionReference can be used for adding documents, getting document references, and querying @@ -33,7 +32,6 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class CollectionReference extends Query { CollectionReference(ResourcePath path, FirebaseFirestore firestore) { @@ -50,7 +48,6 @@ public class CollectionReference extends Query { /** @return The ID of the collection. */ @NonNull - @PublicApi public String getId() { return query.getPath().getLastSegment(); } @@ -63,7 +60,6 @@ public String getId() { * collection. */ @Nullable - @PublicApi public DocumentReference getParent() { ResourcePath parentPath = query.getPath().popLast(); if (parentPath.isEmpty()) { @@ -80,7 +76,6 @@ public DocumentReference getParent() { * @return The path of this collection. */ @NonNull - @PublicApi public String getPath() { return query.getPath().canonicalString(); } @@ -92,7 +87,6 @@ public String getPath() { * @return A DocumentReference pointing to a new document with an auto-generated ID. */ @NonNull - @PublicApi public DocumentReference document() { return document(Util.autoId()); } @@ -105,7 +99,6 @@ public DocumentReference document() { * @return The DocumentReference instance. */ @NonNull - @PublicApi public DocumentReference document(@NonNull String documentPath) { checkNotNull(documentPath, "Provided document path must not be null."); return DocumentReference.forPath( @@ -121,7 +114,6 @@ public DocumentReference document(@NonNull String documentPath) { * @return A Task that will be resolved with the DocumentReference of the newly created document. */ @NonNull - @PublicApi public Task add(@NonNull Object data) { checkNotNull(data, "Provided data must not be null."); final DocumentReference ref = document(); diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentChange.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentChange.java index f710b7e327c..a5112c3743c 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentChange.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentChange.java @@ -17,15 +17,14 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.core.DocumentViewChange; import com.google.firebase.firestore.core.ViewSnapshot; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.model.DocumentSet; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; /** * A DocumentChange represents a change to the documents matching a query. It contains the document @@ -35,10 +34,8 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class DocumentChange { /** An enumeration of snapshot diff types. */ - @PublicApi public enum Type { /** Indicates a new document was added to the set of documents matching the query. */ ADDED, @@ -91,7 +88,6 @@ public int hashCode() { } @NonNull - @PublicApi public Type getType() { return type; } @@ -104,7 +100,6 @@ public Type getType() { * Type.REMOVED). */ @NonNull - @PublicApi public QueryDocumentSnapshot getDocument() { return document; } @@ -114,7 +109,6 @@ public QueryDocumentSnapshot getDocument() { * (i.e. supposing that all prior DocumentChange objects have been applied). Returns -1 for * 'added' events. */ - @PublicApi public int getOldIndex() { return oldIndex; } @@ -124,7 +118,6 @@ public int getOldIndex() { * supposing that all prior DocumentChange objects and the current DocumentChange object have been * applied). Returns -1 for 'removed' events. */ - @PublicApi public int getNewIndex() { return newIndex; } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java index eb096e426ff..17f2ad12d0c 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java @@ -14,7 +14,6 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -43,7 +42,6 @@ * WriteBatch#set}), the property annotated by @DocumentId is ignored, which allows writing the POJO * back to any document, even if it's not the origin of the POJO. */ -@PublicApi @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.METHOD}) public @interface DocumentId {} diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentReference.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentReference.java index 1e3b5144cfc..7d7ad3a67c3 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentReference.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentReference.java @@ -21,10 +21,10 @@ import android.app.Activity; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import com.google.android.gms.tasks.Tasks; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.FirebaseFirestoreException.Code; import com.google.firebase.firestore.core.ActivityScope; import com.google.firebase.firestore.core.AsyncEventListener; @@ -45,7 +45,6 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; -import javax.annotation.Nullable; /** * A DocumentReference refers to a document location in a Firestore database and can be used to @@ -57,7 +56,6 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class DocumentReference { private final DocumentKey key; @@ -91,13 +89,11 @@ DocumentKey getKey() { /** Gets the Firestore instance associated with this document reference. */ @NonNull - @PublicApi public FirebaseFirestore getFirestore() { return firestore; } @NonNull - @PublicApi public String getId() { return key.getPath().getLastSegment(); } @@ -108,7 +104,6 @@ public String getId() { * @return The CollectionReference that contains this document. */ @NonNull - @PublicApi public CollectionReference getParent() { return new CollectionReference(key.getPath().popLast(), firestore); } @@ -120,7 +115,6 @@ public CollectionReference getParent() { * @return The path of this document. */ @NonNull - @PublicApi public String getPath() { return key.getPath().canonicalString(); } @@ -133,7 +127,6 @@ public String getPath() { * @return The CollectionReference instance. */ @NonNull - @PublicApi public CollectionReference collection(@NonNull String collectionPath) { checkNotNull(collectionPath, "Provided collection path must not be null."); return new CollectionReference( @@ -149,7 +142,6 @@ public CollectionReference collection(@NonNull String collectionPath) { * @return A Task that will be resolved when the write finishes. */ @NonNull - @PublicApi public Task set(@NonNull Object data) { return set(data, SetOptions.OVERWRITE); } @@ -165,7 +157,6 @@ public Task set(@NonNull Object data) { * @return A Task that will be resolved when the write finishes. */ @NonNull - @PublicApi public Task set(@NonNull Object data, @NonNull SetOptions options) { checkNotNull(data, "Provided data must not be null."); checkNotNull(options, "Provided options must not be null."); @@ -188,7 +179,6 @@ public Task set(@NonNull Object data, @NonNull SetOptions options) { * @return A Task that will be resolved when the write finishes. */ @NonNull - @PublicApi public Task update(@NonNull Map data) { ParsedUpdateData parsedData = firestore.getDataConverter().parseUpdateData(data); return update(parsedData); @@ -205,7 +195,6 @@ public Task update(@NonNull Map data) { * @return A Task that will be resolved when the write finishes. */ @NonNull - @PublicApi public Task update( @NonNull String field, @Nullable Object value, Object... moreFieldsAndValues) { ParsedUpdateData parsedData = @@ -227,7 +216,6 @@ public Task update( * @return A Task that will be resolved when the write finishes. */ @NonNull - @PublicApi public Task update( @NonNull FieldPath fieldPath, @Nullable Object value, Object... moreFieldsAndValues) { ParsedUpdateData parsedData = @@ -252,7 +240,6 @@ private Task update(@NonNull ParsedUpdateData parsedData) { * @return A Task that will be resolved when the delete completes. */ @NonNull - @PublicApi public Task delete() { return firestore .getClient() @@ -267,7 +254,6 @@ public Task delete() { * DocumentReference. */ @NonNull - @PublicApi public Task get() { return get(Source.DEFAULT); } @@ -284,7 +270,6 @@ public Task get() { * DocumentReference. */ @NonNull - @PublicApi public Task get(@NonNull Source source) { if (source == Source.CACHE) { return firestore @@ -378,7 +363,6 @@ private Task getViaSnapshotListener(Source source) { * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull EventListener listener) { return addSnapshotListener(MetadataChanges.EXCLUDE, listener); @@ -392,7 +376,6 @@ public ListenerRegistration addSnapshotListener( * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull Executor executor, @NonNull EventListener listener) { return addSnapshotListener(executor, MetadataChanges.EXCLUDE, listener); @@ -409,7 +392,6 @@ public ListenerRegistration addSnapshotListener( * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull Activity activity, @NonNull EventListener listener) { return addSnapshotListener(activity, MetadataChanges.EXCLUDE, listener); @@ -424,7 +406,6 @@ public ListenerRegistration addSnapshotListener( * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull MetadataChanges metadataChanges, @NonNull EventListener listener) { return addSnapshotListener(Executors.DEFAULT_CALLBACK_EXECUTOR, metadataChanges, listener); @@ -440,7 +421,6 @@ public ListenerRegistration addSnapshotListener( * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull Executor executor, @NonNull MetadataChanges metadataChanges, @@ -464,7 +444,6 @@ public ListenerRegistration addSnapshotListener( * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull Activity activity, @NonNull MetadataChanges metadataChanges, diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentSnapshot.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentSnapshot.java index ec3bcda7e07..f7cc2a5731c 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentSnapshot.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentSnapshot.java @@ -17,8 +17,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.model.DatabaseId; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.model.DocumentKey; @@ -35,7 +35,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.annotation.Nullable; /** * A DocumentSnapshot contains data read from a document in your Firestore database. The data can be @@ -49,14 +48,12 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class DocumentSnapshot { /** * Controls the return value for server timestamps that have not yet been set to their final * value. */ - @PublicApi public enum ServerTimestampBehavior { /** * Return 'null' for {@link com.google.firebase.firestore.FieldValue#serverTimestamp @@ -126,20 +123,17 @@ static DocumentSnapshot fromNoDocument( /** @return The id of the document. */ @NonNull - @PublicApi public String getId() { return key.getPath().getLastSegment(); } /** @return The metadata for this document snapshot. */ @NonNull - @PublicApi public SnapshotMetadata getMetadata() { return metadata; } /** @return true if the document existed in this snapshot. */ - @PublicApi public boolean exists() { return doc != null; } @@ -156,7 +150,6 @@ Document getDocument() { * @return The fields of the document as a Map or null if the document doesn't exist. */ @Nullable - @PublicApi public Map getData() { return getData(ServerTimestampBehavior.DEFAULT); } @@ -170,7 +163,6 @@ public Map getData() { * @return The fields of the document as a Map or null if the document doesn't exist. */ @Nullable - @PublicApi public Map getData(@NonNull ServerTimestampBehavior serverTimestampBehavior) { checkNotNull( serverTimestampBehavior, "Provided serverTimestampBehavior value must not be null."); @@ -191,7 +183,6 @@ public Map getData(@NonNull ServerTimestampBehavior serverTimest * exist. */ @Nullable - @PublicApi public T toObject(@NonNull Class valueType) { return toObject(valueType, ServerTimestampBehavior.DEFAULT); } @@ -206,7 +197,6 @@ public T toObject(@NonNull Class valueType) { * exist. */ @Nullable - @PublicApi public T toObject( @NonNull Class valueType, @NonNull ServerTimestampBehavior serverTimestampBehavior) { checkNotNull(valueType, "Provided POJO type must not be null."); @@ -225,7 +215,6 @@ public T toObject( * @param field the path to the field. * @return true iff the field exists. */ - @PublicApi public boolean contains(@NonNull String field) { return contains(FieldPath.fromDotSeparatedPath(field)); } @@ -237,7 +226,6 @@ public boolean contains(@NonNull String field) { * @param fieldPath the path to the field. * @return true iff the field exists. */ - @PublicApi public boolean contains(@NonNull FieldPath fieldPath) { checkNotNull(fieldPath, "Provided field path must not be null."); return (doc != null) && (doc.getField(fieldPath.getInternalPath()) != null); @@ -250,7 +238,6 @@ public boolean contains(@NonNull FieldPath fieldPath) { * @return The value at the given field or null. */ @Nullable - @PublicApi public Object get(@NonNull String field) { return get(FieldPath.fromDotSeparatedPath(field), ServerTimestampBehavior.DEFAULT); } @@ -264,7 +251,6 @@ public Object get(@NonNull String field) { * @return The value at the given field or null. */ @Nullable - @PublicApi public Object get( @NonNull String field, @NonNull ServerTimestampBehavior serverTimestampBehavior) { return get(FieldPath.fromDotSeparatedPath(field), serverTimestampBehavior); @@ -277,7 +263,6 @@ public Object get( * @return The value at the given field or null. */ @Nullable - @PublicApi public Object get(@NonNull FieldPath fieldPath) { return get(fieldPath, ServerTimestampBehavior.DEFAULT); } @@ -291,7 +276,6 @@ public Object get(@NonNull FieldPath fieldPath) { * @return The value at the given field or null. */ @Nullable - @PublicApi public Object get( @NonNull FieldPath fieldPath, @NonNull ServerTimestampBehavior serverTimestampBehavior) { checkNotNull(fieldPath, "Provided field path must not be null."); @@ -313,7 +297,6 @@ public Object get( * @return The value at the given field or null. */ @Nullable - @PublicApi public T get(@NonNull String field, @NonNull Class valueType) { return get(FieldPath.fromDotSeparatedPath(field), valueType, ServerTimestampBehavior.DEFAULT); } @@ -329,7 +312,6 @@ public T get(@NonNull String field, @NonNull Class valueType) { * @return The value at the given field or null. */ @Nullable - @PublicApi public T get( @NonNull String field, @NonNull Class valueType, @@ -346,7 +328,6 @@ public T get( * @return The value at the given field or null. */ @Nullable - @PublicApi public T get(@NonNull FieldPath fieldPath, @NonNull Class valueType) { return get(fieldPath, valueType, ServerTimestampBehavior.DEFAULT); } @@ -362,7 +343,6 @@ public T get(@NonNull FieldPath fieldPath, @NonNull Class valueType) { * @return The value at the given field or null. */ @Nullable - @PublicApi public T get( @NonNull FieldPath fieldPath, @NonNull Class valueType, @@ -381,7 +361,6 @@ public T get( * @return The value of the field */ @Nullable - @PublicApi public Boolean getBoolean(@NonNull String field) { return getTypedValue(field, Boolean.class); } @@ -394,7 +373,6 @@ public Boolean getBoolean(@NonNull String field) { * @return The value of the field */ @Nullable - @PublicApi public Double getDouble(@NonNull String field) { Number val = getTypedValue(field, Number.class); return val != null ? val.doubleValue() : null; @@ -408,7 +386,6 @@ public Double getDouble(@NonNull String field) { * @return The value of the field */ @Nullable - @PublicApi public String getString(@NonNull String field) { return getTypedValue(field, String.class); } @@ -421,7 +398,6 @@ public String getString(@NonNull String field) { * @return The value of the field */ @Nullable - @PublicApi public Long getLong(@NonNull String field) { Number val = getTypedValue(field, Number.class); return val != null ? val.longValue() : null; @@ -435,7 +411,6 @@ public Long getLong(@NonNull String field) { * @return The value of the field */ @Nullable - @PublicApi public Date getDate(@NonNull String field) { return getDate(field, ServerTimestampBehavior.DEFAULT); } @@ -453,7 +428,6 @@ public Date getDate(@NonNull String field) { * @return The value of the field */ @Nullable - @PublicApi public Date getDate( @NonNull String field, @NonNull ServerTimestampBehavior serverTimestampBehavior) { checkNotNull(field, "Provided field path must not be null."); @@ -478,7 +452,6 @@ public Date getDate( * @return The value of the field */ @Nullable - @PublicApi public Timestamp getTimestamp(@NonNull String field) { return getTimestamp(field, ServerTimestampBehavior.DEFAULT); } @@ -496,7 +469,6 @@ public Timestamp getTimestamp(@NonNull String field) { * @return The value of the field */ @Nullable - @PublicApi public Timestamp getTimestamp( @NonNull String field, @NonNull ServerTimestampBehavior serverTimestampBehavior) { checkNotNull(field, "Provided field path must not be null."); @@ -517,7 +489,6 @@ public Timestamp getTimestamp( * @return The value of the field */ @Nullable - @PublicApi public Blob getBlob(@NonNull String field) { return getTypedValue(field, Blob.class); } @@ -530,7 +501,6 @@ public Blob getBlob(@NonNull String field) { * @return The value of the field */ @Nullable - @PublicApi public GeoPoint getGeoPoint(@NonNull String field) { return getTypedValue(field, GeoPoint.class); } @@ -543,7 +513,6 @@ public GeoPoint getGeoPoint(@NonNull String field) { * @return The value of the field */ @Nullable - @PublicApi public DocumentReference getDocumentReference(@NonNull String field) { return getTypedValue(field, DocumentReference.class); } @@ -554,7 +523,6 @@ public DocumentReference getDocumentReference(@NonNull String field) { * @return The reference to the document. */ @NonNull - @PublicApi public DocumentReference getReference() { return new DocumentReference(key, firestore); } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/EventListener.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/EventListener.java index dfde9eae8ec..5d021c867b4 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/EventListener.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/EventListener.java @@ -14,11 +14,9 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; -import javax.annotation.Nullable; +import androidx.annotation.Nullable; /** An interface for event listeners. */ -@PublicApi public interface EventListener { /** @@ -28,6 +26,5 @@ public interface EventListener { * @param value The value of the event. null if there was an error. * @param error The error if there was error. null otherwise. */ - @PublicApi void onEvent(@Nullable T value, @Nullable FirebaseFirestoreException error); } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/Exclude.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/Exclude.java index 21a484a2b1f..f01108a8077 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/Exclude.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/Exclude.java @@ -14,14 +14,12 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** Marks a field as excluded from the Database. */ -@PublicApi @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.FIELD}) public @interface Exclude {} diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/FieldPath.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/FieldPath.java index ee8c1bc51ec..3a04494c06a 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/FieldPath.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/FieldPath.java @@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import androidx.annotation.NonNull; -import com.google.firebase.annotations.PublicApi; import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; @@ -28,7 +27,6 @@ * (referring to a top level field in the document), or a list of field names (referring to a nested * field in the document). */ -@PublicApi public final class FieldPath { /** Matches any characters in a field path string that are reserved. */ private static final Pattern RESERVED = Pattern.compile("[~*/\\[\\]]"); @@ -54,8 +52,8 @@ com.google.firebase.firestore.model.FieldPath getInternalPath() { * @param fieldNames A list of field names. * @return A {@code FieldPath} that points to a field location in a document. */ - @PublicApi - public static FieldPath of(@NonNull String... fieldNames) { + @NonNull + public static FieldPath of(String... fieldNames) { checkArgument(fieldNames.length > 0, "Invalid field path. Provided path must not be empty."); for (int i = 0; i < fieldNames.length; ++i) { @@ -75,7 +73,6 @@ public static FieldPath of(@NonNull String... fieldNames) { * queries to sort or filter by the document ID. */ @NonNull - @PublicApi public static FieldPath documentId() { return DOCUMENT_ID_INSTANCE; } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/FieldValue.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/FieldValue.java index 39ac035297d..be22346faea 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/FieldValue.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/FieldValue.java @@ -15,12 +15,10 @@ package com.google.firebase.firestore; import androidx.annotation.NonNull; -import com.google.firebase.annotations.PublicApi; import java.util.Arrays; import java.util.List; /** Sentinel values that can be used when writing document fields with set() or update(). */ -@PublicApi public abstract class FieldValue { FieldValue() {} @@ -107,7 +105,6 @@ Number getOperand() { /** Returns a sentinel for use with update() to mark a field for deletion. */ @NonNull - @PublicApi public static FieldValue delete() { return DELETE_INSTANCE; } @@ -117,7 +114,6 @@ public static FieldValue delete() { * the written data. */ @NonNull - @PublicApi public static FieldValue serverTimestamp() { return SERVER_TIMESTAMP_INSTANCE; } @@ -133,8 +129,7 @@ public static FieldValue serverTimestamp() { * @return The FieldValue sentinel for use in a call to set() or update(). */ @NonNull - @PublicApi - public static FieldValue arrayUnion(@NonNull Object... elements) { + public static FieldValue arrayUnion(Object... elements) { return new ArrayUnionFieldValue(Arrays.asList(elements)); } @@ -148,8 +143,7 @@ public static FieldValue arrayUnion(@NonNull Object... elements) { * @return The FieldValue sentinel for use in a call to set() or update(). */ @NonNull - @PublicApi - public static FieldValue arrayRemove(@NonNull Object... elements) { + public static FieldValue arrayRemove(Object... elements) { return new ArrayRemoveFieldValue(Arrays.asList(elements)); } @@ -167,7 +161,6 @@ public static FieldValue arrayRemove(@NonNull Object... elements) { * @return The FieldValue sentinel for use in a call to set() or update(). */ @NonNull - @PublicApi public static FieldValue increment(long l) { return new NumericIncrementFieldValue(l); } @@ -183,7 +176,6 @@ public static FieldValue increment(long l) { * @return The FieldValue sentinel for use in a call to set() or update(). */ @NonNull - @PublicApi public static FieldValue increment(double l) { return new NumericIncrementFieldValue(l); } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java index d6348336a6e..0d4b7a04020 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java @@ -25,7 +25,6 @@ import com.google.android.gms.tasks.Tasks; import com.google.common.base.Function; import com.google.firebase.FirebaseApp; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.auth.internal.InternalAuthProvider; import com.google.firebase.firestore.FirebaseFirestoreException.Code; import com.google.firebase.firestore.auth.CredentialsProvider; @@ -48,7 +47,6 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class FirebaseFirestore { private static final String TAG = "FirebaseFirestore"; @@ -65,7 +63,6 @@ public class FirebaseFirestore { private volatile FirestoreClient client; @NonNull - @PublicApi public static FirebaseFirestore getInstance() { FirebaseApp app = FirebaseApp.getInstance(); if (app == null) { @@ -75,7 +72,6 @@ public static FirebaseFirestore getInstance() { } @NonNull - @PublicApi public static FirebaseFirestore getInstance(@NonNull FirebaseApp app) { return getInstance(app, DatabaseId.DEFAULT_DATABASE_ID); } @@ -142,7 +138,6 @@ static FirebaseFirestore newInstance( /** Returns the settings used by this FirebaseFirestore object. */ @NonNull - @PublicApi public FirebaseFirestoreSettings getFirestoreSettings() { return settings; } @@ -151,7 +146,6 @@ public FirebaseFirestoreSettings getFirestoreSettings() { * Sets any custom settings used to configure this FirebaseFirestore object. This method can only * be called before calling any other methods on this object. */ - @PublicApi public void setFirestoreSettings(@NonNull FirebaseFirestoreSettings settings) { synchronized (databaseId) { checkNotNull(settings, "Provided settings must not be null."); @@ -190,7 +184,6 @@ private void ensureClientConfigured() { * @return The FirebaseApp instance to which this FirebaseFirestore belongs. */ @NonNull - @PublicApi public FirebaseApp getApp() { return firebaseApp; } @@ -203,7 +196,6 @@ public FirebaseApp getApp() { * @return The CollectionReference instance. */ @NonNull - @PublicApi public CollectionReference collection(@NonNull String collectionPath) { checkNotNull(collectionPath, "Provided collection path must not be null."); ensureClientConfigured(); @@ -218,7 +210,6 @@ public CollectionReference collection(@NonNull String collectionPath) { * @return The DocumentReference instance. */ @NonNull - @PublicApi public DocumentReference document(@NonNull String documentPath) { checkNotNull(documentPath, "Provided document path must not be null."); ensureClientConfigured(); @@ -234,7 +225,6 @@ public DocumentReference document(@NonNull String documentPath) { * @return The created Query. */ @NonNull - @PublicApi public Query collectionGroup(@NonNull String collectionId) { checkNotNull(collectionId, "Provided collection ID must not be null."); if (collectionId.contains("/")) { @@ -289,7 +279,6 @@ private Task runTransaction( * @return The task returned from the updateFunction. */ @NonNull - @PublicApi public Task runTransaction( @NonNull Transaction.Function updateFunction) { checkNotNull(updateFunction, "Provided transaction update function must not be null."); @@ -307,7 +296,6 @@ public Task runTransaction( * @return The created WriteBatch object. */ @NonNull - @PublicApi public WriteBatch batch() { ensureClientConfigured(); @@ -322,7 +310,6 @@ public WriteBatch batch() { * @return A Task that will be resolved when the batch has been committed. */ @NonNull - @PublicApi public Task runBatch(@NonNull WriteBatch.Function batchFunction) { WriteBatch batch = batch(); batchFunction.apply(batch); @@ -346,7 +333,7 @@ AsyncQueue getAsyncQueue() { * * @return A Task that will be completed once networking is enabled. */ - @PublicApi + @NonNull public Task enableNetwork() { ensureClientConfigured(); return client.enableNetwork(); @@ -359,14 +346,13 @@ public Task enableNetwork() { * * @return A Task that will be completed once networking is disabled. */ - @PublicApi + @NonNull public Task disableNetwork() { ensureClientConfigured(); return client.disableNetwork(); } /** Globally enables / disables Firestore logging for the SDK. */ - @PublicApi public static void setLoggingEnabled(boolean loggingEnabled) { if (loggingEnabled) { Logger.setLogLevel(Level.DEBUG); @@ -393,7 +379,7 @@ public static void setLoggingEnabled(boolean loggingEnabled) { * @return A Task that is resolved when the persistent storage is cleared. Otherwise, * the Task is rejected with an error. */ - @PublicApi + @NonNull public Task clearPersistence() { final TaskCompletionSource source = new TaskCompletionSource<>(); asyncQueue.enqueueAndForget( diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestoreException.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestoreException.java index df0f1045f10..939330b51bc 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestoreException.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestoreException.java @@ -18,18 +18,16 @@ import android.util.SparseArray; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.firebase.FirebaseException; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.util.Assert; /** A class of exceptions thrown by Firestore */ -@PublicApi public class FirebaseFirestoreException extends FirebaseException { /** * The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md */ - @PublicApi public enum Code { /** * The operation completed successfully. FirebaseFirestoreException will never have a status of @@ -115,7 +113,6 @@ public enum Code { } /** The numerical value of the code. */ - @PublicApi public int value() { return value; } @@ -137,7 +134,6 @@ private static SparseArray buildStatusList() { } @NonNull - @PublicApi public static Code fromValue(int value) { return STATUS_LIST.get(value, Code.UNKNOWN); } @@ -145,7 +141,6 @@ public static Code fromValue(int value) { @NonNull private final Code code; - @PublicApi public FirebaseFirestoreException(@NonNull String detailMessage, @NonNull Code code) { super(detailMessage); checkNotNull(detailMessage, "Provided message must not be null."); @@ -154,9 +149,8 @@ public FirebaseFirestoreException(@NonNull String detailMessage, @NonNull Code c this.code = checkNotNull(code, "Provided code must not be null."); } - @PublicApi public FirebaseFirestoreException( - @NonNull String detailMessage, @NonNull Code code, Throwable cause) { + @NonNull String detailMessage, @NonNull Code code, @Nullable Throwable cause) { super(detailMessage, cause); checkNotNull(detailMessage, "Provided message must not be null."); Assert.hardAssert( @@ -170,7 +164,6 @@ public FirebaseFirestoreException( * @return the code for the FirebaseFirestoreException */ @NonNull - @PublicApi public Code getCode() { return code; } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestoreSettings.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestoreSettings.java index 8e98761b6d9..2b7781a9f53 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestoreSettings.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestoreSettings.java @@ -19,16 +19,14 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.google.common.base.MoreObjects; -import com.google.firebase.annotations.PublicApi; /** Settings used to configure a FirebaseFirestore instance. */ -@PublicApi public final class FirebaseFirestoreSettings { /** * Constant to use with {@link FirebaseFirestoreSettings.Builder#setCacheSizeBytes(long)} to * disable garbage collection. */ - @PublicApi public static final long CACHE_SIZE_UNLIMITED = -1; + public static final long CACHE_SIZE_UNLIMITED = -1; private static final long MINIMUM_CACHE_BYTES = 1 * 1024 * 1024; // 1 MB private static final long DEFAULT_CACHE_SIZE_BYTES = 100 * 1024 * 1024; // 100 MB @@ -36,7 +34,6 @@ public final class FirebaseFirestoreSettings { private static final boolean DEFAULT_TIMESTAMPS_IN_SNAPSHOTS_ENABLED = true; /** A Builder for creating {@link FirebaseFirestoreSettings}. */ - @PublicApi public static final class Builder { private String host; private boolean sslEnabled; @@ -45,7 +42,6 @@ public static final class Builder { private long cacheSizeBytes; /** Constructs a new FirebaseFirestoreSettings Builder object. */ - @PublicApi public Builder() { host = DEFAULT_HOST; sslEnabled = true; @@ -58,7 +54,6 @@ public Builder() { * Constructs a new FirebaseFirestoreSettings Builder based on an existing * FirebaseFirestoreSettings object. */ - @PublicApi public Builder(@NonNull FirebaseFirestoreSettings settings) { checkNotNull(settings, "Provided settings must not be null."); host = settings.host; @@ -74,7 +69,6 @@ public Builder(@NonNull FirebaseFirestoreSettings settings) { * @return A settings object with the host set. */ @NonNull - @PublicApi public Builder setHost(@NonNull String host) { this.host = checkNotNull(host, "Provided host must not be null."); return this; @@ -86,7 +80,6 @@ public Builder setHost(@NonNull String host) { * @return A settings object that uses SSL as specified by the value. */ @NonNull - @PublicApi public Builder setSslEnabled(boolean value) { this.sslEnabled = value; return this; @@ -99,7 +92,6 @@ public Builder setSslEnabled(boolean value) { * value. */ @NonNull - @PublicApi public Builder setPersistenceEnabled(boolean value) { this.persistenceEnabled = value; return this; @@ -127,7 +119,6 @@ public Builder setPersistenceEnabled(boolean value) { */ @NonNull @Deprecated - @PublicApi public Builder setTimestampsInSnapshotsEnabled(boolean value) { this.timestampsInSnapshotsEnabled = value; return this; @@ -145,7 +136,6 @@ public Builder setTimestampsInSnapshotsEnabled(boolean value) { * {@code value}. */ @NonNull - @PublicApi public Builder setCacheSizeBytes(long value) { if (value != CACHE_SIZE_UNLIMITED && value < MINIMUM_CACHE_BYTES) { throw new IllegalArgumentException( @@ -156,7 +146,6 @@ public Builder setCacheSizeBytes(long value) { } @NonNull - @PublicApi public FirebaseFirestoreSettings build() { if (!this.sslEnabled && this.host.equals(DEFAULT_HOST)) { throw new IllegalStateException( @@ -221,19 +210,16 @@ public String toString() { /** Returns the host of the Firestore backend. */ @NonNull - @PublicApi public String getHost() { return host; } /** Returns whether or not to use SSL for communication. */ - @PublicApi public boolean isSslEnabled() { return sslEnabled; } /** Returns whether or not to use local persistent storage. */ - @PublicApi public boolean isPersistenceEnabled() { return persistenceEnabled; } @@ -242,7 +228,6 @@ public boolean isPersistenceEnabled() { * Returns whether or not {@link DocumentSnapshot DocumentSnapshots} return timestamp fields as * {@link com.google.firebase.Timestamp Timestamps}. */ - @PublicApi public boolean areTimestampsInSnapshotsEnabled() { return timestampsInSnapshotsEnabled; } @@ -251,7 +236,6 @@ public boolean areTimestampsInSnapshotsEnabled() { * Returns the threshold for the cache size above which the SDK will attempt to collect the least * recently used documents. */ - @PublicApi public long getCacheSizeBytes() { return cacheSizeBytes; } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/GeoPoint.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/GeoPoint.java index 665e17f1ae2..ca3774e1e3b 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/GeoPoint.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/GeoPoint.java @@ -16,11 +16,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.util.Util; /** Immutable class representing a GeoPoint in Firestore */ -@PublicApi public class GeoPoint implements Comparable { private final double latitude; private final double longitude; @@ -31,7 +29,6 @@ public class GeoPoint implements Comparable { * @param latitude The latitude of this GeoPoint in the range [-90, 90]. * @param longitude The longitude of this GeoPoint in the range [-180, 180]. */ - @PublicApi public GeoPoint(double latitude, double longitude) { if (Double.isNaN(latitude) || latitude < -90 || latitude > 90) { throw new IllegalArgumentException("Latitude must be in the range of [-90, 90]"); @@ -44,19 +41,16 @@ public GeoPoint(double latitude, double longitude) { } /** @return The latitude value of this GeoPoint. */ - @PublicApi public double getLatitude() { return latitude; } /** @return The longitude value of this GeoPoint. */ - @PublicApi public double getLongitude() { return longitude; } @Override - @PublicApi public int compareTo(@NonNull GeoPoint other) { int comparison = Util.compareDoubles(latitude, other.latitude); if (comparison == 0) { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/IgnoreExtraProperties.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/IgnoreExtraProperties.java index bc11755bcaa..ca13a00d294 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/IgnoreExtraProperties.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/IgnoreExtraProperties.java @@ -14,7 +14,6 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -24,7 +23,6 @@ * Properties that don't map to class fields are ignored when serializing to a class annotated with * this annotation. */ -@PublicApi @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) public @interface IgnoreExtraProperties {} diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/ListenerRegistration.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/ListenerRegistration.java index 45ec0d21e6d..ae2d7d990a1 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/ListenerRegistration.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/ListenerRegistration.java @@ -14,16 +14,12 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; - /** Represents a listener that can be removed by calling remove(). */ -@PublicApi public interface ListenerRegistration { /** * Removes the listener being tracked by this ListenerRegistration. After the initial call, * subsequent calls have no effect. */ - @PublicApi void remove(); } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/MetadataChanges.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/MetadataChanges.java index 5451057c857..5977355e070 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/MetadataChanges.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/MetadataChanges.java @@ -14,13 +14,10 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; - /** * Indicates whether metadata-only changes (i.e. only {@code DocumentSnapshot.getMetadata()} or * {@code Query.getMetadata()} changed) should trigger snapshot events. */ -@PublicApi public enum MetadataChanges { EXCLUDE, INCLUDE diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/PropertyName.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/PropertyName.java index ef4674bc0dd..7e46c0f4c0a 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/PropertyName.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/PropertyName.java @@ -14,14 +14,12 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** Marks a field to be renamed when serialized. */ -@PublicApi @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.FIELD}) public @interface PropertyName { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/Query.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/Query.java index 36a6d9fa930..9df5f92d0fa 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/Query.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/Query.java @@ -20,10 +20,10 @@ import android.app.Activity; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import com.google.android.gms.tasks.Tasks; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.FirebaseFirestoreException.Code; import com.google.firebase.firestore.core.ActivityScope; import com.google.firebase.firestore.core.AsyncEventListener; @@ -50,7 +50,6 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; -import javax.annotation.Nullable; /** * A Query which you can read or listen to. You can also construct refined Query objects by adding @@ -60,14 +59,12 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class Query { final com.google.firebase.firestore.core.Query query; final FirebaseFirestore firestore; /** An enum for the direction of a sort. */ - @PublicApi public enum Direction { ASCENDING, DESCENDING @@ -80,7 +77,6 @@ public enum Direction { /** Gets the Firestore instance associated with this query. */ @NonNull - @PublicApi public FirebaseFirestore getFirestore() { return firestore; } @@ -94,7 +90,6 @@ public FirebaseFirestore getFirestore() { * @return The created Query. */ @NonNull - @PublicApi public Query whereEqualTo(@NonNull String field, @Nullable Object value) { return whereHelper(FieldPath.fromDotSeparatedPath(field), Operator.EQUAL, value); } @@ -108,7 +103,6 @@ public Query whereEqualTo(@NonNull String field, @Nullable Object value) { * @return The created Query. */ @NonNull - @PublicApi public Query whereEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) { return whereHelper(fieldPath, Operator.EQUAL, value); } @@ -122,7 +116,6 @@ public Query whereEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) * @return The created Query. */ @NonNull - @PublicApi public Query whereLessThan(@NonNull String field, @NonNull Object value) { return whereHelper(FieldPath.fromDotSeparatedPath(field), Operator.LESS_THAN, value); } @@ -136,7 +129,6 @@ public Query whereLessThan(@NonNull String field, @NonNull Object value) { * @return The created Query. */ @NonNull - @PublicApi public Query whereLessThan(@NonNull FieldPath fieldPath, @NonNull Object value) { return whereHelper(fieldPath, Operator.LESS_THAN, value); } @@ -150,7 +142,6 @@ public Query whereLessThan(@NonNull FieldPath fieldPath, @NonNull Object value) * @return The created Query. */ @NonNull - @PublicApi public Query whereLessThanOrEqualTo(@NonNull String field, @NonNull Object value) { return whereHelper(FieldPath.fromDotSeparatedPath(field), Operator.LESS_THAN_OR_EQUAL, value); } @@ -164,7 +155,6 @@ public Query whereLessThanOrEqualTo(@NonNull String field, @NonNull Object value * @return The created Query. */ @NonNull - @PublicApi public Query whereLessThanOrEqualTo(@NonNull FieldPath fieldPath, @NonNull Object value) { return whereHelper(fieldPath, Operator.LESS_THAN_OR_EQUAL, value); } @@ -178,7 +168,6 @@ public Query whereLessThanOrEqualTo(@NonNull FieldPath fieldPath, @NonNull Objec * @return The created Query. */ @NonNull - @PublicApi public Query whereGreaterThan(@NonNull String field, @NonNull Object value) { return whereHelper(FieldPath.fromDotSeparatedPath(field), Operator.GREATER_THAN, value); } @@ -192,7 +181,6 @@ public Query whereGreaterThan(@NonNull String field, @NonNull Object value) { * @return The created Query. */ @NonNull - @PublicApi public Query whereGreaterThan(@NonNull FieldPath fieldPath, @NonNull Object value) { return whereHelper(fieldPath, Operator.GREATER_THAN, value); } @@ -206,7 +194,6 @@ public Query whereGreaterThan(@NonNull FieldPath fieldPath, @NonNull Object valu * @return The created Query. */ @NonNull - @PublicApi public Query whereGreaterThanOrEqualTo(@NonNull String field, @NonNull Object value) { return whereHelper( FieldPath.fromDotSeparatedPath(field), Operator.GREATER_THAN_OR_EQUAL, value); @@ -221,7 +208,6 @@ public Query whereGreaterThanOrEqualTo(@NonNull String field, @NonNull Object va * @return The created Query. */ @NonNull - @PublicApi public Query whereGreaterThanOrEqualTo(@NonNull FieldPath fieldPath, @NonNull Object value) { return whereHelper(fieldPath, Operator.GREATER_THAN_OR_EQUAL, value); } @@ -239,7 +225,6 @@ public Query whereGreaterThanOrEqualTo(@NonNull FieldPath fieldPath, @NonNull Ob * @return The created Query. */ @NonNull - @PublicApi public Query whereArrayContains(@NonNull String field, @NonNull Object value) { return whereHelper(FieldPath.fromDotSeparatedPath(field), Operator.ARRAY_CONTAINS, value); } @@ -257,7 +242,6 @@ public Query whereArrayContains(@NonNull String field, @NonNull Object value) { * @return The created Query. */ @NonNull - @PublicApi public Query whereArrayContains(@NonNull FieldPath fieldPath, @NonNull Object value) { return whereHelper(fieldPath, Operator.ARRAY_CONTAINS, value); } @@ -526,7 +510,6 @@ private void validateNewFilter(Filter filter) { * @return The created Query. */ @NonNull - @PublicApi public Query orderBy(@NonNull String field) { return orderBy(FieldPath.fromDotSeparatedPath(field), Direction.ASCENDING); } @@ -538,7 +521,6 @@ public Query orderBy(@NonNull String field) { * @return The created Query. */ @NonNull - @PublicApi public Query orderBy(@NonNull FieldPath fieldPath) { checkNotNull(fieldPath, "Provided field path must not be null."); return orderBy(fieldPath.getInternalPath(), Direction.ASCENDING); @@ -553,7 +535,6 @@ public Query orderBy(@NonNull FieldPath fieldPath) { * @return The created Query. */ @NonNull - @PublicApi public Query orderBy(@NonNull String field, @NonNull Direction direction) { return orderBy(FieldPath.fromDotSeparatedPath(field), direction); } @@ -567,7 +548,6 @@ public Query orderBy(@NonNull String field, @NonNull Direction direction) { * @return The created Query. */ @NonNull - @PublicApi public Query orderBy(@NonNull FieldPath fieldPath, @NonNull Direction direction) { checkNotNull(fieldPath, "Provided field path must not be null."); return orderBy(fieldPath.getInternalPath(), direction); @@ -603,7 +583,6 @@ private Query orderBy( * @return The created Query. */ @NonNull - @PublicApi public Query limit(long limit) { if (limit <= 0) { throw new IllegalArgumentException( @@ -621,7 +600,6 @@ public Query limit(long limit) { * @return The created Query. */ @NonNull - @PublicApi public Query startAt(@NonNull DocumentSnapshot snapshot) { Bound bound = boundFromDocumentSnapshot("startAt", snapshot, /*before=*/ true); return new Query(query.startAt(bound), firestore); @@ -635,7 +613,6 @@ public Query startAt(@NonNull DocumentSnapshot snapshot) { * @return The created Query. */ @NonNull - @PublicApi public Query startAt(Object... fieldValues) { Bound bound = boundFromFields("startAt", fieldValues, /*before=*/ true); return new Query(query.startAt(bound), firestore); @@ -650,7 +627,6 @@ public Query startAt(Object... fieldValues) { * @return The created Query. */ @NonNull - @PublicApi public Query startAfter(@NonNull DocumentSnapshot snapshot) { Bound bound = boundFromDocumentSnapshot("startAfter", snapshot, /*before=*/ false); return new Query(query.startAt(bound), firestore); @@ -666,7 +642,6 @@ public Query startAfter(@NonNull DocumentSnapshot snapshot) { * @return The created Query. */ @NonNull - @PublicApi public Query startAfter(Object... fieldValues) { Bound bound = boundFromFields("startAfter", fieldValues, /*before=*/ false); return new Query(query.startAt(bound), firestore); @@ -681,7 +656,6 @@ public Query startAfter(Object... fieldValues) { * @return The created Query. */ @NonNull - @PublicApi public Query endBefore(@NonNull DocumentSnapshot snapshot) { Bound bound = boundFromDocumentSnapshot("endBefore", snapshot, /*before=*/ true); return new Query(query.endAt(bound), firestore); @@ -696,7 +670,6 @@ public Query endBefore(@NonNull DocumentSnapshot snapshot) { * @return The created Query. */ @NonNull - @PublicApi public Query endBefore(Object... fieldValues) { Bound bound = boundFromFields("endBefore", fieldValues, /*before=*/ true); return new Query(query.endAt(bound), firestore); @@ -711,7 +684,6 @@ public Query endBefore(Object... fieldValues) { * @return The created Query. */ @NonNull - @PublicApi public Query endAt(@NonNull DocumentSnapshot snapshot) { Bound bound = boundFromDocumentSnapshot("endAt", snapshot, /*before=*/ false); return new Query(query.endAt(bound), firestore); @@ -725,7 +697,6 @@ public Query endAt(@NonNull DocumentSnapshot snapshot) { * @return The created Query. */ @NonNull - @PublicApi public Query endAt(Object... fieldValues) { Bound bound = boundFromFields("endAt", fieldValues, /*before=*/ false); return new Query(query.endAt(bound), firestore); @@ -845,7 +816,6 @@ private Bound boundFromFields(String methodName, Object[] values, boolean before * @return A Task that will be resolved with the results of the Query. */ @NonNull - @PublicApi public Task get() { return get(Source.DEFAULT); } @@ -861,8 +831,7 @@ public Task get() { * @return A Task that will be resolved with the results of the Query. */ @NonNull - @PublicApi - public Task get(Source source) { + public Task get(@NonNull Source source) { if (source == Source.CACHE) { return firestore .getClient() @@ -936,7 +905,6 @@ private Task getViaSnapshotListener(Source source) { * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener(@NonNull EventListener listener) { return addSnapshotListener(MetadataChanges.EXCLUDE, listener); } @@ -949,7 +917,6 @@ public ListenerRegistration addSnapshotListener(@NonNull EventListener listener) { return addSnapshotListener(executor, MetadataChanges.EXCLUDE, listener); @@ -965,7 +932,6 @@ public ListenerRegistration addSnapshotListener( * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull Activity activity, @NonNull EventListener listener) { return addSnapshotListener(activity, MetadataChanges.EXCLUDE, listener); @@ -980,7 +946,6 @@ public ListenerRegistration addSnapshotListener( * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull MetadataChanges metadataChanges, @NonNull EventListener listener) { return addSnapshotListener(Executors.DEFAULT_CALLBACK_EXECUTOR, metadataChanges, listener); @@ -996,7 +961,6 @@ public ListenerRegistration addSnapshotListener( * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull Executor executor, @NonNull MetadataChanges metadataChanges, @@ -1019,7 +983,6 @@ public ListenerRegistration addSnapshotListener( * @return A registration object that can be used to remove the listener. */ @NonNull - @PublicApi public ListenerRegistration addSnapshotListener( @NonNull Activity activity, @NonNull MetadataChanges metadataChanges, diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/QueryDocumentSnapshot.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/QueryDocumentSnapshot.java index 3878b9d36fb..25430fb3fd7 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/QueryDocumentSnapshot.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/QueryDocumentSnapshot.java @@ -17,12 +17,11 @@ import static com.google.common.base.Preconditions.checkNotNull; import androidx.annotation.NonNull; -import com.google.firebase.annotations.PublicApi; +import androidx.annotation.Nullable; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.model.DocumentKey; import com.google.firebase.firestore.util.Assert; import java.util.Map; -import javax.annotation.Nullable; /** * A QueryDocumentSnapshot contains data read from a document in your Firestore database as part of @@ -37,7 +36,6 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class QueryDocumentSnapshot extends DocumentSnapshot { private QueryDocumentSnapshot( @@ -62,7 +60,6 @@ static QueryDocumentSnapshot fromDocument( */ @NonNull @Override - @PublicApi public Map getData() { Map result = super.getData(); Assert.hardAssert(result != null, "Data in a QueryDocumentSnapshot should be non-null"); @@ -79,7 +76,6 @@ public Map getData() { */ @NonNull @Override - @PublicApi public Map getData(@NonNull ServerTimestampBehavior serverTimestampBehavior) { checkNotNull( serverTimestampBehavior, "Provided serverTimestampBehavior value must not be null."); @@ -96,7 +92,6 @@ public Map getData(@NonNull ServerTimestampBehavior serverTimest */ @NonNull @Override - @PublicApi public T toObject(@NonNull Class valueType) { T result = super.toObject(valueType); Assert.hardAssert(result != null, "Object in a QueryDocumentSnapshot should be non-null"); @@ -113,7 +108,6 @@ public T toObject(@NonNull Class valueType) { */ @NonNull @Override - @PublicApi public T toObject( @NonNull Class valueType, @NonNull ServerTimestampBehavior serverTimestampBehavior) { checkNotNull( diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/QuerySnapshot.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/QuerySnapshot.java index f3efa0353b1..d71728b3bfd 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/QuerySnapshot.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/QuerySnapshot.java @@ -17,14 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import androidx.annotation.NonNull; -import com.google.firebase.annotations.PublicApi; +import androidx.annotation.Nullable; import com.google.firebase.firestore.core.ViewSnapshot; import com.google.firebase.firestore.model.Document; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; -import javax.annotation.Nullable; /** * A QuerySnapshot contains the results of a query. It can contain zero or more DocumentSnapshot @@ -34,7 +33,6 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class QuerySnapshot implements Iterable { private final Query originalQuery; @@ -80,14 +78,12 @@ public void remove() { } @NonNull - @PublicApi public Query getQuery() { return originalQuery; } /** @return The metadata for this document snapshot. */ @NonNull - @PublicApi public SnapshotMetadata getMetadata() { return metadata; } @@ -101,7 +97,6 @@ public SnapshotMetadata getMetadata() { * @return The list of document changes since the last snapshot. */ @NonNull - @PublicApi public List getDocumentChanges() { return getDocumentChanges(MetadataChanges.EXCLUDE); } @@ -115,7 +110,6 @@ public List getDocumentChanges() { * @return The list of document changes since the last snapshot. */ @NonNull - @PublicApi public List getDocumentChanges(@NonNull MetadataChanges metadataChanges) { if (MetadataChanges.INCLUDE.equals(metadataChanges) && snapshot.excludesMetadataChanges()) { throw new IllegalArgumentException( @@ -137,7 +131,6 @@ public List getDocumentChanges(@NonNull MetadataChanges metadata * @return The list of documents. */ @NonNull - @PublicApi public List getDocuments() { List res = new ArrayList<>(snapshot.getDocuments().size()); for (com.google.firebase.firestore.model.Document doc : snapshot.getDocuments()) { @@ -147,20 +140,17 @@ public List getDocuments() { } /** Returns true if there are no documents in the QuerySnapshot. */ - @PublicApi public boolean isEmpty() { return snapshot.getDocuments().isEmpty(); } /** Returns the number of documents in the QuerySnapshot. */ - @PublicApi public int size() { return snapshot.getDocuments().size(); } @Override @NonNull - @PublicApi public Iterator iterator() { return new QuerySnapshotIterator(snapshot.getDocuments().iterator()); } @@ -172,7 +162,6 @@ public Iterator iterator() { * @param clazz The POJO type used to convert the documents in the list. */ @NonNull - @PublicApi public List toObjects(@NonNull Class clazz) { return toObjects(clazz, DocumentSnapshot.ServerTimestampBehavior.DEFAULT); } @@ -186,7 +175,6 @@ public List toObjects(@NonNull Class clazz) { * been set to their final value. */ @NonNull - @PublicApi public List toObjects( @NonNull Class clazz, @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior) { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/ServerTimestamp.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/ServerTimestamp.java index bba882933f4..a54af59a4ff 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/ServerTimestamp.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/ServerTimestamp.java @@ -14,7 +14,6 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -25,7 +24,6 @@ * being written contains null for a @ServerTimestamp-annotated field, it will be replaced with a * server-generated timestamp. */ -@PublicApi @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.FIELD}) public @interface ServerTimestamp {} diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/SetOptions.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/SetOptions.java index d6099e0e6e4..6492668a61e 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/SetOptions.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/SetOptions.java @@ -19,7 +19,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.model.mutation.FieldMask; import java.util.HashSet; import java.util.List; @@ -31,7 +30,6 @@ * calls in {@link DocumentReference}, {@link WriteBatch} and {@link Transaction} can be configured * to perform granular merges instead of overwriting the target documents in their entirety. */ -@PublicApi public final class SetOptions { static final SetOptions OVERWRITE = new SetOptions(false, null); @@ -63,7 +61,6 @@ public FieldMask getFieldMask() { * Fields omitted from the set() call will remain untouched. */ @NonNull - @PublicApi public static SetOptions merge() { return MERGE_ALL_FIELDS; } @@ -79,7 +76,6 @@ public static SetOptions merge() { * within the document. */ @NonNull - @PublicApi public static SetOptions mergeFields(@NonNull List fields) { Set fieldPaths = new HashSet<>(); @@ -101,7 +97,6 @@ public static SetOptions mergeFields(@NonNull List fields) { * within the document. */ @NonNull - @PublicApi public static SetOptions mergeFields(String... fields) { Set fieldPaths = new HashSet<>(); @@ -122,7 +117,6 @@ public static SetOptions mergeFields(String... fields) { * @param fields The list of fields to merge. */ @NonNull - @PublicApi public static SetOptions mergeFieldPaths(@NonNull List fields) { Set fieldPaths = new HashSet<>(); diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/SnapshotMetadata.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/SnapshotMetadata.java index ded3a298c2b..ca72905245f 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/SnapshotMetadata.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/SnapshotMetadata.java @@ -14,8 +14,7 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; -import javax.annotation.Nullable; +import androidx.annotation.Nullable; /** * Metadata about a snapshot, describing the state of the snapshot. @@ -24,7 +23,6 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class SnapshotMetadata { private final boolean hasPendingWrites; private final boolean isFromCache; @@ -40,7 +38,6 @@ public class SnapshotMetadata { * updates (via `MetadataChanges.INCLUDE`) you will receive another snapshot with * `hasPendingWrites()` equal to false once the writes have been committed to the backend. */ - @PublicApi public boolean hasPendingWrites() { return hasPendingWrites; } @@ -51,7 +48,6 @@ public boolean hasPendingWrites() { * `MetadataChanges.INCLUDE`) you will receive another snapshot with `isFomCache()` equal to * false once the client has received up-to-date data from the backend. */ - @PublicApi public boolean isFromCache() { return isFromCache; } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/Source.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/Source.java index 335b7099d82..73ac5896436 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/Source.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/Source.java @@ -14,15 +14,12 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; - /** * Configures the behavior of {@code get()} calls on {@link DocumentReference} and {@link Query}. By * providing a Source value, these methods can be configured to fetch results only from the server, * only from the local cache, or attempt to fetch results from the server and fall back to the cache * (which is the default). */ -@PublicApi public enum Source { /** * Causes Firestore to try to retrieve an up-to-date (server-retrieved) snapshot, but fall back to diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/ThrowOnExtraProperties.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/ThrowOnExtraProperties.java index 9eb5db6fc24..be00e1e39da 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/ThrowOnExtraProperties.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/ThrowOnExtraProperties.java @@ -14,7 +14,6 @@ package com.google.firebase.firestore; -import com.google.firebase.annotations.PublicApi; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -24,7 +23,6 @@ * Properties that don't map to class fields when serializing to a class annotated with this * annotation cause an exception to be thrown. */ -@PublicApi @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) public @interface ThrowOnExtraProperties {} diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/Transaction.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/Transaction.java index 87ec26a4761..5f08f2e6225 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/Transaction.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/Transaction.java @@ -21,7 +21,6 @@ import androidx.annotation.Nullable; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Tasks; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.core.UserData.ParsedSetData; import com.google.firebase.firestore.core.UserData.ParsedUpdateData; import com.google.firebase.firestore.model.Document; @@ -44,7 +43,6 @@ * * @see FirebaseFirestore#runTransaction(Function) */ -@PublicApi public class Transaction { private final com.google.firebase.firestore.core.Transaction transaction; private final FirebaseFirestore firestore; @@ -65,7 +63,6 @@ public class Transaction { * @return This Transaction instance. Used for chaining method calls. */ @NonNull - @PublicApi public Transaction set(@NonNull DocumentReference documentRef, @NonNull Object data) { return set(documentRef, data, SetOptions.OVERWRITE); } @@ -82,7 +79,6 @@ public Transaction set(@NonNull DocumentReference documentRef, @NonNull Object d * @return This Transaction instance. Used for chaining method calls. */ @NonNull - @PublicApi public Transaction set( @NonNull DocumentReference documentRef, @NonNull Object data, @NonNull SetOptions options) { firestore.validateReference(documentRef); @@ -106,7 +102,6 @@ public Transaction set( * @return This Transaction instance. Used for chaining method calls. */ @NonNull - @PublicApi public Transaction update( @NonNull DocumentReference documentRef, @NonNull Map data) { ParsedUpdateData parsedData = firestore.getDataConverter().parseUpdateData(data); @@ -125,7 +120,6 @@ public Transaction update( * @return This Transaction instance. Used for chaining method calls. */ @NonNull - @PublicApi public Transaction update( @NonNull DocumentReference documentRef, @NonNull String field, @@ -151,7 +145,6 @@ public Transaction update( * @return This Transaction instance. Used for chaining method calls. */ @NonNull - @PublicApi public Transaction update( @NonNull DocumentReference documentRef, @NonNull FieldPath fieldPath, @@ -180,7 +173,6 @@ private Transaction update( * @return This Transaction instance. Used for chaining method calls. */ @NonNull - @PublicApi public Transaction delete(@NonNull DocumentReference documentRef) { firestore.validateReference(documentRef); transaction.delete(documentRef.getKey()); @@ -229,7 +221,6 @@ private Task getAsync(DocumentReference documentRef) { * @return The contents of the Document at this DocumentReference. */ @NonNull - @PublicApi public DocumentSnapshot get(@NonNull DocumentReference documentRef) throws FirebaseFirestoreException { firestore.validateReference(documentRef); @@ -250,10 +241,8 @@ public DocumentSnapshot get(@NonNull DocumentReference documentRef) * * @see FirebaseFirestore#runTransaction(Function) */ - @PublicApi public interface Function { @Nullable - @PublicApi TResult apply(@NonNull Transaction transaction) throws FirebaseFirestoreException; } } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/UserDataConverter.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/UserDataConverter.java index 331e1e57e52..67a1b2c8080 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/UserDataConverter.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/UserDataConverter.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import com.google.firebase.Timestamp; import com.google.firebase.firestore.FieldValue.ArrayRemoveFieldValue; @@ -57,7 +58,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import javax.annotation.Nullable; /** * Helper for parsing raw user input (provided via the API) into internal model classes. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/WriteBatch.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/WriteBatch.java index 555d3b342be..607a328cdf1 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/WriteBatch.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/WriteBatch.java @@ -20,7 +20,6 @@ import androidx.annotation.Nullable; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Tasks; -import com.google.firebase.annotations.PublicApi; import com.google.firebase.firestore.core.UserData.ParsedSetData; import com.google.firebase.firestore.core.UserData.ParsedUpdateData; import com.google.firebase.firestore.model.mutation.DeleteMutation; @@ -44,7 +43,6 @@ * test mocks. Subclassing is not supported in production code and new SDK releases may break code * that does so. */ -@PublicApi public class WriteBatch { private final FirebaseFirestore firestore; private final ArrayList mutations = new ArrayList<>(); @@ -64,7 +62,6 @@ public class WriteBatch { * @return This WriteBatch instance. Used for chaining method calls. */ @NonNull - @PublicApi public WriteBatch set(@NonNull DocumentReference documentRef, @NonNull Object data) { return set(documentRef, data, SetOptions.OVERWRITE); } @@ -81,7 +78,6 @@ public WriteBatch set(@NonNull DocumentReference documentRef, @NonNull Object da * @return This WriteBatch instance. Used for chaining method calls. */ @NonNull - @PublicApi public WriteBatch set( @NonNull DocumentReference documentRef, @NonNull Object data, @NonNull SetOptions options) { firestore.validateReference(documentRef); @@ -106,7 +102,6 @@ public WriteBatch set( * @return This WriteBatch instance. Used for chaining method calls. */ @NonNull - @PublicApi public WriteBatch update( @NonNull DocumentReference documentRef, @NonNull Map data) { ParsedUpdateData parsedData = firestore.getDataConverter().parseUpdateData(data); @@ -125,7 +120,6 @@ public WriteBatch update( * @return This WriteBatch instance. Used for chaining method calls. */ @NonNull - @PublicApi public WriteBatch update( @NonNull DocumentReference documentRef, @NonNull String field, @@ -151,7 +145,6 @@ public WriteBatch update( * @return This WriteBatch instance. Used for chaining method calls. */ @NonNull - @PublicApi public WriteBatch update( @NonNull DocumentReference documentRef, @NonNull FieldPath fieldPath, @@ -181,7 +174,6 @@ private WriteBatch update( * @return This WriteBatch instance. Used for chaining method calls. */ @NonNull - @PublicApi public WriteBatch delete(@NonNull DocumentReference documentRef) { firestore.validateReference(documentRef); verifyNotCommitted(); @@ -195,7 +187,6 @@ public WriteBatch delete(@NonNull DocumentReference documentRef) { * @return A Task that will be resolved when the write finishes. */ @NonNull - @PublicApi public Task commit() { verifyNotCommitted(); committed = true; @@ -218,9 +209,8 @@ private void verifyNotCommitted() { * * @see FirebaseFirestore#runBatch(WriteBatch.Function) */ - @PublicApi public interface Function { - @PublicApi + void apply(@NonNull WriteBatch batch); } } diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/FirebaseAuthCredentialsProvider.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/FirebaseAuthCredentialsProvider.java index 02a2c4e1909..d025698847c 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/FirebaseAuthCredentialsProvider.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/FirebaseAuthCredentialsProvider.java @@ -15,6 +15,7 @@ package com.google.firebase.firestore.auth; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.android.gms.tasks.Task; import com.google.firebase.FirebaseApp; import com.google.firebase.auth.GetTokenResult; @@ -23,7 +24,6 @@ import com.google.firebase.firestore.FirebaseFirestoreException; import com.google.firebase.firestore.FirebaseFirestoreException.Code; import com.google.firebase.firestore.util.Listener; -import javax.annotation.Nullable; /** * FirebaseAuthCredentialsProvider uses Firebase Auth via {@link FirebaseApp} to get an auth token. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/Token.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/Token.java index 7fddfea52aa..960f0823239 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/Token.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/Token.java @@ -14,7 +14,7 @@ package com.google.firebase.firestore.auth; -import javax.annotation.Nullable; +import androidx.annotation.Nullable; /** * The current User and the authentication token provided by the underlying authentication diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/User.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/User.java index a074384e834..4aea2543036 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/User.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/auth/User.java @@ -14,7 +14,7 @@ package com.google.firebase.firestore.auth; -import javax.annotation.Nullable; +import androidx.annotation.Nullable; /** * Simple wrapper around a nullable UID. Mostly exists to make code more readable and for use as a diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/ActivityScope.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/ActivityScope.java index 5be3947f9da..f18e15c27b6 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/ActivityScope.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/ActivityScope.java @@ -17,12 +17,12 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; import android.app.Activity; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import com.google.firebase.firestore.ListenerRegistration; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; /** * Scopes the lifetime of a ListenerRegistration to an Activity. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/AsyncEventListener.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/AsyncEventListener.java index 536e075d6cd..fb281a7eb33 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/AsyncEventListener.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/AsyncEventListener.java @@ -14,10 +14,10 @@ package com.google.firebase.firestore.core; +import androidx.annotation.Nullable; import com.google.firebase.firestore.EventListener; import com.google.firebase.firestore.FirebaseFirestoreException; import java.util.concurrent.Executor; -import javax.annotation.Nullable; /** * A wrapper event listener that uses an Executor to dispatch events. Exposes a mute() call to diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/Query.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/Query.java index cd2f9f893a9..107bab94089 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/Query.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/Query.java @@ -16,6 +16,7 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.firestore.core.Filter.Operator; import com.google.firebase.firestore.core.OrderBy.Direction; import com.google.firebase.firestore.model.Document; @@ -28,7 +29,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import javax.annotation.Nullable; /** Represents the internal structure of a Firestore Query */ public final class Query { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/QueryListener.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/QueryListener.java index 4c594429396..fb8d99d3afb 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/QueryListener.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/QueryListener.java @@ -16,12 +16,12 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.firestore.EventListener; import com.google.firebase.firestore.FirebaseFirestoreException; import com.google.firebase.firestore.core.DocumentViewChange.Type; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; /** * QueryListener takes a series of internal view snapshots and determines when to raise events. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/SyncEngine.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/SyncEngine.java index 6dda084c962..5b8290ca2bd 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/SyncEngine.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/SyncEngine.java @@ -17,6 +17,7 @@ import static com.google.firebase.firestore.util.Assert.fail; import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; @@ -51,7 +52,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.annotation.Nullable; /** * SyncEngine is the central controller in the client SDK architecture. It is the glue code between diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/Transaction.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/Transaction.java index bafb34f6e84..72b7db112f2 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/Transaction.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/Transaction.java @@ -17,6 +17,7 @@ import static com.google.firebase.firestore.util.Assert.fail; import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Tasks; import com.google.firebase.firestore.FirebaseFirestoreException; @@ -42,7 +43,6 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; /** * Internal transaction object responsible for accumulating the mutations to perform and the base diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/UserData.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/UserData.java index 0cb0f614903..2909202b5b8 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/UserData.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/UserData.java @@ -16,6 +16,7 @@ import static java.util.Collections.unmodifiableList; +import androidx.annotation.Nullable; import com.google.firebase.firestore.model.DocumentKey; import com.google.firebase.firestore.model.FieldPath; import com.google.firebase.firestore.model.mutation.FieldMask; @@ -33,7 +34,6 @@ import java.util.List; import java.util.Set; import java.util.regex.Pattern; -import javax.annotation.Nullable; public class UserData { private UserData() {} // Do not instantiate diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/View.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/View.java index db8c0194b71..32d5e2a6827 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/core/View.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/core/View.java @@ -17,6 +17,7 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; import static com.google.firebase.firestore.util.Util.compareIntegers; +import androidx.annotation.Nullable; import com.google.firebase.database.collection.ImmutableSortedMap; import com.google.firebase.database.collection.ImmutableSortedSet; import com.google.firebase.firestore.core.DocumentViewChange.Type; @@ -30,7 +31,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import javax.annotation.Nullable; /** * View is responsible for computing the final merged truth of what docs are in a query. It gets diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalDocumentsView.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalDocumentsView.java index e718129e5ec..d190cfa1e30 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalDocumentsView.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalDocumentsView.java @@ -18,6 +18,7 @@ import static com.google.firebase.firestore.model.DocumentCollections.emptyMaybeDocumentMap; import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.database.collection.ImmutableSortedMap; import com.google.firebase.firestore.core.Query; import com.google.firebase.firestore.model.Document; @@ -30,7 +31,6 @@ import com.google.firebase.firestore.model.mutation.MutationBatch; import java.util.List; import java.util.Map; -import javax.annotation.Nullable; /** * A readonly view of the local state of all documents we're tracking (i.e. we have a cached version diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalStore.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalStore.java index 8a34076b45d..0e92e76c2c2 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalStore.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalStore.java @@ -18,6 +18,7 @@ import static java.util.Arrays.asList; import android.util.SparseArray; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.database.collection.ImmutableSortedMap; import com.google.firebase.database.collection.ImmutableSortedSet; @@ -46,7 +47,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; /** * Local storage in the Firestore client. Coordinates persistence components like the mutation queue diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryMutationQueue.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryMutationQueue.java index a0f9ba644be..40330618760 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryMutationQueue.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryMutationQueue.java @@ -18,6 +18,7 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; import static java.util.Collections.emptyList; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.database.collection.ImmutableSortedSet; import com.google.firebase.firestore.core.Query; @@ -32,7 +33,6 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -import javax.annotation.Nullable; final class MemoryMutationQueue implements MutationQueue { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryQueryCache.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryQueryCache.java index 7c0315dc3fe..68ef30d1b8f 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryQueryCache.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryQueryCache.java @@ -15,6 +15,7 @@ package com.google.firebase.firestore.local; import android.util.SparseArray; +import androidx.annotation.Nullable; import com.google.firebase.database.collection.ImmutableSortedSet; import com.google.firebase.firestore.core.Query; import com.google.firebase.firestore.model.DocumentKey; @@ -23,7 +24,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import javax.annotation.Nullable; /** * An implementation of the QueryCache protocol that merely keeps queries in memory, suitable for diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryRemoteDocumentCache.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryRemoteDocumentCache.java index d1e5dc754fb..6a9dd59cef1 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryRemoteDocumentCache.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryRemoteDocumentCache.java @@ -18,6 +18,7 @@ import static com.google.firebase.firestore.model.DocumentCollections.emptyMaybeDocumentMap; import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.database.collection.ImmutableSortedMap; import com.google.firebase.firestore.core.Query; import com.google.firebase.firestore.model.Document; @@ -27,7 +28,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import javax.annotation.Nullable; /** In-memory cache of remote documents. */ final class MemoryRemoteDocumentCache implements RemoteDocumentCache { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MutationQueue.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MutationQueue.java index 340dafeecba..0279914b96c 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MutationQueue.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/MutationQueue.java @@ -14,6 +14,7 @@ package com.google.firebase.firestore.local; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.core.Query; import com.google.firebase.firestore.model.DocumentKey; @@ -21,7 +22,6 @@ import com.google.firebase.firestore.model.mutation.MutationBatch; import com.google.protobuf.ByteString; import java.util.List; -import javax.annotation.Nullable; /** A queue of mutations to apply to the remote store. */ interface MutationQueue { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryCache.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryCache.java index 9e51249a1e4..7b3adc3aec6 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryCache.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryCache.java @@ -14,12 +14,12 @@ package com.google.firebase.firestore.local; +import androidx.annotation.Nullable; import com.google.firebase.database.collection.ImmutableSortedSet; import com.google.firebase.firestore.core.Query; import com.google.firebase.firestore.model.DocumentKey; import com.google.firebase.firestore.model.SnapshotVersion; import com.google.firebase.firestore.util.Consumer; -import javax.annotation.Nullable; /** * Represents cached queries received from the remote backend. This contains both a mapping between diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/RemoteDocumentCache.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/RemoteDocumentCache.java index fbc72916a3d..bf3c2f7290a 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/RemoteDocumentCache.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/RemoteDocumentCache.java @@ -14,13 +14,13 @@ package com.google.firebase.firestore.local; +import androidx.annotation.Nullable; import com.google.firebase.database.collection.ImmutableSortedMap; import com.google.firebase.firestore.core.Query; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.model.DocumentKey; import com.google.firebase.firestore.model.MaybeDocument; import java.util.Map; -import javax.annotation.Nullable; /** * Represents cached documents received from the remote backend. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteMutationQueue.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteMutationQueue.java index 7f19621d654..c6f208d4c59 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteMutationQueue.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteMutationQueue.java @@ -20,6 +20,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteStatement; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.auth.User; import com.google.firebase.firestore.core.Query; @@ -39,7 +40,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.annotation.Nullable; /** A mutation queue for a specific user, backed by SQLite. */ final class SQLiteMutationQueue implements MutationQueue { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLitePersistence.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLitePersistence.java index 5744b7e88c6..5f17f831319 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLitePersistence.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLitePersistence.java @@ -27,6 +27,7 @@ import android.database.sqlite.SQLiteProgram; import android.database.sqlite.SQLiteStatement; import android.database.sqlite.SQLiteTransactionListener; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.google.common.base.Function; import com.google.firebase.firestore.FirebaseFirestoreException; @@ -45,7 +46,6 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -import javax.annotation.Nullable; /** * A SQLite-backed instance of Persistence. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteQueryCache.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteQueryCache.java index 571b302136a..fb266a8447d 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteQueryCache.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteQueryCache.java @@ -19,6 +19,7 @@ import android.database.sqlite.SQLiteStatement; import android.util.SparseArray; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.database.collection.ImmutableSortedSet; import com.google.firebase.firestore.core.Query; @@ -27,7 +28,6 @@ import com.google.firebase.firestore.proto.Target; import com.google.firebase.firestore.util.Consumer; import com.google.protobuf.InvalidProtocolBufferException; -import javax.annotation.Nullable; /** Cached Queries backed by SQLite. */ final class SQLiteQueryCache implements QueryCache { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteRemoteDocumentCache.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteRemoteDocumentCache.java index f8436cf1a58..fae8f366192 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteRemoteDocumentCache.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteRemoteDocumentCache.java @@ -17,6 +17,7 @@ import static com.google.firebase.firestore.util.Assert.fail; import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.database.collection.ImmutableSortedMap; import com.google.firebase.firestore.core.Query; import com.google.firebase.firestore.model.Document; @@ -33,7 +34,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Executor; -import javax.annotation.Nullable; final class SQLiteRemoteDocumentCache implements RemoteDocumentCache { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/Document.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/Document.java index b5f7405d4f2..f12441594c3 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/Document.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/Document.java @@ -16,6 +16,8 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.common.base.Function; import com.google.firebase.firestore.model.value.FieldValue; import com.google.firebase.firestore.model.value.ObjectValue; @@ -23,8 +25,6 @@ import java.util.Comparator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; /** * Represents a document in Firestore with a key, version, data and whether the data has local @@ -90,7 +90,7 @@ public Document( return proto; } - @Nonnull + @NonNull public ObjectValue getData() { if (objectValue == null) { hardAssert(proto != null && converter != null, "Expected proto and converter to be non-null"); diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/DocumentSet.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/DocumentSet.java index 023d993354a..1fb2f7ee4db 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/DocumentSet.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/DocumentSet.java @@ -17,6 +17,7 @@ import static com.google.firebase.firestore.model.DocumentCollections.emptyDocumentMap; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.firebase.database.collection.ImmutableSortedMap; import com.google.firebase.database.collection.ImmutableSortedSet; import java.util.ArrayList; @@ -24,7 +25,6 @@ import java.util.Comparator; import java.util.Iterator; import java.util.List; -import javax.annotation.Nullable; /** * An immutable set of documents (unique by key) ordered by the given comparator or ordered by key diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/DeleteMutation.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/DeleteMutation.java index a1f760eb30c..9ca3060efb3 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/DeleteMutation.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/DeleteMutation.java @@ -16,13 +16,13 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.model.DocumentKey; import com.google.firebase.firestore.model.MaybeDocument; import com.google.firebase.firestore.model.NoDocument; import com.google.firebase.firestore.model.SnapshotVersion; import com.google.firebase.firestore.model.value.ObjectValue; -import javax.annotation.Nullable; /** Represents a Delete operation */ public final class DeleteMutation extends Mutation { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Mutation.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Mutation.java index e106f7c9a27..22cb481ffa6 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Mutation.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Mutation.java @@ -16,13 +16,13 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.model.DocumentKey; import com.google.firebase.firestore.model.MaybeDocument; import com.google.firebase.firestore.model.SnapshotVersion; import com.google.firebase.firestore.model.value.ObjectValue; -import javax.annotation.Nullable; /** * Represents a Mutation of a document. Different subclasses of Mutation will perform different diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java index 0c68de215ac..4941d1608fd 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java @@ -16,6 +16,7 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.database.collection.ImmutableSortedMap; import com.google.firebase.firestore.model.DocumentKey; @@ -23,7 +24,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.annotation.Nullable; /** * A batch of mutations that will be sent as one unit to the backend. Batches can be marked as a diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/PatchMutation.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/PatchMutation.java index 3ae40447364..1db36f78765 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/PatchMutation.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/PatchMutation.java @@ -16,6 +16,7 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.model.DocumentKey; @@ -25,7 +26,6 @@ import com.google.firebase.firestore.model.UnknownDocument; import com.google.firebase.firestore.model.value.FieldValue; import com.google.firebase.firestore.model.value.ObjectValue; -import javax.annotation.Nullable; /** * A mutation that modifies fields of the document at the given key with the given values. The diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Precondition.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Precondition.java index 8e988bf5e8f..49904ea6abe 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Precondition.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Precondition.java @@ -17,10 +17,10 @@ import static com.google.firebase.firestore.util.Assert.fail; import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.model.MaybeDocument; import com.google.firebase.firestore.model.SnapshotVersion; -import javax.annotation.Nullable; /** * Encodes a precondition for a mutation. This follows the model that the backend accepts with the diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/ServerTimestampOperation.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/ServerTimestampOperation.java index ee6bd1b8451..27dafd1567c 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/ServerTimestampOperation.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/ServerTimestampOperation.java @@ -14,10 +14,10 @@ package com.google.firebase.firestore.model.mutation; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.model.value.FieldValue; import com.google.firebase.firestore.model.value.ServerTimestampValue; -import javax.annotation.Nullable; /** Transforms a value into a server-generated timestamp. */ public class ServerTimestampOperation implements TransformOperation { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/SetMutation.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/SetMutation.java index ef46ada0f6f..d148c9816c1 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/SetMutation.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/SetMutation.java @@ -16,13 +16,13 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.model.DocumentKey; import com.google.firebase.firestore.model.MaybeDocument; import com.google.firebase.firestore.model.SnapshotVersion; import com.google.firebase.firestore.model.value.ObjectValue; -import javax.annotation.Nullable; /** * A mutation that creates or replaces the document at the given key with the object value contents. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformMutation.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformMutation.java index 02315f3666f..89434670e58 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformMutation.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformMutation.java @@ -16,6 +16,7 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.model.DocumentKey; @@ -26,7 +27,6 @@ import com.google.firebase.firestore.model.value.ObjectValue; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; /** * A mutation that modifies specific fields of the document with transform operations. Currently the diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformOperation.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformOperation.java index 1d416cc8e44..e4be1caf3d2 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformOperation.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformOperation.java @@ -14,9 +14,9 @@ package com.google.firebase.firestore.model.mutation; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.model.value.FieldValue; -import javax.annotation.Nullable; /** A transform within a TransformMutation. */ public interface TransformOperation { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/FieldValue.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/FieldValue.java index 1b6d07f301d..ae5485995a0 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/FieldValue.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/FieldValue.java @@ -17,8 +17,8 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.firebase.firestore.util.Util; -import javax.annotation.Nullable; /** * A field value represents a data type as stored by Firestore. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/NullValue.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/NullValue.java index 902ec5f4293..e771e1d6b7c 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/NullValue.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/NullValue.java @@ -14,7 +14,7 @@ package com.google.firebase.firestore.model.value; -import javax.annotation.Nullable; +import androidx.annotation.Nullable; /** A wrapper for null values in Firestore. */ public class NullValue extends FieldValue { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/ObjectValue.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/ObjectValue.java index 7097eed6e9e..d4a0ef7c8db 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/ObjectValue.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/ObjectValue.java @@ -16,6 +16,7 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.database.collection.ImmutableSortedMap; import com.google.firebase.firestore.model.FieldPath; import com.google.firebase.firestore.model.mutation.FieldMask; @@ -26,7 +27,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import javax.annotation.Nullable; /** A structured object value stored in Firestore. */ public class ObjectValue extends FieldValue { diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/ServerTimestampValue.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/ServerTimestampValue.java index a3b69aadf4a..81e68040d9e 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/ServerTimestampValue.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/ServerTimestampValue.java @@ -14,9 +14,9 @@ package com.google.firebase.firestore.model.value; +import androidx.annotation.Nullable; import com.google.firebase.Timestamp; import com.google.firebase.firestore.DocumentSnapshot; -import javax.annotation.Nullable; /** * Represents a locally-applied Server Timestamp. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/remote/AndroidConnectivityMonitor.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/remote/AndroidConnectivityMonitor.java index 11fb058eb2e..228aabbd33a 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/remote/AndroidConnectivityMonitor.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/remote/AndroidConnectivityMonitor.java @@ -25,10 +25,10 @@ import android.net.Network; import android.net.NetworkInfo; import android.os.Build; +import androidx.annotation.Nullable; import com.google.firebase.firestore.util.Consumer; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; /** * Android implementation of ConnectivityMonitor. Parallel implementations exist for N+ and pre-N. diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/remote/WatchChange.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/remote/WatchChange.java index 565c85afa2e..89debc9d2e5 100644 --- a/firebase-firestore/src/main/java/com/google/firebase/firestore/remote/WatchChange.java +++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/remote/WatchChange.java @@ -16,12 +16,12 @@ import static com.google.firebase.firestore.util.Assert.hardAssert; +import androidx.annotation.Nullable; import com.google.firebase.firestore.model.DocumentKey; import com.google.firebase.firestore.model.MaybeDocument; import com.google.protobuf.ByteString; import io.grpc.Status; import java.util.List; -import javax.annotation.Nullable; /** * A Watch Change is the internal representation of the watcher API protocol buffers. This is an diff --git a/tools/lint/src/main/kotlin/CheckRegistry.kt b/tools/lint/src/main/kotlin/CheckRegistry.kt index f43854c2476..b8df4c08cf0 100644 --- a/tools/lint/src/main/kotlin/CheckRegistry.kt +++ b/tools/lint/src/main/kotlin/CheckRegistry.kt @@ -25,7 +25,8 @@ class CheckRegistry : IssueRegistry() { KotlinInteropDetector.KOTLIN_PROPERTY, KotlinInteropDetector.LAMBDA_LAST, KotlinInteropDetector.NO_HARD_KOTLIN_KEYWORDS, - KotlinInteropDetector.PLATFORM_NULLNESS + KotlinInteropDetector.PLATFORM_NULLNESS, + NonAndroidxNullabilityDetector.NON_ANDROIDX_NULLABILITY ) override val api: Int diff --git a/tools/lint/src/main/kotlin/KotlinInteropDetector.kt b/tools/lint/src/main/kotlin/KotlinInteropDetector.kt index 8685d24ec9c..1ed75f45ccc 100644 --- a/tools/lint/src/main/kotlin/KotlinInteropDetector.kt +++ b/tools/lint/src/main/kotlin/KotlinInteropDetector.kt @@ -517,7 +517,7 @@ class KotlinInteropDetector : Detector(), SourceCodeScanner { } // Known nullability: don't complain - if (isEqualsParameter(node) || isToStringMethod(node)) { + if (isEqualsParameter(node) || isToStringMethod(node) || isVarargParameter(node)) { return } @@ -608,6 +608,10 @@ class KotlinInteropDetector : Detector(), SourceCodeScanner { return false } + private fun isVarargParameter(node: UDeclaration): Boolean { + return node is UParameter && node.isVarArgs + } + private fun isToStringMethod(node: UDeclaration): Boolean { if (node is UMethod) { val method = node diff --git a/tools/lint/src/main/kotlin/NonAndroidxNullabilityDetector.kt b/tools/lint/src/main/kotlin/NonAndroidxNullabilityDetector.kt new file mode 100644 index 00000000000..00baa2f6ec9 --- /dev/null +++ b/tools/lint/src/main/kotlin/NonAndroidxNullabilityDetector.kt @@ -0,0 +1,130 @@ +// Copyright 2019 Google LLC +// +// 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.firebase.lint.checks + +import com.android.tools.lint.client.api.UElementHandler +import com.android.tools.lint.detector.api.Category +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Implementation +import com.android.tools.lint.detector.api.Issue +import com.android.tools.lint.detector.api.JavaContext +import com.android.tools.lint.detector.api.LintFix +import com.android.tools.lint.detector.api.Scope +import com.android.tools.lint.detector.api.Severity +import com.android.tools.lint.detector.api.SourceCodeScanner +import com.android.tools.lint.detector.api.isKotlin +import org.jetbrains.uast.UAnnotation +import org.jetbrains.uast.UClass +import org.jetbrains.uast.UDeclaration +import org.jetbrains.uast.UElement +import org.jetbrains.uast.UField +import org.jetbrains.uast.UMethod + +private val NULLABLE_ANNOTATIONS = listOf("Nullable", "CheckForNull") +private val NOT_NULL_ANNOTATIONS = listOf("NonNull", "NotNull", "Nonnull") + +private val ANDROIDX_ANNOTATIONS = listOf( + "androidx.annotation.Nullable", + "androidx.annotation.NonNull", + "android.support.annotation.Nullable", + "android.support.annotation.NonNull") + +class NonAndroidxNullabilityDetector : Detector(), SourceCodeScanner { + companion object Issues { + private val IMPLEMENTATION = Implementation( + NonAndroidxNullabilityDetector::class.java, + Scope.JAVA_FILE_SCOPE + ) + + @JvmField + val NON_ANDROIDX_NULLABILITY = Issue.create( + id = "FirebaseNonAndroidxNullability", + briefDescription = "Use androidx nullability annotations.", + + explanation = "Use androidx nullability annotations instead.", + category = Category.COMPLIANCE, + priority = 1, + severity = Severity.ERROR, + enabledByDefault = false, + implementation = IMPLEMENTATION + ) + } + + override fun getApplicableUastTypes(): List>? { + return listOf(UClass::class.java, UMethod::class.java, UField::class.java) + } + + override fun createUastHandler(context: JavaContext): UElementHandler? { + // using deprecated psi field here instead of sourcePsi because the IDE + // still uses older version of UAST + if (isKotlin(context.uastFile?.sourcePsi)) { + // These checks apply only to Java code + return null + } + return Visitor(context) + } + + class Visitor(private val context: JavaContext) : UElementHandler() { + override fun visitClass(node: UClass) { + doVisit(node) + } + + override fun visitMethod(node: UMethod) { + doVisit(node) + for (parameter in node.uastParameters) { + doVisit(parameter) + } + } + + override fun visitField(node: UField) { + doVisit(node) + } + + private fun doVisit(node: UDeclaration) { + for (annotation in node.annotations) { + ensureAndroidNullability(context, annotation) + } + } + + private fun ensureAndroidNullability(context: JavaContext, annotation: UAnnotation) { + val name = annotation.qualifiedName ?: return + + val simpleName = name.split('.').last() + + if (!isNullabilityAnnotation(simpleName) || name in ANDROIDX_ANNOTATIONS) { + return + } + + val replacement = if (simpleName in NOT_NULL_ANNOTATIONS) "NonNull" else "Nullable" + val replacementAnnotation = "@androidx.annotation.$replacement" + + val fix = LintFix.create() + .replace() + .name("Replace with $replacementAnnotation") + .range(context.getLocation(annotation)) + .all() + .shortenNames() + .reformat(true) + .with(replacementAnnotation) + .build() + + context.report(NON_ANDROIDX_NULLABILITY, context.getLocation(annotation), + "Use androidx nullability annotations.", fix) + } + + private fun isNullabilityAnnotation(name: String): Boolean = + name in NULLABLE_ANNOTATIONS || name in NOT_NULL_ANNOTATIONS + } +} \ No newline at end of file diff --git a/tools/lint/src/test/kotlin/AndroidxNullabilityTests.kt b/tools/lint/src/test/kotlin/AndroidxNullabilityTests.kt new file mode 100644 index 00000000000..f101e6c6875 --- /dev/null +++ b/tools/lint/src/test/kotlin/AndroidxNullabilityTests.kt @@ -0,0 +1,130 @@ +// Copyright 2019 Google LLC +// +// 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.firebase.lint.checks + +import com.android.tools.lint.checks.infrastructure.LintDetectorTest +import com.android.tools.lint.detector.api.Detector +import com.android.tools.lint.detector.api.Issue + +private const val EXPECTED_ERROR = "Use androidx nullability annotations" +private const val NO_WARNINGS = "No warnings." + +private fun annotationSource(pkg: String, name: String): String { + return """ + package $pkg; + + public @interface $name {} + """.trimIndent() +} + +private fun javaxAnnotation(name: String): String { + return annotationSource("javax.annotation", name) +} + +private fun androidxAnnotation(name: String): String { + return annotationSource("androidx.annotation", name) +} + +private val JAVAX_NULLABLE_CLASS = """ + import javax.annotation.Nullable; + @Nullable + class Foo {} +""".trimIndent() + +private val ANDROIDX_NULLABLE_CLASS = """ + import androidx.annotation.Nullable; + @Nullable + class Foo {} +""".trimIndent() + +private val JAVAX_NULLABLE_METHOD = """ + import javax.annotation.Nullable; + + class Foo { + @Nullable String hello() { return null; } + } +""".trimIndent() + +private val ANDROIDX_NULLABLE_METHOD = """ + import androidx.annotation.Nullable; + + class Foo { + @Nullable String hello() { return null; } + } +""".trimIndent() + +private val JAVAX_NON_NULL_METHOD_PARAMETER = """ + import javax.annotation.Nonnull; + + class Foo { + String hello(@Nonnull String bar) { return null; } + } +""".trimIndent() + +private val ANDROIDX_NON_NULL_METHOD_PARAMETER = """ + import androidx.annotation.NonNull; + + class Foo { + String hello(@NonNull String bar) { return null; } + } +""".trimIndent() + +class AndroidxNullabilityTests : LintDetectorTest() { + override fun getDetector(): Detector = NonAndroidxNullabilityDetector() + + override fun getIssues(): MutableList = + mutableListOf(NonAndroidxNullabilityDetector.NON_ANDROIDX_NULLABILITY) + + fun testJavaxAnnotatedNullableClass() { + lint().files(java(JAVAX_NULLABLE_CLASS), java(javaxAnnotation("Nullable"))) + .run() + .checkContains(EXPECTED_ERROR) + } + + fun testAndroidxAnnotatedNullableClass() { + lint().files( + java(ANDROIDX_NULLABLE_CLASS), java(androidxAnnotation("Nullable"))) + .run() + .checkContains(NO_WARNINGS) + } + + fun testJavaxAnnotatedNullableMethod() { + lint().files( + java(JAVAX_NULLABLE_METHOD), java(javaxAnnotation("Nullable"))) + .run() + .checkContains(EXPECTED_ERROR) + } + + fun testAndroidxAnnotatedNullableMethod() { + lint().files( + java(ANDROIDX_NULLABLE_METHOD), java(androidxAnnotation("Nullable"))) + .run() + .checkContains(NO_WARNINGS) + } + + fun testJavaxAnnotatedNonNullMethodParameter() { + lint().files( + java(JAVAX_NON_NULL_METHOD_PARAMETER), java(javaxAnnotation("Nonnull"))) + .run() + .checkContains(EXPECTED_ERROR) + } + + fun testAndroidxAnnotatedNonNullMethodParameter() { + lint().files( + java(ANDROIDX_NON_NULL_METHOD_PARAMETER), java(androidxAnnotation("NonNull"))) + .run() + .checkContains(NO_WARNINGS) + } +}