From 7f545a57c987862d55966ac08ef64cfe0b9f51e4 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Wed, 30 Jul 2014 13:01:39 +0900 Subject: [PATCH] [HW7.5] Introduce the @Nonnull annotation (take 2) Change-Id: I05512b5434810046c8b72d6bb41567b6cd8b9d6e --- java/Android.mk | 2 +- java/src/com/android/inputmethod/event/Combiner.java | 3 +++ java/src/com/android/inputmethod/event/CombinerChain.java | 7 +++---- .../src/com/android/inputmethod/event/DeadKeyCombiner.java | 3 +++ .../com/android/inputmethod/event/MyanmarReordering.java | 3 +++ java/src/com/android/inputmethod/latin/WordComposer.java | 3 +++ tools/dicttool/Android.mk | 1 + 7 files changed, 17 insertions(+), 5 deletions(-) diff --git a/java/Android.mk b/java/Android.mk index b580624d7..9b8b2b448 100644 --- a/java/Android.mk +++ b/java/Android.mk @@ -25,7 +25,7 @@ LOCAL_CERTIFICATE := shared LOCAL_JNI_SHARED_LIBRARIES := libjni_latinime -LOCAL_STATIC_JAVA_LIBRARIES := android-common inputmethod-common android-support-v4 +LOCAL_STATIC_JAVA_LIBRARIES := android-common inputmethod-common android-support-v4 jsr305 # Do not compress dictionary files to mmap dict data runtime LOCAL_AAPT_FLAGS := -0 .dict diff --git a/java/src/com/android/inputmethod/event/Combiner.java b/java/src/com/android/inputmethod/event/Combiner.java index 8b808c6b3..fee93f0c6 100644 --- a/java/src/com/android/inputmethod/event/Combiner.java +++ b/java/src/com/android/inputmethod/event/Combiner.java @@ -18,6 +18,8 @@ package com.android.inputmethod.event; import java.util.ArrayList; +import javax.annotation.Nonnull; + /** * A generic interface for combiners. Combiners are objects that transform chains of input events * into committable strings and manage feedback to show to the user on the combining state. @@ -33,6 +35,7 @@ public interface Combiner { * @param event the event to combine with the existing state. * @return the resulting event. */ + @Nonnull Event processEvent(ArrayList previousEvents, Event event); /** diff --git a/java/src/com/android/inputmethod/event/CombinerChain.java b/java/src/com/android/inputmethod/event/CombinerChain.java index 8ddc9e7d9..f69bf4fd0 100644 --- a/java/src/com/android/inputmethod/event/CombinerChain.java +++ b/java/src/com/android/inputmethod/event/CombinerChain.java @@ -24,6 +24,8 @@ import com.android.inputmethod.latin.Constants; import java.util.ArrayList; import java.util.HashMap; +import javax.annotation.Nonnull; + /** * This class implements the logic chain between receiving events and generating code points. * @@ -87,6 +89,7 @@ public class CombinerChain { * @return the processed event. It may be the same event, or a consumed event, or a completely * new event. However it may never be null. */ + @Nonnull public Event processEvent(final ArrayList previousEvents, final Event newEvent) { final ArrayList modifiablePreviousEvents = new ArrayList<>(previousEvents); Event event = newEvent; @@ -94,10 +97,6 @@ public class CombinerChain { // A combiner can never return more than one event; it can return several // code points, but they should be encapsulated within one event. event = combiner.processEvent(modifiablePreviousEvents, event); - if (null == event) { - // Combiners return null if they eat the event. - break; - } } return event; } diff --git a/java/src/com/android/inputmethod/event/DeadKeyCombiner.java b/java/src/com/android/inputmethod/event/DeadKeyCombiner.java index 342f499c9..d816247d8 100644 --- a/java/src/com/android/inputmethod/event/DeadKeyCombiner.java +++ b/java/src/com/android/inputmethod/event/DeadKeyCombiner.java @@ -23,6 +23,8 @@ import com.android.inputmethod.latin.Constants; import java.util.ArrayList; +import javax.annotation.Nonnull; + /** * A combiner that handles dead keys. */ @@ -31,6 +33,7 @@ public class DeadKeyCombiner implements Combiner { final StringBuilder mDeadSequence = new StringBuilder(); @Override + @Nonnull public Event processEvent(final ArrayList previousEvents, final Event event) { if (TextUtils.isEmpty(mDeadSequence)) { if (event.isDead()) { diff --git a/java/src/com/android/inputmethod/event/MyanmarReordering.java b/java/src/com/android/inputmethod/event/MyanmarReordering.java index 80c711f4a..dcd06c899 100644 --- a/java/src/com/android/inputmethod/event/MyanmarReordering.java +++ b/java/src/com/android/inputmethod/event/MyanmarReordering.java @@ -21,6 +21,8 @@ import com.android.inputmethod.latin.Constants; import java.util.ArrayList; import java.util.Arrays; +import javax.annotation.Nonnull; + /** * A combiner that reorders input for Myanmar. */ @@ -129,6 +131,7 @@ public class MyanmarReordering implements Combiner { } @Override + @Nonnull public Event processEvent(ArrayList previousEvents, Event newEvent) { final int codePoint = newEvent.mCodePoint; if (VOWEL_E == codePoint) { diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 4284884f7..3b6904847 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -25,6 +25,8 @@ import com.android.inputmethod.latin.utils.StringUtils; import java.util.ArrayList; import java.util.Collections; +import javax.annotation.Nonnull; + /** * A place to store the currently composing word with information such as adjacent key codes as well */ @@ -179,6 +181,7 @@ public final class WordComposer { * @param event the unprocessed event. * @return the processed event. Never null, but may be marked as consumed. */ + @Nonnull public Event processEvent(final Event event) { final Event processedEvent = mCombinerChain.processEvent(mEvents, event); mEvents.add(event); diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk index e4de59db6..0f1f34418 100644 --- a/tools/dicttool/Android.mk +++ b/tools/dicttool/Android.mk @@ -88,6 +88,7 @@ LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES) \ $(call all-java-files-under, $(DICTTOOL_ONDEVICE_TESTS_DIRECTORY)) LOCAL_JAVA_LIBRARIES := junit +LOCAL_STATIC_JAVA_LIBRARIES := jsr305lib LOCAL_REQUIRED_MODULES := $(LATINIME_HOST_NATIVE_LIBNAME) LOCAL_JAR_MANIFEST := etc/manifest.txt LOCAL_MODULE := dicttool_aosp