From c4ffa235e5490c3cba211b469c7f125d162f9f86 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 14 Oct 2014 17:42:10 +0900 Subject: [PATCH] Add JSR305 annotation to LeakGuardHandlerWrapper Change-Id: I7456200af739db4510c5549b7bc894fb48749455 --- .../android/inputmethod/keyboard/TextDecorator.java | 4 ++-- .../inputmethod/keyboard/internal/DrawingHandler.java | 4 +++- .../inputmethod/keyboard/internal/TimerHandler.java | 4 +++- java/src/com/android/inputmethod/latin/LatinIME.java | 4 +++- .../inputmethod/latin/setup/SetupWizardActivity.java | 4 +++- .../latin/utils/LeakGuardHandlerWrapper.java | 11 ++++++----- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/TextDecorator.java b/java/src/com/android/inputmethod/keyboard/TextDecorator.java index ddc65bf36..2b7d2ce3c 100644 --- a/java/src/com/android/inputmethod/keyboard/TextDecorator.java +++ b/java/src/com/android/inputmethod/keyboard/TextDecorator.java @@ -303,7 +303,7 @@ public class TextDecorator { */ private static final class LayoutInvalidator { private final HandlerImpl mHandler; - public LayoutInvalidator(final TextDecorator ownerInstance) { + public LayoutInvalidator(@Nonnull final TextDecorator ownerInstance) { mHandler = new HandlerImpl(ownerInstance); } @@ -311,7 +311,7 @@ public class TextDecorator { private static final class HandlerImpl extends LeakGuardHandlerWrapper { - public HandlerImpl(final TextDecorator ownerInstance) { + public HandlerImpl(@Nonnull final TextDecorator ownerInstance) { super(ownerInstance); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java b/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java index 4f8a105d5..1a55359f5 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java +++ b/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java @@ -23,6 +23,8 @@ import com.android.inputmethod.keyboard.internal.DrawingHandler.Callbacks; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; +import javax.annotation.Nonnull; + // TODO: Separate this class into KeyPreviewHandler and BatchInputPreviewHandler or so. public class DrawingHandler extends LeakGuardHandlerWrapper { public interface Callbacks { @@ -34,7 +36,7 @@ public class DrawingHandler extends LeakGuardHandlerWrapper { private static final int MSG_DISMISS_KEY_PREVIEW = 0; private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1; - public DrawingHandler(final Callbacks ownerInstance) { + public DrawingHandler(@Nonnull final Callbacks ownerInstance) { super(ownerInstance); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java b/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java index ec7b9b024..80b299bf5 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java +++ b/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java @@ -27,6 +27,8 @@ import com.android.inputmethod.keyboard.internal.TimerHandler.Callbacks; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; +import javax.annotation.Nonnull; + // TODO: Separate this class into KeyTimerHandler and BatchInputTimerHandler or so. public final class TimerHandler extends LeakGuardHandlerWrapper implements TimerProxy { public interface Callbacks { @@ -45,7 +47,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper imple private final int mIgnoreAltCodeKeyTimeout; private final int mGestureRecognitionUpdateTime; - public TimerHandler(final Callbacks ownerInstance, final int ignoreAltCodeKeyTimeout, + public TimerHandler(@Nonnull final Callbacks ownerInstance, final int ignoreAltCodeKeyTimeout, final int gestureRecognitionUpdateTime) { super(ownerInstance); mIgnoreAltCodeKeyTimeout = ignoreAltCodeKeyTimeout; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 77016cb8b..b989cf266 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -110,6 +110,8 @@ import java.util.List; import java.util.Locale; import java.util.concurrent.TimeUnit; +import javax.annotation.Nonnull; + /** * Input method implementation for Qwerty'ish keyboard. */ @@ -208,7 +210,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private int mDelayInMillisecondsToUpdateSuggestions; private int mDelayInMillisecondsToUpdateShiftState; - public UIHandler(final LatinIME ownerInstance) { + public UIHandler(@Nonnull final LatinIME ownerInstance) { super(ownerInstance); } diff --git a/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java b/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java index 54562f39d..c3b30dcb4 100644 --- a/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java +++ b/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java @@ -42,6 +42,8 @@ import com.android.inputmethod.latin.utils.UncachedInputMethodManagerUtils; import java.util.ArrayList; +import javax.annotation.Nonnull; + // TODO: Use Fragment to implement welcome screen and setup steps. public final class SetupWizardActivity extends Activity implements View.OnClickListener { static final String TAG = SetupWizardActivity.class.getSimpleName(); @@ -82,7 +84,7 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL private final InputMethodManager mImmInHandler; - public SettingsPoolingHandler(final SetupWizardActivity ownerInstance, + public SettingsPoolingHandler(@Nonnull final SetupWizardActivity ownerInstance, final InputMethodManager imm) { super(ownerInstance); mImmInHandler = imm; diff --git a/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java b/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java index dd6fac671..9a5be99b3 100644 --- a/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java +++ b/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java @@ -21,21 +21,22 @@ import android.os.Looper; import java.lang.ref.WeakReference; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + public class LeakGuardHandlerWrapper extends Handler { private final WeakReference mOwnerInstanceRef; - public LeakGuardHandlerWrapper(final T ownerInstance) { + public LeakGuardHandlerWrapper(@Nonnull final T ownerInstance) { this(ownerInstance, Looper.myLooper()); } - public LeakGuardHandlerWrapper(final T ownerInstance, final Looper looper) { + public LeakGuardHandlerWrapper(@Nonnull final T ownerInstance, final Looper looper) { super(looper); - if (ownerInstance == null) { - throw new NullPointerException("ownerInstance is null"); - } mOwnerInstanceRef = new WeakReference<>(ownerInstance); } + @Nullable public T getOwnerInstance() { return mOwnerInstanceRef.get(); }