summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2017-11-17 11:14:58 -0800
committerGeorge Mount <mount@google.com>2017-11-22 10:20:19 -0800
commitb84ecb4af104ad2b34331cb4af1d36fb32874b53 (patch)
treeb43762cb463fe964a7c46186b4b5bdbae6925125 /extensions
parent3f5c722d20d4c3cba0bb122947a0170ebc9f70b4 (diff)
downloaddata-binding-b84ecb4af104ad2b34331cb4af1d36fb32874b53.tar.gz
Add Nullable and NonNull annotations
Bug: 69458517 Test: compiled Change-Id: Iebc160cf8704f5b3f052f8ca2a9c0f13295111cc
Diffstat (limited to 'extensions')
-rw-r--r--extensions/library/src/main/java/android/databinding/BaseObservable.java6
-rw-r--r--extensions/library/src/main/java/android/databinding/DataBindingUtil.java44
-rw-r--r--extensions/library/src/main/java/android/databinding/ListChangeRegistry.java13
-rw-r--r--extensions/library/src/main/java/android/databinding/MapChangeRegistry.java5
-rw-r--r--extensions/library/src/main/java/android/databinding/PropertyChangeRegistry.java4
-rw-r--r--extensions/library/src/main/java/android/databinding/ViewDataBinding.java9
-rw-r--r--extensions/library/src/main/java/android/databinding/ViewStubProxy.java10
7 files changed, 60 insertions, 31 deletions
diff --git a/extensions/library/src/main/java/android/databinding/BaseObservable.java b/extensions/library/src/main/java/android/databinding/BaseObservable.java
index 6011e4ad..7dbd9eda 100644
--- a/extensions/library/src/main/java/android/databinding/BaseObservable.java
+++ b/extensions/library/src/main/java/android/databinding/BaseObservable.java
@@ -16,6 +16,8 @@
package android.databinding;
+import android.support.annotation.NonNull;
+
/**
* A convenience class that implements {@link android.databinding.Observable} interface and provides
* {@link #notifyPropertyChanged(int)} and {@link #notifyChange} methods.
@@ -27,7 +29,7 @@ public class BaseObservable implements Observable {
}
@Override
- public void addOnPropertyChangedCallback(OnPropertyChangedCallback callback) {
+ public void addOnPropertyChangedCallback(@NonNull OnPropertyChangedCallback callback) {
synchronized (this) {
if (mCallbacks == null) {
mCallbacks = new PropertyChangeRegistry();
@@ -37,7 +39,7 @@ public class BaseObservable implements Observable {
}
@Override
- public void removeOnPropertyChangedCallback(OnPropertyChangedCallback callback) {
+ public void removeOnPropertyChangedCallback(@NonNull OnPropertyChangedCallback callback) {
synchronized (this) {
if (mCallbacks == null) {
return;
diff --git a/extensions/library/src/main/java/android/databinding/DataBindingUtil.java b/extensions/library/src/main/java/android/databinding/DataBindingUtil.java
index 7efdd317..3288239e 100644
--- a/extensions/library/src/main/java/android/databinding/DataBindingUtil.java
+++ b/extensions/library/src/main/java/android/databinding/DataBindingUtil.java
@@ -17,6 +17,7 @@
package android.databinding;
import android.app.Activity;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.InflateException;
import android.view.LayoutInflater;
@@ -46,7 +47,7 @@ public class DataBindingUtil {
*
* @param bindingComponent The default binding component to use
*/
- public static void setDefaultComponent(DataBindingComponent bindingComponent) {
+ public static void setDefaultComponent(@Nullable DataBindingComponent bindingComponent) {
sDefaultComponent = bindingComponent;
}
@@ -59,6 +60,7 @@ public class DataBindingUtil {
* <code>null</code> if no default was set in
* {@link #setDefaultComponent(DataBindingComponent)}.
*/
+ @Nullable
public static DataBindingComponent getDefaultComponent() {
return sDefaultComponent;
}
@@ -86,8 +88,9 @@ public class DataBindingUtil {
* @throws InflateException When a merge layout was used and attachToParent was false.
* @see #setDefaultComponent(DataBindingComponent)
*/
- public static <T extends ViewDataBinding> T inflate(LayoutInflater inflater, int layoutId,
- @Nullable ViewGroup parent, boolean attachToParent) {
+ @Nullable
+ public static <T extends ViewDataBinding> T inflate(@NonNull LayoutInflater inflater,
+ int layoutId, @Nullable ViewGroup parent, boolean attachToParent) {
return inflate(inflater, layoutId, parent, attachToParent, sDefaultComponent);
}
@@ -112,9 +115,10 @@ public class DataBindingUtil {
* the layoutId wasn't for a binding layout.
* @throws InflateException When a merge layout was used and attachToParent was false.
*/
+ @Nullable
public static <T extends ViewDataBinding> T inflate(
- LayoutInflater inflater, int layoutId, @Nullable ViewGroup parent,
- boolean attachToParent, DataBindingComponent bindingComponent) {
+ @NonNull LayoutInflater inflater, int layoutId, @Nullable ViewGroup parent,
+ boolean attachToParent, @Nullable DataBindingComponent bindingComponent) {
final boolean useChildren = parent != null && attachToParent;
final int startChildren = useChildren ? parent.getChildCount() : 0;
final View view = inflater.inflate(layoutId, parent, attachToParent);
@@ -141,7 +145,8 @@ public class DataBindingUtil {
* @see #getBinding(View)
*/
@SuppressWarnings("unchecked")
- public static <T extends ViewDataBinding> T bind(View root) {
+ @Nullable
+ public static <T extends ViewDataBinding> T bind(@NonNull View root) {
return bind(root, sDefaultComponent);
}
@@ -161,7 +166,8 @@ public class DataBindingUtil {
* @see #getBinding(View)
*/
@SuppressWarnings("unchecked")
- public static <T extends ViewDataBinding> T bind(View root,
+ @Nullable
+ public static <T extends ViewDataBinding> T bind(@NonNull View root,
DataBindingComponent bindingComponent) {
T binding = getBinding(root);
if (binding != null) {
@@ -205,7 +211,8 @@ public class DataBindingUtil {
* @return The ViewDataBinding associated with the given view or <code>null</code> if
* view is not part of a bound layout.
*/
- public static <T extends ViewDataBinding> T findBinding(View view) {
+ @Nullable
+ public static <T extends ViewDataBinding> T findBinding(@NonNull View view) {
while (view != null) {
ViewDataBinding binding = ViewDataBinding.getBinding(view);
if (binding != null) {
@@ -252,7 +259,8 @@ public class DataBindingUtil {
* @return The ViewDataBinding associated with the given view or <code>null</code> if
* either the view is not a root View for a layout or view hasn't been bound.
*/
- public static <T extends ViewDataBinding> T getBinding(View view) {
+ @Nullable
+ public static <T extends ViewDataBinding> T getBinding(@NonNull View view) {
return (T) ViewDataBinding.getBinding(view);
}
@@ -264,9 +272,12 @@ public class DataBindingUtil {
* @param activity The Activity whose content View should change.
* @param layoutId The resource ID of the layout to be inflated, bound, and set as the
* Activity's content.
- * @return The binding associated with the inflated content view.
+ * @return The binding associated with the inflated content view or {@code null} if the
+ * layoutId is not a data binding layout.
*/
- public static <T extends ViewDataBinding> T setContentView(Activity activity, int layoutId) {
+ @Nullable
+ public static <T extends ViewDataBinding> T setContentView(@NonNull Activity activity,
+ int layoutId) {
return setContentView(activity, layoutId, sDefaultComponent);
}
@@ -279,10 +290,12 @@ public class DataBindingUtil {
* @param activity The Activity whose content View should change.
* @param layoutId The resource ID of the layout to be inflated, bound, and set as the
* Activity's content.
- * @return The binding associated with the inflated content view.
+ * @return The binding associated with the inflated content view or {@code null} if the
+ * layoutId is not a data binding layout.
*/
- public static <T extends ViewDataBinding> T setContentView(Activity activity, int layoutId,
- DataBindingComponent bindingComponent) {
+ @Nullable
+ public static <T extends ViewDataBinding> T setContentView(@NonNull Activity activity,
+ int layoutId, @Nullable DataBindingComponent bindingComponent) {
activity.setContentView(layoutId);
View decorView = activity.getWindow().getDecorView();
ViewGroup contentView = (ViewGroup) decorView.findViewById(android.R.id.content);
@@ -294,8 +307,9 @@ public class DataBindingUtil {
* purposes.
*
* @param id The integer id, which should be a field from BR class.
- * @return The name if the BR id or null if id is out of bounds.
+ * @return The name if the BR id or {@code null} if id is out of bounds.
*/
+ @Nullable
public static String convertBrIdToString(int id) {
return sMapper.convertBrIdToString(id);
}
diff --git a/extensions/library/src/main/java/android/databinding/ListChangeRegistry.java b/extensions/library/src/main/java/android/databinding/ListChangeRegistry.java
index 3b88fe5f..12e115f8 100644
--- a/extensions/library/src/main/java/android/databinding/ListChangeRegistry.java
+++ b/extensions/library/src/main/java/android/databinding/ListChangeRegistry.java
@@ -15,6 +15,7 @@
*/
package android.databinding;
+import android.support.annotation.NonNull;
import android.support.v4.util.Pools;
/**
@@ -65,7 +66,7 @@ public class ListChangeRegistry
*
* @param list The list that changed.
*/
- public void notifyChanged(ObservableList list) {
+ public void notifyChanged(@NonNull ObservableList list) {
notifyCallbacks(list, ALL, null);
}
@@ -76,7 +77,7 @@ public class ListChangeRegistry
* @param start The index of the first changed element.
* @param count The number of changed elements.
*/
- public void notifyChanged(ObservableList list, int start, int count) {
+ public void notifyChanged(@NonNull ObservableList list, int start, int count) {
ListChanges listChanges = acquire(start, 0, count);
notifyCallbacks(list, CHANGED, listChanges);
}
@@ -88,7 +89,7 @@ public class ListChangeRegistry
* @param start The index where the elements were inserted.
* @param count The number of elements that were inserted.
*/
- public void notifyInserted(ObservableList list, int start, int count) {
+ public void notifyInserted(@NonNull ObservableList list, int start, int count) {
ListChanges listChanges = acquire(start, 0, count);
notifyCallbacks(list, INSERTED, listChanges);
}
@@ -101,7 +102,7 @@ public class ListChangeRegistry
* @param to The index of where the element was moved to.
* @param count The number of elements moved.
*/
- public void notifyMoved(ObservableList list, int from, int to, int count) {
+ public void notifyMoved(@NonNull ObservableList list, int from, int to, int count) {
ListChanges listChanges = acquire(from, to, count);
notifyCallbacks(list, MOVED, listChanges);
}
@@ -113,7 +114,7 @@ public class ListChangeRegistry
* @param start The index of the first element to be removed.
* @param count The number of elements removed.
*/
- public void notifyRemoved(ObservableList list, int start, int count) {
+ public void notifyRemoved(@NonNull ObservableList list, int start, int count) {
ListChanges listChanges = acquire(start, 0, count);
notifyCallbacks(list, REMOVED, listChanges);
}
@@ -130,7 +131,7 @@ public class ListChangeRegistry
}
@Override
- public synchronized void notifyCallbacks(ObservableList sender, int notificationType,
+ public synchronized void notifyCallbacks(@NonNull ObservableList sender, int notificationType,
ListChanges listChanges) {
super.notifyCallbacks(sender, notificationType, listChanges);
if (listChanges != null) {
diff --git a/extensions/library/src/main/java/android/databinding/MapChangeRegistry.java b/extensions/library/src/main/java/android/databinding/MapChangeRegistry.java
index 9c453b6b..4b5a0e45 100644
--- a/extensions/library/src/main/java/android/databinding/MapChangeRegistry.java
+++ b/extensions/library/src/main/java/android/databinding/MapChangeRegistry.java
@@ -15,6 +15,9 @@
*/
package android.databinding;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
/**
* Utility class for managing ObservableMap callbacks.
*/
@@ -40,7 +43,7 @@ public class MapChangeRegistry
* @param sender The map that has changed.
* @param key The key of the element that changed.
*/
- public void notifyChange(ObservableMap sender, Object key) {
+ public void notifyChange(@NonNull ObservableMap sender, @Nullable Object key) {
notifyCallbacks(sender, 0, key);
}
}
diff --git a/extensions/library/src/main/java/android/databinding/PropertyChangeRegistry.java b/extensions/library/src/main/java/android/databinding/PropertyChangeRegistry.java
index 5e1858c3..20e20056 100644
--- a/extensions/library/src/main/java/android/databinding/PropertyChangeRegistry.java
+++ b/extensions/library/src/main/java/android/databinding/PropertyChangeRegistry.java
@@ -15,6 +15,8 @@
*/
package android.databinding;
+import android.support.annotation.NonNull;
+
/**
* Utility class for managing Observable callbacks.
*/
@@ -40,7 +42,7 @@ public class PropertyChangeRegistry extends
* @param propertyId The BR id of the property that has changed or BR._all if the entire
* Observable has changed.
*/
- public void notifyChange(Observable observable, int propertyId) {
+ public void notifyChange(@NonNull Observable observable, int propertyId) {
notifyCallbacks(observable, propertyId, null);
}
}
diff --git a/extensions/library/src/main/java/android/databinding/ViewDataBinding.java b/extensions/library/src/main/java/android/databinding/ViewDataBinding.java
index db551800..41ce1791 100644
--- a/extensions/library/src/main/java/android/databinding/ViewDataBinding.java
+++ b/extensions/library/src/main/java/android/databinding/ViewDataBinding.java
@@ -24,6 +24,8 @@ import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Handler;
import android.os.Looper;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.LongSparseArray;
import android.util.SparseArray;
@@ -318,7 +320,7 @@ public abstract class ViewDataBinding extends BaseObservable {
* @return <code>true</code> if the variable is declared or used in the binding or
* <code>false</code> otherwise.
*/
- public abstract boolean setVariable(int variableId, Object value);
+ public abstract boolean setVariable(int variableId, @Nullable Object value);
/**
* Add a listener to be called when reevaluating dirty fields. This also allows automatic
@@ -326,7 +328,7 @@ public abstract class ViewDataBinding extends BaseObservable {
*
* @param listener The listener to add.
*/
- public void addOnRebindCallback(OnRebindCallback listener) {
+ public void addOnRebindCallback(@NonNull OnRebindCallback listener) {
if (mRebindCallbacks == null) {
mRebindCallbacks = new CallbackRegistry<OnRebindCallback, ViewDataBinding, Void>(REBIND_NOTIFIER);
}
@@ -338,7 +340,7 @@ public abstract class ViewDataBinding extends BaseObservable {
*
* @param listener The listener to remove.
*/
- public void removeOnRebindCallback(OnRebindCallback listener) {
+ public void removeOnRebindCallback(@NonNull OnRebindCallback listener) {
if (mRebindCallbacks != null) {
mRebindCallbacks.remove(listener);
}
@@ -448,6 +450,7 @@ public abstract class ViewDataBinding extends BaseObservable {
*
* @return the outermost View in the layout file associated with the Binding.
*/
+ @NonNull
public View getRoot() {
return mRoot;
}
diff --git a/extensions/library/src/main/java/android/databinding/ViewStubProxy.java b/extensions/library/src/main/java/android/databinding/ViewStubProxy.java
index 69799287..1058f87c 100644
--- a/extensions/library/src/main/java/android/databinding/ViewStubProxy.java
+++ b/extensions/library/src/main/java/android/databinding/ViewStubProxy.java
@@ -15,6 +15,8 @@
*/
package android.databinding;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewStub;
import android.view.ViewStub.OnInflateListener;
@@ -49,12 +51,12 @@ public class ViewStubProxy {
}
};
- public ViewStubProxy(ViewStub viewStub) {
+ public ViewStubProxy(@NonNull ViewStub viewStub) {
mViewStub = viewStub;
mViewStub.setOnInflateListener(mProxyListener);
}
- public void setContainingBinding(ViewDataBinding containingBinding) {
+ public void setContainingBinding(@NonNull ViewDataBinding containingBinding) {
mContainingBinding = containingBinding;
}
@@ -87,6 +89,7 @@ public class ViewStubProxy {
* @return the data binding associated with the inflated layout once it has been inflated.
* <code>null</code> prior to inflation or if there is no binding associated with the layout
*/
+ @Nullable
public ViewDataBinding getBinding() {
return mViewDataBinding;
}
@@ -96,6 +99,7 @@ public class ViewStubProxy {
*
* @return the ViewStub in the layout or <code>null</code> if the ViewStub has been inflated.
*/
+ @Nullable
public ViewStub getViewStub() {
return mViewStub;
}
@@ -107,7 +111,7 @@ public class ViewStubProxy {
*
* @param listener The OnInflateListener to notify of successful inflation
*/
- public void setOnInflateListener(OnInflateListener listener) {
+ public void setOnInflateListener(@Nullable OnInflateListener listener) {
if (mViewStub != null) {
mOnInflateListener = listener;
}